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]]]我想在家里做上面的事,因为我没有数学。使用您想要的任何工具,我喜欢使用Python和R,但是对任何解决方案都很满意。我首先想到的是RStudio和这里这个问题,但我不确定是否有更好的方法来做到这一点。
我如何在X上进行交互-GUI-创新?
数学模型的程序-snippet概述
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发布于 2012-08-22 19:15:41
下面是一个R函数,用于您描述的内容:
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中:
matrix2mathematica <- function(x) {
paste0( '{',
paste0( '{', x[,1], ', ', x[,2], '}', collapse=', '),
'}')
}
cat( matrix2mathematica(out))发布于 2012-08-22 17:52:35
在R中可以随意地查看/从我的呆板、buggy、RateSketch()函数中获取,它可以做一些类似的这里。你可以把它缩小到你的情况下,有足够的简化空间。
发布于 2012-08-22 18:39:31
只是locator的一个简单例子
plot(1:10)
point <- locator(1)
# now click somewhere on the plot
point
$x
[1] 8.010256
$y
[1] 7.980781(当然,结果会根据您单击的位置而有所不同)
https://stackoverflow.com/questions/12078575
复制相似问题