使用Mathematica中的Locator和Manipulate设置步长

Jam*_*ard 1 graphics wolfram-mathematica manipulators

鉴于此Mathematica代码,

Manipulate[Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, Locator}]
Run Code Online (Sandbox Code Playgroud)

如何在定位器上设置步距?如果可能的话,约束他们?

Hei*_*ike 5

你可以做点什么

Manipulate[
 Graphics[Line[{{0, 0}, p}], 
  PlotRange -> 2], {{p, {1, 1}}, {-1, -1}, {1, 1}, {0.4, 0.5}, Locator}]
Run Code Online (Sandbox Code Playgroud)

将定位器限制为矩形格子,水平间距为0.4,垂直间距为0.5.定位器的坐标范围由{xmin,ymin} = {-1,-1}和指定{xmax, ymax} = {1,1}.


如果你想要更多的灵活性,例如你想要将定位器的位置限制为非矩形点阵或更一般的坐标集,你可以做类似的事情

Manipulate[
 With[{tab = RandomReal[{-1, 1}, {40, 2}]}, 
  LocatorPane[Dynamic[p, (p = Nearest[tab, #][[1]]) &], 
   Graphics[{Line[{{0, 0}, Dynamic[p]}], {Red, Point /@ tab}}, PlotRange -> 2]]],
 {{p, {1, 1}}, ControlType -> None}]
Run Code Online (Sandbox Code Playgroud)

  • @James垂直和水平步长在上面代码中的"{0.4,0.5}"部分.我理解你的问题是你在找什么,不是吗? (2认同)