How to rotate triangle such that its base is flat straight?

148 views Asked by At

considering my English is not very good. I will try to use picture

enter image description here

Hopefully you can get what I mean. Basically what I want is I want to rotate the triangle such that the base of the triangle is flat straight ( horizontally straight). Keep in mind, that the triangle is a shape. and I know the coordinate of each point, and each midpoint of each edges. How would I do that?

2

There are 2 answers

4
O.B On

This seems to be an equilateral triangle so could you not just rotate the triangle 120 degrees?

If not you could use Math.atan. So plainly put you can get the x and y coordinates of a and c. Use the difference between the x's and y's to give you two vectors. Then x = adjacent, y = opposite and so Math.atan(Opp, Adj) = angle. Then select your object and rotate it an extra value of angle.

https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Math.html#atan()

Think thats what you're after

Edit

enter image description here

So this image is what I think you are after. I randomly drew a triangle. Now you want B.y = C.y. So if you get the angle of r you should be able to use that to rotate the triangle the correct amount so that B.y = C.y.

You will have to consider what if B.y > C.y and adapt this to make it work 100%, but in this example this should work.

0
VC.One On

(1)

"Basically what I want is to rotate the triangle such that the base of the triangle is flat straight (horizontally straight)."

You can simply set as point_C.y = point_B.y (this will put point C on same vertical height as point B so that now, a horizontal line between those two points will be a straight line.

(2)

"The point the triangle is formed by mouse click. Each mouse click, I make point at (mouseX, mouseY). So, the triangle could be totally random."

I would make a var to keep count of clicks...

//# count clicks to know when straight line is needed
public var count_Clicks :uint = 0;

//# straight line via "IF" statement
private function draw_Triangle_Point (evt :MouseEvent) : void    
{
    count_Click += 1; //add plus 1

    if (count_Clicks == 3)
    {
        point_C.x = stage.mouseX;
        point_C.y = point_B.y; //straight (horiz) line

        count_Clicks = 0; //reset
    }
    else
    {
        //draw your other two points
    }

}

Hope it helps.