How to get height of triangle by midpoint
I have midpoint of triangle and also i don't other vertex information So how will i calculate height of triangle with mid-point formula?
sorry i m editing it.although this is math problem but i am making computer program.I had vertex information this is being lost in program execution so i m keeping only midpoint.So in flow of开发者_如何学JAVA program i have only midpoint information.So how will i calculate height of triangle if i have triangle vertex like (-0.5,0), (0.5,0),(0.0,1).
If you do have all three vertices, then the "height" is still not well defined. Each of the three vertices has a "height" from the corresponding opposite side. In general, these are not equal.
To get the distance of a given vertex c
from the opposite side (a,b) use cross products:
Define
a = (ax, ay)
b = (bx, by)
c = (cx, cy)
Compute:
bMinusA == b-a == (bMinusAx, bMinusAy)
= (bx - ax, by - ay)
cMinusA == c-a == (cMinusAx, cMinusAy)
= (cx - ax, cy - ay)
Compute:
bMinusCcrossCMinusA == |(b-a)^(c-a)|
= abs(bMinusAx* cMinusAy - bMinusAy*cMinusAx)
Then:
heightCfromAB = bMinusCcrossCMinusA/ length(bMinusA)
= bMinusCrosscMinusA/ sqrt( bMinusAx*bMinusAx+ bMinusAy* bMinusAy)
Note that if you permute the vertices, you always get the same for the cross-product ( bar a sign), as it is twice the area of the triangle.
The heights then vary inversely with the length of the opposite side.
So if you like, you can find the greatest height by first finding the shortest side and using that.
Correction: Original expression for cross product had a typo. Corrected.
精彩评论