Copy link to clipboard
Copied
As per title, why’d does the arrowhead shape rotate 180 from the expected orientation randomly?
Please see linked video: https://youtu.be/WjvBc6ee1l4
How can I fix this to keep the orientation consistent?
I have a line path with the ends following nulls.. so I can easily select the null and move the line endpoints.
I have an expression on the Shape (triangle) postion and rotation to position and orient it at the end of the line.
Position the arrow at end of the line:
shapeGroup = thisComp.layer("Shape Layer 1").content("The Line");
myPath = shapeGroup.content("Path 1").path;
endPt = myPath.pointOnPath(1);
Orient the arrow to the end of the line:
shapeGroup = thisComp.layer("Shape Layer 1").content("The Line");
myPath = shapeGroup.content("Path 1").path;
tg = myPath.tangentOnPath(1.0);
a = Math.atan2(tg[1],tg[0]); radiansToDegrees(a)-30;
Thanks in advance.
My guess is that it's probably something wierd about calculating the tangent right on the end of the line. I'd try changing this:
tg = myPath.tangentOnPath(1.0);
to this:
tg = myPath.tangentOnPath(.99);
and see if that helps.
Copy link to clipboard
Copied
My guess is that it's probably something wierd about calculating the tangent right on the end of the line. I'd try changing this:
tg = myPath.tangentOnPath(1.0);
to this:
tg = myPath.tangentOnPath(.99);
and see if that helps.
Copy link to clipboard
Copied
@Dan Ebberts - interesting.. seems to do the trick. Thx, much!
Copy link to clipboard
Copied
At certain angles the result will simply be zero. Your demo shows around 30-ish degrees, which would track. Simple math.
Mylenium
Copy link to clipboard
Copied
Thanks, @Mylenium - I'm sure there is a simple mathematical explaination, it has been ages since I've flexed my trig, but, respectfully, I don't think it has to do with the resulting angles in this case. After all, for a straight line, wouldn't tangentOnPath(0.999) be the same as tangentOnPath(1.0) (or, indeed any value x in the range of 0 to 1 for tangentOnPath(x)) ? As you can see, the slight difference as suggested by @Dan Ebberts resolves the issue... I think it has more to do with how AE is computing the tangent at 1.0 rather than the angle of the line being nearly 309 or anything else for that matter. After all, if it were due to 'certain angles the result will simply be 0', I would expect the arrowhead to randomly orient to 0, not randomly flipping 180 degress... if it were due to the angle, I'd expect the same result regardless of x for a straight line, but by further testing, any value seems to work, except for 1. Again, I'm sure there is a simple mathematical explaination, but why the tangent at 1 is causing this alludes me at the moment.
See this video for compaison...
https://www.youtube.com/watch?v=MVxFfMrN6-A
Copy link to clipboard
Copied
My bad, I meant 30. Fatty thumbs typing. *lol*
Mylenium
Copy link to clipboard
Copied
Forgot: For the math it probably boils down to the vectors' dot product being zero at some point...
Mylenium
Copy link to clipboard
Copied
@Mylenium - Not sure I follow the 30 or dot product... but something is getting confused... you can see in this latest iteration that the dx and dy values are being 'flipped' randomly, e.g., resulting in the vector ending up in the opposite quadrant, and thus, the angle being roated 180deg.