-
2D rotation problem
Hi, I'm starting to experiment with the drawing API and I can't figure this thing out... I'm trying to rotate 2D points about the origin... but when it rotates... it also sizes it down... something must be wrong with my math... can you tell?
function rotatePoly(){
var theta = ((Math.PI*degree.text)/180.0);
for(var i=0;i<thisPolygon.length;i++){
thisPolygon[i].x = Math.cos(theta)*thisPolygon[i].x-Math.sin(theta)*thisPolygon[i].y;
thisPolygon[i].y = Math.sin(theta)*thisPolygon[i].x+Math.cos(theta)*thisPolygon[i].y;
}
drawPoly();
}
-
Senior Member
Err, I'm not sure if this is whats causing the problem, but have you noticed that you are rotating the x co-ordinate, and then using the rotated x to calculate the y. This is likely to cause some strange problems.
I usually use different variables for rotated and original co-ordinates anyway, as they can deform slightly over time if you rotate them a lot.
-
AHA!
now why didnt i notice that? thanks for pointing that out...that was exactly the problem...
-
Senior Member
No problem.
It took me ages to figure out what was wrong the first time I did that too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|