Thursday, 15 August 2013

java - How to rotate triangle around center? -



java - How to rotate triangle around center? -

i drawing triangle on canvas:

float x = 540; float y = 960; path path = new path(); path.moveto(x, y); path.lineto(x+18, y+60); path.lineto(x-18, y+60); path.lineto(x, y); canvas.drawpath(path, mpaint);

this canvas has objects. need rotate triangle around center of triangle on random angle (between 0 , 360). how implement it? how coordinates vertexes of triangle after rotation?

its simple math, if center of triangle (x,y) , center-vertex distace a, 3 vertex

-(a*math.cos(angle),a*math.sin(angle))

-(a*math.cos(angle+2*math.pi/3),a*math.sin(angle+2*math.pi/3))

-(a*math.cos(angle-2*math.pi/3),a*math.sin(angle-2*math.pi/3))

java android math geometry

No comments:

Post a Comment