Skip to main content
GameDev.net gamedev.net
🔒 Locked

Line equations

Started by chillah Sep 8, 2005 at 2:29 PM 2 replies 900+ views
Original Post
chillah
chillah
I need some help on this. Say I have a line (x1, y1) to (x2, y2). I calculate the half way point for this line using ((x2 + x1)/2, (y2 + y1)/2). Now I want to find a point a specific distance from my line that lies on the line perpendicular to my line and passing through the half way point, and I want the line to be pointing 'out', so if I was to rotate counter-clockwise from point 2 to point 1 the point I calculated would be in that area. Anyone have any idea how I would go about doing this?

eg.  1
    '\'    * (pt to calculate)
     '\'
      '\'
        2
"I'm never alone, I'm alone all the time" - Glycerine-Bush"It starts with one thing" In The End-Linkin Park
Jackis
Jackis
It's simple:

calculate normal vector: let dx = x2 - x1, dy = y2 - y1. So, the normal is N = (-dy, dx), that is the normal pointing the direction you need. Normalize it (N_normalized = N / length(N) = N / sqrt((-dy)^2 + (dx)^2) = (-dy / sqrt((-dy)^2 + (dx)^2), dx / sqrt((-dy)^2 + (dx)^2))). So, now it is unit length.

Now, your desired point P (distanced in a distance D from half-way point) is

half_way + N_normalized * d (in vector terms)

[EDIT] : sorry, while I was printing, Anonimous Poster already gave the answer ))
chillah
chillah
Thanks a lot you guys. That was very helpful.
"I'm never alone, I'm alone all the time" - Glycerine-Bush"It starts with one thing" In The End-Linkin Park

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.