Reputation: 206
Hi i'm having trouble figuring out how to create a vector which is perpendicular to another. [-0.17640, 51.426700], [0.17640, 51.796700]
this is the first vector and i'm trying to create a perpendicular line which goes straight through the middle of it. This is what iv done so far but the line is not the correct angle.
startPosition = [-0.17640, 51.426700];
endPosition = [0.17640, 51.796700];
var midPoint = [];
midPoint[0] = (startPosition[0] + endPosition [0]) / 2;
midPoint[1] = (startPosition[1] + endPosition [1]) / 2;
positions[0] = midPoint;
positions[1] = [startPosition[1], startPosition[0] * -1];
positions[2] = [endPosition[0], endPosition[1]];
Upvotes: 4
Views: 3014
Reputation: 15851
In order to get the 2D vector perpendicular to another 2D vector you can simply swap the X and Y components and negate the new Y component. So { x, y } becomes { y | -x }.
Midpoint: [(x1 + x2)/2,( y1 + y2)/2]
Take a look at https://www.wikihow.com/Find-the-Perpendicular-Bisector-of-Two-Points
Upvotes: 4