ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Finding the intersection of two lines in polar coordinates

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Nick Hill
Finding the intersection of two lines in polar coordinates
on Jul 11, 2012 at 10:28:26 am

I have a few lines connecting points in a comp. These lines are just solids, scaled/positioned/rotated to connect two other layers.



I now want to "fill" the space bounded by sets of lines, so I'm using solids which are corner pinned to warp around as the points, and therefore the lines associated with them, move. So each "fill" layer has 8 layer controls associated with it, two per corner, which define which pair of lines detemine the corner's position at their crossing point.

The problem is, to find out what those positions are, I now have a load of (I think) parallel equations, like this. (This would be for the rightmost point on the green diamond shape - where lines 3 and 5 cross.)


L1 = thisComp.layer("line3");
L2 = thisComp.layer("line4");

p1 = L1.position;
p2 = L2.position;

r1 = degreesToRadians(L1.rotation);
r2 = degreesToRadians(L2.rotation);

// if the crossing point is [x, y]... pseudocode from here on!
x = p1[0] + d1 * Math.cos(r1) = p2[0] + d2 * Math.cos(r2);
y = p1[1] + d1 * Math.sin(r1) = p2[1] + d2 * Math.sin(r2);

// where d1 and d2 are the distances between p1 and [x,y], and p2 and [x,y], respectively.



I know there's probably a neat way of solving these two (basically all I need is to find d1 or d2) but it's years since I had to do this at school (and I was never very good at it anyway) so I'm struggling!



Return to posts index

Nick Hill
Re: Finding the intersection of two lines in polar coordinates
on Jul 11, 2012 at 1:07:02 pm

Sorry, the first two lines of that code should've read....


L1 = thisComp.layer("line3");
L2 = thisComp.layer("line5");




Return to posts index

Dan Ebberts
Re: Finding the intersection of two lines in polar coordinates
on Jul 12, 2012 at 1:53:34 pm

This isn't exactly what you're asking for, but it should help. This finds the intersection of two lines where one line is defined by end point layers P1 and P2, and the other line is defined by the end point layers P3 and P4:


p1 = thisComp.layer("P1").transform.position;
p2 = thisComp.layer("P2").transform.position;
p3 = thisComp.layer("P3").transform.position;
p4 = thisComp.layer("P4").transform.position;

m1vert = Math.abs(p1[0]-p2[0]) < .0001;
m2vert = Math.abs(p3[0]-p4[0]) < .0001;
if (! m1vert){
m1 = (p2[1]-p1[1])/(p2[0]-p1[0]);
b1 = p1[1]-m1*p1[0];
}
if (! m2vert){
m2 = (p4[1]-p3[1])/(p4[0]-p3[0]);
b2 = p3[1]-m2*p3[0];
}
if (m1vert && m2vert){
x = value[0];
y = value[1];
}else if(m1vert){
x = p1[0];
y = m2*x + b2;
}else if (m2vert){
x = p3[0];
y = m1*x + b1;
}else if (m1 == m2){
x = value[0];
y = value[1];
}else{
x = (b1-b2)/(m2-m1);
y = m1*x +b1;
}
[x,y]


I haven't tested it thoroughly, but it should be close.


Dan



Return to posts index


Nick Hill
Re: Finding the intersection of two lines in polar coordinates
on Jul 12, 2012 at 7:49:37 pm

Sir, as usual, I stand humbled by your comprehensive mathematical awesomeness. Thank you!



Return to posts index

Mikhail Vasilev
Re: Finding the intersection of two lines in polar coordinates
on Mar 15, 2019 at 5:20:29 pm

You'd saved me man! : )
Thansk a lot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Return to posts index

Mikhail Vasilev
Re: Finding the intersection of two lines in polar coordinates
on Mar 15, 2019 at 5:21:03 pm

You'd saved me man! : )
Thansk a lot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Return to posts index


Mikhail Vasilev
Re: Finding the intersection of two lines in polar coordinates
on Mar 18, 2019 at 12:56:28 pm

We have god os the Sun, God of the Earth, and God of the After Effects Expressions : )


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]