Unix:像Mathematica一样在X上获得鼠标坐标? [英] Unix: Getting Mouse -coordinates over X like the Mathematica?

查看:86
本文介绍了Unix:像Mathematica一样在X上获得鼠标坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mathematica

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]]]

我想在没有Mathematica的家里做上述事情.使用所需的任何工具,我喜欢使用Python和R,但对任何候选解决方案都满意.我想到的第一件事是RStudio,这个问题

I want to do the above at home where I do not have Mathematica. Use whatever tool you want, I like to use Python and R but happy with any solution candidate. The first thing that came to my mind was RStudio and this question here but I am unsure whether some better way to do this.

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

Mathematica的过程-摘要概述

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

推荐答案

这是一个R函数,可以完成您描述的事情:

Here is an R function that does what you describe:

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列矩阵,但是如果需要,可以将其更改为其他结构.还有很多其他东西可以定制.

You can change the shape argument to xspline to change the style of spline. This version returns a 2 column matrix with the x and y values, but that could be changed to another structure if prefered. There are plenty of other things that could be customized as well.

增加了将输出粘贴到Mathematica中的功能:

Added function to get the output to paste into Mathematica:

matrix2mathematica <- function(x) {
    paste0( '{', 
        paste0( '{', x[,1], ', ', x[,2], '}', collapse=', '),
    '}')
}

cat( matrix2mathematica(out))

这篇关于Unix:像Mathematica一样在X上获得鼠标坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆