Thomas Frenkel's profile

Automatic Round Tangents for After Effects

NoMagnolia provided this awesome script that was used to convert anchors AND TANGENTS to Null-Objects:
https://nomagnolia.tv/ae-link-path-points-tangents-nulls/



Expressions for all IN-TANGENT-NULLs position values:
// IN-TANGENT
pathLayer=thisComp.layer("SHAPE 1");         // Layer that contains the Path
pointsAmt=pathLayer.content("Path 1").path.points().length;         // Amount of Anchors
parentIndex=pathLayer.index-parent.index;         // Index of current Anchor
influence=50;


// Points
P1=parent;
P2=thisComp.layer(pathLayer.name+": Path 1 [1."+parentIndex%pointsAmt+"]");
P3=thisComp.layer(pathLayer.name+": Path 1 [1."+(parentIndex+pointsAmt-2)%pointsAmt+"]");

//Vectors
V1=P2.position-P1.position;
V2=P3.position-P1.position;


//Vector Length
lengthV1=length(P2.position,P1.position);
lengthV2=length(P3.position,P1.position);

// Normalize Vector Length
normalizeDivider=lengthV1+lengthV2;
normalizedV1=lengthV1/normalizeDivider;
normalizedV2=lengthV2/normalizeDivider;
AngleV1=(radiansToDegrees(Math.atan2(V1[1],V1[0]))-90+360)%360;
AngleV2=(radiansToDegrees(Math.atan2(V2[1],V2[0]))+90+360)%360;
if(length(AngleV2,AngleV1)<180){
AngleAverage=(AngleV1*normalizedV2+AngleV2*normalizedV1+360)%360;
} else {
AngleAverage=(AngleV1*normalizedV2+AngleV2*normalizedV1+360)%360+180;
}
AngleRadians=AngleAverage/180*Math.PI;
t2Length=length(P1.position,P3.position)*influence/100;
[Math.sin(AngleRadians)*t2Length,-Math.cos(AngleRadians)*t2Length];


Expression for all OUT-TANGENT-NULLs position values:
// OUT-TANGENT
pathLayer=thisComp.layer("Formebene 1");       // Layer that contains the Path
pointsAmt=pathLayer.content("Pfad 1").path.points().length;      // Amount of Anchors
parentIndex=pathLayer.index-parent.index;       // Index of current Anchor
influence=50;

// Points
P1=parent;
P2=thisComp.layer(pathLayer.name+": Pfad 1 [1."+parentIndex%pointsAmt+"]");
P3=thisComp.layer(pathLayer.name+": Pfad 1 [1."+(parentIndex+pointsAmt-2)%pointsAmt+"]");

// Vectors
V1=P2.position-P1.position;
V2=P3.position-P1.position;

// Vector Length
lengthV1=length(P2.position,P1.position);
lengthV2=length(P3.position,P1.position);

// Normalize Vector Length
normalizeDivider=lengthV1+lengthV2;
normalizedV1=lengthV1/normalizeDivider;
normalizedV2=lengthV2/normalizeDivider;

AngleV2=(radiansToDegrees(Math.atan2(V1[1],V1[0]))-90+360)%360;
AngleV3=(radiansToDegrees(Math.atan2(V2[1],V2[0]))+90+360)%360;
if(length(AngleV3,AngleV2)<180){
angleAverage=(AngleV2*normalizedV2+AngleV3*normalizedV1+360)%360;
} else {
angleAverage=(AngleV2*normalizedV2+AngleV3*normalizedV1+360)%360-180;
}
AngleRadians=((angleAverage+180)/180*Math.PI+360)%360;
t2Length=length(P1.position,P2.position)*influence/100;
[Math.sin(AngleRadians)*t2Length,-Math.cos(AngleRadians)*t2Length];




PROBLEMS:
The calculation of the tangents gets messed up in situations where one anchor passes the X- or Y-coordinate of another anchor. I was not able to fix that yet.
Automatic Round Tangents for After Effects
Published:

Owner

Automatic Round Tangents for After Effects

Expression that forces similar Tangent behaviour as with RotoBezier-Paths. However this works after using the CreateNullsFromPath-Script, which i Read More

Published: