有了这个数学代码,
Manipulate[Graphics[Line[{{0, 0}, p}], PlotRange -> 2], {{p, {1, 1}}, Locator}]
如何在定位器上设置步长距离?如果可能的话,约束他们?
发布于 2011-08-25 05:21:15
你可以这样做
Manipulate[
Graphics[Line[{{0, 0}, p}],
PlotRange -> 2], {{p, {1, 1}}, {-1, -1}, {1, 1}, {0.4, 0.5}, Locator}]
这将把定位器限制为具有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}]
发布于 2011-08-25 05:20:34
documentation声明:
Manipulate[expr, {u, umin, umax, du}]
允许u的值在步骤du中的umin和umax之间变化。
和
Manipulate[expr, {u, {u1, u2, u3,...}}]
允许u取离散值。
这些方法中的一种应该对您有效。
https://stackoverflow.com/questions/7182171
复制相似问题