I'm trying to create a dynamic environment where I specify, using two locators, the initial condition (position (x,y) and velocity angle (alpha)) of a 2D particle.
To simplify, I'm assuming the initial position is restricted to a circle, and the velocity angle is always in respect to an angle in relation to the normal vector, perpendicular to the tangent vector.
This means that in the end, I would like to have 3 parameters: x,y initial position of the positional locator, and an initial angle, defined as the angle between the vector (positional locator - angle locator) and the normal vector.
The main problem resides on the coupling between the positional locator, and the angle locator: when I move the positional locator, I would like to have the angle locator moved in such a way that the initial angle is preserved.
To manipulate those, I'm using two Locators: one for position (initialPoint), one for initial angle (pt2)
DynamicModule[{initialPoint = {0, 0}, pt2 = {0, 0}},
Style[Graphics[{
Dashed,
Circle[{0, 0}, 1],
Locator[
Dynamic[pt2, (pt2 =
initialPoint + 0.5 Normalize[# - initialPoint]) &]],
Locator[Dynamic[initialPoint, (initialPoint = Normalize[#]) &]]},
PlotRange -> {{-3.3, 3.3}, {-3.3, 3.3}}, AspectRatio -> 1],
Selectable -> False]]
however, when I dynamically pick the initialPoint, the second locator does not follow it. What can I do it in order to keep pt2 always such that the initial angle is preserved?
Comments
Post a Comment