Page 1 of 1

rotating a triangle

PostPosted: Fri Dec 07, 2007 6:52 pm
by antix
Part of the game im creating uses lines to create a ship, in the shape of a triangle. What I was planning on doing, was use a center point, then draw the 3 edges of the triangle relative to the center, with the top point in the direction that the 'ship' is facing. I believe I could use cos and sine to get the direction, and move the points to the correct positions. What my problem is, is that I have no idea how to do this. My understanding of cos and sine is limited, so could anyone give me a hand? Give me an example, formula, or a suggestion? Any help would be seriously appriciated. Thanks.

Re: rotating a triangle

PostPosted: Sat Jan 12, 2008 10:20 pm
by picstart
Well much depends on the resolution of the angles. If the resolution is coarse say every 15 degs of rotation a look up table with the cartesian coordinates of the vertices would work. A line drawing algorith (Breshenham Ex) would draw the lines between the vertices. For fine resolution deg of arc then I'd look at the CORDIC to rotate the (x.y) or if you prefer sine and cosine values this is the math
coords (x,y) are rotated through angle a to (x',y')
x'=x.cos(a)-y.sin(a)
y'=y.cos(a)+x.sin(a)
Watch out for quadrant issues sin and cos are cyclical.