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
如何在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函数:
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列矩阵,但是如果需要,可以将其更改为其他结构。还有很多其他东西可以定制。
shape
xspline
添加了将输出粘贴到Mathematica中的功能:
matrix2mathematica <- function(x) { paste0( '{', paste0( '{', x[,1], ', ', x[,2], '}', collapse=', '), '}') } cat( matrix2mathematica(out))