首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Unix:在X上获得鼠标-coordinates,就像数学一样?

Unix:在X上获得鼠标-coordinates,就像数学一样?
EN

Stack Overflow用户
提问于 2012-08-22 17:42:11
回答 3查看 342关注 0票数 2

Mathematica

代码语言:javascript
复制
DynamicModule[{list = {}}, 
 EventHandler[
  Dynamic[Framed@
    Graphics[{BSplineCurve[list], Red, Line[list], Point[list]}, 
     PlotRange -> 2]], {{"MouseClicked", 
     1} :> {AppendTo[list, 
      MousePosition["Graphics"]]}}, {"MouseClicked", 2} :> 
   Print[list]]]

我想在家里做上面的事,因为我没有数学。使用您想要的任何工具,我喜欢使用Python和R,但是对任何解决方案都很满意。我首先想到的是RStudio和这里这个问题,但我不确定是否有更好的方法来做到这一点。

我如何在X上进行交互-GUI-创新?

数学模型的程序-snippet概述

代码语言:javascript
复制
1. you click points

2. you will see BSplineCurve formating between the points and points are red

3. points are saved to an array

4. when finished, you click `right-mouse-button` so array to stdout
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-08-22 19:15:41

下面是一个R函数,用于您描述的内容:

代码语言:javascript
复制
dynmodfunc <- function() {
    plot(0:1,0:1,ann=FALSE,type='n')
    mypoints <- matrix(ncol=2, nrow=0)
    while( length(p <- locator(1, type='p', col='red')) ) {
        mypoints <- rbind(mypoints, unlist(p))
        plot(mypoints, col='red', ann=FALSE, xlim=0:1, ylim=0:1)
        if(nrow(mypoints)>1) {
            xspline(mypoints, shape=-1)
        }
    }
    mypoints
}

(out <- dynmodfunc())

可以将shape参数更改为xspline,以更改样条的样式。此版本返回带有x和y值的2列矩阵,但如果优先使用,则可以更改为另一种结构。还有很多其他的东西也可以定制。

添加函数,将输出粘贴到Mathematica中:

代码语言:javascript
复制
matrix2mathematica <- function(x) {
    paste0( '{', 
        paste0( '{', x[,1], ', ', x[,2], '}', collapse=', '),
    '}')
}

cat( matrix2mathematica(out))
票数 5
EN

Stack Overflow用户

发布于 2012-08-22 17:52:35

在R中可以随意地查看/从我的呆板、buggy、RateSketch()函数中获取,它可以做一些类似的这里。你可以把它缩小到你的情况下,有足够的简化空间。

票数 1
EN

Stack Overflow用户

发布于 2012-08-22 18:39:31

只是locator的一个简单例子

代码语言:javascript
复制
plot(1:10)
point <- locator(1)
# now click somewhere on the plot

point
$x
[1] 8.010256

$y
[1] 7.980781

(当然,结果会根据您单击的位置而有所不同)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12078575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档