Re: How to compute triangle base/altitude intersection



"Arthur J. O'Dwyer" <ajonospam@xxxxxxxxxxxxxx> writes:

On Wed, 30 Aug 2006, Pascal Bourguignon wrote:
"Phlip" <phlipcpp@xxxxxxxxx> writes:
Balabek wrote:

Hope you can help me solve this problem.

Suppose I have a triange ABC. I have altitude passing through vertice
C, and it intersects line AB or extension of line AB at point D.

How do you define "altitude"?

An altitude of a triangle passes through one of the vertices and
is perpendicular to the opposite side. I don't know what the word for
"altitude" is in French, but I would expect it would be a cognate to
the English word "altitude".

Oh, it's called "la hauteur du triangle" (height).
"Altitude" in French is usually absolute, not relative.

Ok, so you have the normal problem, not a strange variation.

There's no difficulty in it. As have been explained, to find the
position of C geometricaly you just draw two circles centered on A and
B of the given radius, and find their intersections. When you draw
the line CC', the intersection of this line with AB is D.

Or you can use the Pythagore theorem: Since we have three unknowns
DC, AD and DB, we need three equations:

+C
/|\
/ | \
/ | \
A+---+---+B
D
AB=AD+DB
AD²+DC²=AC²
DB²+DC²=BC²

DB=AB-AD (2a)
AD²+DC²=AC² (2b)
(AB-AD)²+DC²=BC² (2c)

DB=AB-AD (3a) = (2a)
AD²+DC²=AC² (3b) = (2b)
(AB-AD)²-AD²=BC²-AC² (3c) = (2c)-(2b)

DB=AB-AD
AD²+DC²=AC²
AB²-2(AD)(AB)+AD²-AD²=BC²-AC²

DB=AB-AD
AD²+DC²=AC²
(AB²-BC²+AC²)/2AB=AD

DB=AB-AD
DC²=AC²-AD²
AD=(AB²-BC²+AC²)/2AB

AD=AB/2+(AC²-BC²)/2AB
DB=AB-AD
DC=sqrt(AC²-AD²)

Since you want to compute only the coordinates of D, you don't need to
compute the square root.

AD=AB/2+(AC²-BC²)/2AB
DB=AB-AD

So, D is on the line AB, at a distance AD from A (positive AD is
toward B, negative AD is away from B).


(defun square (x) (* x x))
(dolist (test '( (10 3 15) (10 8 5) (10 8 8) (10 5 5) (10 5 8) (10 15 3)))
(destructuring-bind (ab ac bc) test
(let* ((ad (+ (/ ab 2) (/ (- (square ac) (square bc)) 2 ab)))
(db (- ab ad)))
(format t "AB=~3A, AC=~3A, BC=~3A ==> AD=~6A, DB=~6A~%"
ab ac bc ad db))))

AB=10 , AC=3 , BC=15 ==> AD=-29/5 , DB=79/5
AB=10 , AC=8 , BC=5 ==> AD=139/20, DB=61/20
AB=10 , AC=8 , BC=8 ==> AD=5 , DB=5
AB=10 , AC=5 , BC=5 ==> AD=5 , DB=5
AB=10 , AC=5 , BC=8 ==> AD=61/20 , DB=139/20
AB=10 , AC=15 , BC=3 ==> AD=79/5 , DB=-29/5



You can find the coordinates of D computing the unit vector AB/|AB|
and multiplying by AD: AD*AB/|AB|
Of course, it works only when A/=B, when |AB|/=0

AB = (b.x-a.x, b.y-a.y)
|AB| = sqrt(square(b.x-a.x)+square(b.y-a.y))


(defun x (v) (aref v 0))
(defun y (v) (aref v 1))
(dolist (test '( (#(0 0) #(10 0) 5 8)
(#(0 0) #(0 10) 5 8)
(#(0 0) #(7 7) 5 8) ))
(destructuring-bind (a b ac bc) test
(let* ((norm-ab (sqrt (+ (square (- (x b) (x a)))
(square (- (y b) (y a))))))
(norm-ad (+ (/ norm-ab 2)
(/ (- (square ac) (square bc)) 2 norm-ab)))
(unit (vector (/ (- (x b) (x a)) norm-ab)
(/ (- (y b) (y a)) norm-ab)))
(ad (vector (* norm-ad (x unit))
(* norm-ad (y unit)))))
(format t "A=(~A ~A), B=(~A ~A), |AB|=~3A, |AC|=~3A, |BC|=~3A ~@
~& ==> unit=(~A ~A) |AD|=~6A, AD=(~A ~A)~%"
(x a) (y a) (x b) (y b) norm-ab ac bc
(x unit) (y unit) norm-ad (x ad) (y ad)))))

A=(0 0), B=(10 0), |AB|=10 , |AC|=5 , |BC|=8
==> unit=(1 0) |AD|=61/20 , AD=(61/20 0)
A=(0 0), B=(0 10), |AB|=10 , |AC|=5 , |BC|=8
==> unit=(0 1) |AD|=61/20 , AD=(0 61/20)
A=(0 0), B=(7 7), |AB|=9.899495, |AC|=5 , |BC|=8
==> unit=(0.70710677 0.70710677) |AD|=2.9799502, AD=(2.107143 2.107143)



--
__Pascal Bourguignon__
.



Relevant Pages

  • Re: How to compute triangle base/altitude intersection
    ... I have altitude passing through vertice ... and it intersects line AB or extension of line AB at point D. ... it's called "la hauteur du triangle". ...
    (comp.programming)
  • Re: Altitude of a point in a triangle
    ... XZ grid, with their corners at various "altitudes". ... average the 4th point ANYWHERE within the triangle. ... The altitude of a triangle means the distance between one of its points ... the triangles are laid out on an XZ grid -- like XY graph paper ...
    (comp.games.development.programming.algorithms)
  • Re: Altitude of a point in a triangle
    ... The thing I'm wrestling with is how to average the 4th point ANYWHERE within the triangle. ... The altitude of a triangle means the distance between one of its points and the line defined by its other two points. ... In other words, if you change P's y-coordinate so that it is contained within that plane, what would that y-coordinate be? ...
    (comp.games.development.programming.algorithms)
  • Re: Altitude of a point in a triangle
    ... triangle is NOT vertically aligned. ... I thought that altitude would be clear from my description that it's a ... XZ grid, with their corners at various "altitudes". ... Find the distance from xx/zz to each of the corners ...
    (comp.games.development.programming.algorithms)