Activity › Forums › Adobe After Effects Expressions › Clamping x position on after effects
-
Clamping x position on after effects
Meng Zhang replied 9 years, 3 months ago 3 Members · 13 Replies
-
Meng Zhang
April 10, 2017 at 9:12 pmDan, thank you for your quick response. I agree with you, although I didn’t find a perfect solution, I managed to find out a way to detect if the position is within a mask using this attached code by M. Katz based on Nirg’s approach:
By changing the polygon to to a layer mask, I successfully got a right result. And it is all I need for now. I just need to detect the position key frames outside the mask and delete them. I’m planning looping through the key frames and delete those that are out of range.
I hope to take the chance to thank you for all your awesome answers in this forum. I have always been learning a lot from you. Thank you.
function pointIsInPoly(p, polygon) {
var isInside = false;
var minX = polygon[0].x, maxX = polygon[0].x;
var minY = polygon[0].y, maxY = polygon[0].y;
for (var n = 1; n < polygon.length; n++) {
var q = polygon[n];
minX = Math.min(q.x, minX);
maxX = Math.max(q.x, maxX);
minY = Math.min(q.y, minY);
maxY = Math.max(q.y, maxY);
}if (p.x < minX || p.x > maxX || p.y < minY || p.y > maxY) {
return false;
}var i = 0, j = polygon.length - 1;
for (i, j; i < polygon.length; j = i++) {
if ( (polygon[i].y > p.y) != (polygon[j].y > p.y) &&
p.x < (polygon[j].x - polygon[i].x) * (p.y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x ) {
isInside = !isInside;
}
}return isInside;
} -
Dan Ebberts
April 10, 2017 at 10:54 pmSo this is for a script? That should work because scripting has access to mask/path vertices.
Dan
-
Meng Zhang
April 11, 2017 at 12:34 amHey Dan,
It is a script. My fault not making this clear. I didn’t see it is under expression discussion. Thank you again for help!
Reply to this Discussion! Login or Sign Up