Question
[Math] Determining perpendicular angle...
It seemed like it should be trivially easy, however, the past
several hours(!) have proven otherwise, at least for me.
I have a series of points with angles. I want to know which of these points is the "most perpendicular" to a target point. If I have to walk each point, that is fine.
So I have something like:
P1 = {x:25,y:15,angle:45}
P1 = {x:73,y:375,angle:180}
P1 = {x:35,y:135,angle:-56}
etc
targetP = {x:75,y:15,angle:15}
Which P is the most perpendicular to targetP?
I should note that in actually, these points fall along a bezier curve(the angle for each point is the tangent). So they aren't randomly placed.
I've gotten sorta close. I'm walking through the points, performing some basic math so that perpendicular is always 0, then when I "pass over" 0 I know I just passed perpendicular, so in between the two points is perpendicular:
currAngle = angle1-angle2;
if(currAngle>180) currAngle -= 180;
if(currAngle<-180) currAngle += 180;
currAngle = 90-Math.abs(currAngle);
if((currAngle>0 && prevAngle<0) || (currAngle<0 && prevAngle>0)){
// I have just passed perpendicular....?
}
The problem is it isn't always the case. Sometimes, it seems, that the angles go from positive, to 0, then back to positive again. Additionally, sometimes it goes from 90 to -90, thus triggering 'perpendicular' when it isn't actually. My math is just bad. I need a reliable way to determine which point/angle pair is most perpendicular with a given point, accounting for Flash's -180 to 180 angle measurement.
Thanks for any help!
I have a series of points with angles. I want to know which of these points is the "most perpendicular" to a target point. If I have to walk each point, that is fine.
So I have something like:
P1 = {x:25,y:15,angle:45}
P1 = {x:73,y:375,angle:180}
P1 = {x:35,y:135,angle:-56}
etc
targetP = {x:75,y:15,angle:15}
Which P is the most perpendicular to targetP?
I should note that in actually, these points fall along a bezier curve(the angle for each point is the tangent). So they aren't randomly placed.
I've gotten sorta close. I'm walking through the points, performing some basic math so that perpendicular is always 0, then when I "pass over" 0 I know I just passed perpendicular, so in between the two points is perpendicular:
currAngle = angle1-angle2;
if(currAngle>180) currAngle -= 180;
if(currAngle<-180) currAngle += 180;
currAngle = 90-Math.abs(currAngle);
if((currAngle>0 && prevAngle<0) || (currAngle<0 && prevAngle>0)){
// I have just passed perpendicular....?
}
The problem is it isn't always the case. Sometimes, it seems, that the angles go from positive, to 0, then back to positive again. Additionally, sometimes it goes from 90 to -90, thus triggering 'perpendicular' when it isn't actually. My math is just bad. I need a reliable way to determine which point/angle pair is most perpendicular with a given point, accounting for Flash's -180 to 180 angle measurement.
Thanks for any help!
