简体   繁体   English

如何围绕质心旋转/缩放/平移

[英]How to rotate/scaling/translate about centroid

rotating
x' = x*Cos(angle) - y*Sin(angle)
y' = x*Sin(angle) + y*Cos(angle)
Scaling
x' = x*sx
y' = y*sy
translate
x' = x+tx
y' = y+ty

but all formulas will doing about origin point. 但是所有公式都可以处理原点。 If i want to do about Centroid point. 如果我想做质心点。 (I have (Cx,Cy) ). (我有(Cx,Cy))。 What the formulas will be. 公式将是什么。

Sorry, about english, I will practice more. 对不起,关于英语,我会练习更多。

Thanks. 谢谢。

Translate so that the centroid is the origin, rotate, translate back. 平移以使质心为原点,旋转,平移回去。 That is, if you have coordinates for a point (x,y)=(Cx,Cy)+(xr,yr) where (x,y) is the point you want to rotate around the centroid, (Cx,Cy) is the coordinates of the centroid, and (xr,yr) is the position of the point relative to the centroid. 也就是说,如果您有一个点(x,y)=(Cx,Cy)+(xr,yr) (x,y)其中(x,y)是要绕形心旋转的点,则(Cx,Cy)为质心的坐标, (xr,yr)是点相对于质心的位置。 Then you can rotate (xr,yr) and add it to Cx,Cy) . 然后,您可以旋转(xr,yr)并将其添加到Cx,Cy)

Translate the object so that the centroid coincides with the origin, then perform whatever transformation, then translate it back. 转换对象,使质心与原点重合,然后执行任何转换,然后将其转换回原点。

Depending what you're using to implement geometry, you might be able to linearly compose these operations before performing the heavy lifting. 根据您用于实现几何图形的内容,您可能可以在执行繁重的操作之前线性地组合这些操作。 Or your library might provide versions of the operations with an invariant point as an argument, for which you can specify the centroid. 或者您的库可能会提供带有不变点作为参数的操作版本,您可以为其指定质心。

But there's nothing special about transforming about the centroid as opposed to any other point. 但是,与其他任何点相比,对质心进行转换没有什么特别的。

That's what the translation is for. 这就是翻译的目的。 Translating moves the origin to a new point (more properly, it establishes a new coordinate system whose origin coincides with the point specified in the original coordinate system). 平移将原点移动到新点(更恰当地,它将建立一个新坐标系,其原点与原始坐标系中指定的点重合)。 In a typical graphics implementation using affine matrix transformations, this new origin will be the center for any rotations performed after it. 在使用仿射矩阵变换的典型图形实现中,此新原点将是其后进行的任何旋转的中心。

You can see this from the equations, if you compose them. 如果将它们组成,则可以从方程式中看到。 Say we want to place a figure rotating around point (200, 200). 假设我们要放置一个围绕点(200,200)旋转的图形。

// translate to new origin
x' = x + 200
y' = y + 200
// rotate by 90 degrees
x'' = x'*cos(90) - y'*sin(90) 
    = x*cos(90) + 200*cos(90) - y*sin(90) - 200*sin(90)
    = x*cos(90) - y*sin(90) + 200
y'' = x'*sin(90) + y'*cos(90)
    = x*sin(90) + 200*sin(90) + y*cos(90) + 200*cos(90)
    = x*sin(90) + y*cos(90) + 200

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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