1
\$\begingroup\$

I have 3 points, (x1, y1), (x2, y2), (x3, y3)

enter image description here


I should find the AH height. For this i must use:
enter image description here

How can i find each "a", "b" and "c" values?

\$\endgroup\$
10
  • \$\begingroup\$ This is a general math question, and doesn't belong here. \$\endgroup\$
    – Marton
    Aug 9, 2012 at 11:00
  • \$\begingroup\$ mathworld.wolfram.com/Line.html see here for your a, b, c coefficients.. Derive them manually from equation (4). \$\endgroup\$
    – teodron
    Aug 9, 2012 at 11:04
  • \$\begingroup\$ @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) \$\endgroup\$
    – MarsPeople
    Aug 9, 2012 at 11:21
  • \$\begingroup\$ @Kumul If it's easy on paper, then writing the code should be easy as well. Where are you stuck? \$\endgroup\$
    – Marton
    Aug 9, 2012 at 12:30
  • \$\begingroup\$ 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) \$\endgroup\$
    – MarsPeople
    Aug 9, 2012 at 13:06

2 Answers 2

6
\$\begingroup\$

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

\$\endgroup\$
5
\$\begingroup\$

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.
\$\endgroup\$
1
  • \$\begingroup\$ +1 Almost posted this exact same answer, read from the exact same book. \$\endgroup\$ Oct 12, 2012 at 15:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .