# The distance to a line from a point, find the constant values?

I have 3 points, (x1, y1), (x2, y2), (x3, y3) I should find the AH height. For this i must use: How can i find each "a", "b" and "c" values?

• This is a general math question, and doesn't belong here. – Marton Aug 9 '12 at 11:00
• mathworld.wolfram.com/Line.html see here for your a, b, c coefficients.. Derive them manually from equation (4). – teodron Aug 9 '12 at 11:04
• @Marton, i don't want an answer on "paper" (yes it's easy), i want the answer on "code" and it's not the same. (equation on paper or code) – MarsPeople Aug 9 '12 at 11:21
• @Kumul If it's easy on paper, then writing the code should be easy as well. Where are you stuck? – Marton Aug 9 '12 at 12:30
• i mean that: I was hoping there will be a "deterministic solution" but was not. For example, how we can write a equation that we knows 2 points and angle of equation? we can't output the answer like equation. But we write the values of equation piecemeal. My english is poor i can't explain myself correctly. (sorry for if i talking to a rough) – MarsPeople Aug 9 '12 at 13:06

a, b, c describe the line passing through B-C so a = y2-y3, b = x2-x3 and c = x2*y3 - x3*y2

Here's a simple way to find point H (which makes finding AH trivial):

V1 = A - B
V2 = C - B
t = dot(V1,V2) / dot(V2,V2)
H = B + t*V2


Notes:

• Definition of dot product: dot(a,b) = a.x*b.x + a.y*b.y
• Another definition of dot product: dot(a,b) = |a|*|b| * cos(theta), where theta = angle between a and b. This means you can get a free cosine out of a couple of multiplications and an addition if you play your cards right - or if we know theta==0 then we get an easy |a|*|b|.
• Picture AB and CB as two line segments that meet at B. V1 and V2 are the line segments relative to B (as if B were 0,0).
• Points along the line BC can be defined by BC(t) = B + t*(C-B), where for example BC(0) is B, BC(1) is C, and BC(0.5) is in the middle.
• If V2 was parallel to the the x axis we could get H (the projection of V1 on V2) with a simple V1 * cos(theta). But it's not so we have to do this: |V1|*cos(theta) * directionOf(V2), where directionOf(V2) = V2/|V2|. We can add in an extra |V2|/|V2| to get (|V1|*|V2|*cos(theta) * V2) / (|V2|*|V2|), which is equivalent to (dot(V1,V2) / dot(V2,V2)) * V2. Leaving out the last V2 at first gives us 't'.
• Solution taken from "Essential Mathematics for Games and Interactive Applications" by Verth & Bishop.
• +1 Almost posted this exact same answer, read from the exact same book. – michael.bartnett Oct 12 '12 at 15:58