Hello,
I have a triangle ABC,
I know all points' coordinates A(x1, y1), B(x2, y2), C(x3, y3)
I want to draw a vertical edge from A to [BC]
How can i calculate?
Thanks your advance
Hello,
I have a triangle ABC,
I know all points' coordinates A(x1, y1), B(x2, y2), C(x3, y3)
I want to draw a vertical edge from A to [BC]
How can i calculate?
Thanks your advance
First, you have to find the slope of [BC] by s = (y3-y2) / (x3 - x2). m = (-1/s) gives you the slope of normal of [BC]. By that, y = mx + b you can take find the equation of the line of vertical that you want to draw. As x and y, you must put x1 and y1 of A. After you find this equation, you can do all sort of things you want I guess.
What you call "vertical edge" is the altitute (i.e. segment [AH], orthogonal to [BC])?
If yes then calculate BH/CH ratio. First use trigonometrical relations in the right triangles ABH and ACH (do it for acute triangle, in obtuse the relations will be the same), then use of Law of cosines. You'll have a neat formula, where this ratio is expressed only in squares of lengths of triangle's sides. Calculate square of a side is easy, since you know cartesian coordinates of the points.
You'll get BH/CH = x/y. Rewrite it as BH*y = CH*x to avoid division by zero. Write this via vectors. And do the calculation, taking, again, special care of division by zero.
draw a line from (x1, y1) to x1, ((y3-y2) / (x3-x2)) * (x1-x2) + y2
I assume you want the point where A projects onto the line determined by B and C. You can look up "vector projection" to find the math details.
multiplier = (double)((x1 - x2)*(x3 - x1) + (y1 - y2)*(y3 - y2)) /
(double)((x3 - x1)*(x3 - x1) + (y3 - y1)*(y3 - y1)); // dot products
x = x2 + multiplier * (x3 - x2);
y = y2 + multiplier * (y3 - y2);
There is a division by zero problem if B and C are the same point. (They wouldn't determine a line in that case.) So check for that first.
Interesting, and a bit confusing. You want to draw a vertical line from A to BC. Not a Perpendicular line, but a vertical line! Well, that's easy! Draw from (x1, 0) to e.g. (x1, 1024). That should draw your vertical line.
To keep it in the triangle, you have to make sure that x1 is between x2 and x3, otherwise, the vertical line doesn't go through BC. Next, you need to calculate the point where this line should go through BC. If x1 == x2 then draw from A to B. If x1 == x3 then draw from A to C. Otherwise, you need to calculate the line that goes through B and C and this requires some math. Basically, we need to get something like Y=>aX+b. We can calculate a by this:
a = (y2-y3)/(x2-x3)
Next, we need to calculate b, like this:
b = y2 - (a*x2)
Now we'll calculate the value for y where x equals x1:
y = a*x1 + b
Example, A=(3,2), B=(1,4), C=(5,6) Thus, a would be (4-6)/(1-5) => -2/-4 = 0.5 And b would be 4-(0.5*1) => 3.5 Next, y. And y = 0.5*3 + 3.5 = 5.
So, you need to draw a line from (3,2) to (3,5) to get a vertical line!
Just hoping this is what you wanted. Was it homework?