i'm trying write script (javascript) in api of virtual table top program can manipulate tokens (car wars :)).
i'm sort of finding answer, seems i'm struggling , reinventing wheel thought i'd ask help. 1 reason i'm getting confused program returns results based on +y down , deg go clockwise different trig formulas want (counter clockwise , +y up).
here have access to. rectangle rotates around centre, centre point(x,y), width, height, , rotation. i've got code working moving rectangle in direction of rotation, side side, , down, etc. need able rotate around of 4 corners or point nice, 4 corners thats needed.
it won't let me include image since i'm new hope description enough. had image done up. :(
in api can't draw rectangle, can set rotation, , centre value. thought if can find x,y of 1 corner currently, rotate desired degs around centre (i can setting rectangles rotation), find new x,y of same corner. know offset , apply centre (thats how rectangle moved well).
so need able find x,y of corner of rectangle @ given starting angle, again @ new angle rotated @ centre. offset applied centre x,y , rectangle see have rotated along 1 of corners.
thanks can give. i'm hoping figure out, writing description out has helped me think through. i'm stuck!
konrad
the trick rotating around arbitrary point in 2d (eg, 1 of 4 corners of rectangle), first translate vertices of shape point around want rotate in origin (ie 0,0).
to achieve this:
1. translate rectangle (-x, -y).
2. rotate rectangle desired angle.
3. translate rectangle (x, y) place was.
(x,y) x/y coordinates of point around rotate.
you can use negative angles adjust clockwise rotations.
there lot of info on net, example: http://www.siggraph.org/education/materials/hypergraph/modeling/mod_tran/2drota.htm
Comments
Post a Comment