Poru
Poru

Reputation: 8360

JavaScript: Rotate Polys

My code doesn't work right:

function rotate(Points, Angle) {
    for (var i=0; i<Points.length;i++) {
        Points[i] = [Math.cos(Angle) * Points[i][0] - Math.sin(Angle) * Points[i][1], Math.sin(Angle) * Points[i][0] + Math.cos(Angle) * Points[i][1]];
    }
    return Points;
}


rotate([[0, 0], [50, 0], [25, 25]], 5);

I used the following: http://www.vb-helper.com/howto_rotate_polygon_points.html

Upvotes: 0

Views: 179

Answers (1)

kennytm
kennytm

Reputation: 523264

cos and sin in most programming languages are in radians. Are you sure you want to rotate by 5 radians (= 286 degrees)?

Upvotes: 2

Related Questions