3. Constrain Segments to Integer Length and to 5° Intervals
Acknowledgement: Michael Borcherds "Demo: constrain a Segment to 15° intervals"
To constrain AB to integer length
B = Point(Sequence(A + (i, 0), i, 1, 20, 1))
To constrain AC to integer length
C1=(3,3) (C1 is a free point of any coordinates)
u = Vector(A, C1)
UPoints = Sequence(A + i UnitVector(Segment(A, C1)), i, 1, 20, 1)
C = DynamicCoordinates(C1, x(ClosestPoint(UPoints, C1)), y(ClosestPoint(UPoints, C1)))
uCopy = (3,3) (uCopy is a free vector of any value)
Scripting | On Update of the following objects:
u: SetValue(uCopy, u)
A: SetValue(C1,A+uCopy)
The purpose of the scripting is to preserve the position of C when A moves.
To constrain BC' to 5° interval
C2=(6,6) (C2 is a free point of any coordinates)
v = Vector(B, C2)
VPoints = Sequence((x(B) + Length(v) cos(t°), y(B) + Length(v) sin(t°)), t, 0, 355, 5)
C' = DynamicCoordinates(C2, x(ClosestPoint(VPoints, C2)), y(ClosestPoint(VPoints, C2)))
vCopy = (6,6) (vCopy is a free vector of any value)
Scripting|OnUpdate of the following objects:
v: SetValue(vCopy, v)
B: SetValue(C2,B+vCopy)
SetValue(C1,A+uCopy)
A: SetValue(C1,A+uCopy)
SetValue(C2,B+vCopy)
The purpose of the scripting is to preserve the position of C' and C when B or A moves.
To snap C and C' to the 2 intersections G and G'
Scripting|OnUpdate of:
C: SetValue(C, If(Distance(C,G)<d, G, If(Distance(C,G')<d, G', C)))
C': SetValue(C', If(Distance(C',G)<d, G, If(Distance(C',G')<d, G', C')))
where d=0.3 is the distance less than which the point would be snapped to G or G'.