expression controllers

expression controllers

mad.kaveh
Advocate Advocate
1,029 Views
3 Replies
Message 1 of 4

expression controllers

mad.kaveh
Advocate
Advocate

hi, everybody, I constrained green dummy to the red line I used path contrast. how I can drive it on the path exact at the intersection point of the green line whit expression controllers.
thank you so much Untitled picture.png

0 Likes
Accepted solutions (1)
1,030 Views
3 Replies
Replies (3)
Message 2 of 4

leeminardi
Mentor
Mentor

First list the assumptions you are making about the positioning of cylinder001 with respect to cylinder003.   The axes of the two must be on the same plane.  

How do you want to be able to move one of the cylinders with respect to the other or are their position fixed?

 

The path of the green dummy for the configuration shown is an ellipse.  Rather than constraining the dummy to a line from one of the cylinders I would give it an expression controller and relate its position to the angle of rotation of one of the cylinders. 

lee.minardi
0 Likes
Message 3 of 4

leeminardi
Mentor
Mentor
Accepted solution

Here's a solution to the problem of placing a dummy at the intersection of the two lines that are revolving in a cylinder.  I used a Maxscript for the dummy and some vector algebra coupled with a numerical solution.

 

I removed all the constraints you had in the model and set up the following.  In the image below the cylinder on the left is CylinderA, it has a line linked to it LineA, and at the end of LineA is Point A linked to Line A.  There's a similar construction for CylinderB on the right.

To find the position in world coordinates of  PointA (pA in the script) I added the position LineA to pA and multiplied by the transformation matrix of Cylinder A.  Point B is found similarly but pB is subtracted from LineB because their local coordinates are in opposite directions.

To find the intersection point of the two lines I projected endA onto line B yielding pmpm is then projected to line A yielding pn. The process is repeated until the difference in the length of the two vectors is less than an acceptable error (0.001 in this example).  The location of the intersection is  the last computed position of pm.

Dummy001 will track the intersection of the two line if either cylinder A or B is rotated about its local Y axis.

The mechanism will still work if either cylinder A or B is rotated about its world Z axis.

No check is made if the two lines are not coplanar.

 

endA = (LineA + pA) * cylAT
endB = (LineB - pB) * cylBT
midA = LineA * cylAT
midB = LineB * cylBT
uB = normalize (midB-endB)
uA = normalize (midA-endA)
pm = endB + uB * (dot uB (endA - endB))
pn = endA + uA * (dot uA (pm - endA))
lenM = length(pn-pm)
pm = endB + uB * (dot uB (pn - endB))
lenN = length( pn-pm)
while  abs(lenM - lenN) > 0.001 do
(
pn = endA + uA * (dot uA (pm - endA))
lenM = length(pn-pm)
pm = endB + uB * (dot uB (pn - endB))
lenN = length( pn-pm)
)
p = pm

dd1.JPG

 

lee.minardi
0 Likes
Message 4 of 4

mad.kaveh
Advocate
Advocate

I appreciate so much leeminardi .

0 Likes