简体   繁体   中英

How to calculate points in a shape when shape is rotated

I have a bunch of different shapes and on these shapes there 20 points laid out in a grid. What I am trying to figure out is how to calculate where these points are when a shape is rotated, the shapes can be rotated any degree from the center of the shape. The points are placed from the top left of the shape.

在此处输入图片说明

在此处输入图片说明

Here are a couple of examples of shapes with the points I want to be able to calculate as the shape is rotated. I have all of the x/y coordinates for all of the shapes at 0 degrees. I am build a JavaScript app so if someone has any functions in JavaScript for this that would be great or if you could direct me to somewhere with some resources for this.

To rotate point (Xold,Yold) about center point (Xc, Yc) by angle Angle counter clockwise, you can use complex affine transformation , composed from translation of rotation center to origin, rotation around origin, and back translation. Resulting formula:

Xnew = Xc + (Xold - Xc) * Cos(Angle) - (Yold-Yc) * Sin(Angle)
Ynew = Yc + (Xold - Xc) * Sin(Angle) + (Yold-Yc) * Cos(Angle)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM