Find the last coordinate of an isosceles triangle with given base and height coordinates
I have no idea about trigonometry even though he is in school when I think it should be pretty easy but trawling through tons of triggers on the internet makes my head ache :) So maybe someone can help me ...
The title explains what exactly I want to do, I have a line: x1, y1 and x2, y2 and want the function to find x3, y3 to complete an isosceles triangle given the height.
To be clear, the line x1, y2 -> x2, y2 will be the base and it will not be aligned to any axis (it will be at a random angle.)
Does anyone have a simple function for this?
construct a normal to the vector (x1, y1) → (x2, y2). place it in the middle of ((x1 + x2) / 2, (y1 + y2) / 2) and go out to distance h.
the normal will look like (- (y2-y1), x2-x1). make it a unit vector ( http://en.wikipedia.org/wiki/Unit_vector ).
add h times this unit vector to the midpoint.
source to share
The third point is at the perpendicular bisector of your base and is at a distance altitude
from the line.
- Calculate the midpoint of the datum by averaging the x and y coordinates.
- Calculate the slope of your height: -dx / dy (perpendicular to dy / dx). You now have your line (point and slope).
- y - my = -dx / dy * (x - mx)
- Replace the variables in the distance formula: d = sqrt (dx ^ 2 + dy ^ 2)
- d = sqrt ((x - mx) ^ 2 + (y - my) ^ 2)
- d = sqrt ((x - mx) ^ 2 + (-dx / dy * (x - mx)) ^ 2)
- d ^ 2 = (x - mx) ^ 2 + (-dx / dy * (x - mx)) ^ 2
- d ^ 2 - (x - mx) ^ 2 = (-dx / dy * (x - mx)) ^ 2
- ± sqrt (d ^ 2 - (x - mx) ^ 2) = -dx / dy * (x - mx)
- ± sqrt (d ^ 2 - (x - mx) ^ 2) * dy / dx = x - mx
- ± sqrt (d ^ 2 - (x - mx) ^ 2) * dy / dx + mx = x
- x = ± sqrt (d ^ 2 - (x - mx) ^ 2) * dy / dx + mx
- Calculate the other variable (y here) using your linear equation (from # 2).
- You now have two points; choose what you want ...
In pseudocode:
dx = x1 - x2
midpoint = ((x1 + x2) / 2, (y1 + y2) / 2)
slope = -dx / (y1 - y2)
x = sqrt(altitude*altitude - dx*dx) / slope + midpoint.x
y = slope * (x - midpoint.x) + midpoint.y
This is probably not the most optimal method. Not sure if it works. XD
source to share