Calculating the perpendicular bisector of a line?

This topic is 5066 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, If i have a line made from 2 points, how can I calculate the perpendicular bisector - to indicate the "Normal" of the line? I can calculate where the bisector starts, by just getting the absolute difference of the x and y of the two points, but I don't know how to do any more... Thanks, - aCiD2

Share on other sites
Jusat normalize the line, and rotate it 90 degrees (PI/2 radians) by swapping the x and y components. Mathematically, you'd take a cross product of the normalized line and z-axis, but it boils down to what I said.

EDIT: Of course, this assumes that the line is 2D [smile]

Share on other sites
But what vector am I normalizing? The line is composed of 2 points so the lines origin is not necissarily 0, 0, 0... Sorry if your post covered this, but I didn't quite understand. Mind running through it again, possibly with a pseudo code sample?

Share on other sites
The vector composed between the two points, so p1 - p2, like acid i presume you are talking about a 2d line?

Share on other sites
Let the line run from (x1, y1) to (x2, y2). The centre of the line is thus ((x1+x2)/2, (y1+y2)/2).

The gradient of your line is (y2-y1)/(x2-x1), and the gradient of the perpendicular line is thus (x1-x2)/(y2-y1). So, your perpendicular bisector runs from ((x1+x2)/2, (y1+y2)/2) to (x1+x2)/2, (y1+y2)/2) + n * ((x1-x2)/(y2-y1).

Share on other sites
IMO I would avoid the gradiant or slope, and use the vector representation instead, as it is valid for all lines, horizontal, vertical or otherwise.

So basically what Nik02 said. If you're still unsure about that, here's a little more detail. To find the normal to a line represented by points p1, p2:

Vector2 dir = p2 - p1;
Vector2 normal(-dir.y, dir.x);
normal.Normalize();

Note that if you want the normal to point the other way, just use:

Vector2 normal(dir.y, -dir.x);

The normal by itself is just a direction - it doesn't know anything about 'bisecting' the segment as such. If for some reason you need a segment that is perpendicular to and bisects the original segment, it can then be constructed from the segment midpoint and the normal.

'Hope that clears things up a bit.

Share on other sites
Wow, many thanks to all of you. I wasn't expecting such an in depth set of answers - saddly me giving you a positive rating doesn't do much, but a huge thank you to you all! I got it working using normal vectors, but tried the gradient aswell (didn't work with vertical lines and I felt normals was a 'more accurate' way).

Good ol' GDNET ^_^

Again, many thanks
- aCiD2

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• Forum Statistics

• Total Topics
634047
• Total Posts
3015226
×