【发布时间】:2011-09-16 06:22:36
【问题描述】:
所以我在这里有一个数学函数,假设返回一个旋转的点,并取一个原点,指向旋转的点(原点)和弧度来旋转它。
但是它只以半速旋转(又名 180 度移动 = 90 度旋转)
sf::Vector2f RotatePoint(sf::Vector2f origin, sf::Vector2f point, float radian) {
float s = sin(radian);
float c = cos(radian);
// translate point back to origin:
point.x -= origin.x;
point.y -= origin.y;
// rotate point
float xnew = point.x * c - point.y * s;
float ynew = point.x * s + point.y * c;
// translate point back to global coords:
sf::Vector2f TranslatedPoint;
TranslatedPoint.x = xnew + origin.x;
TranslatedPoint.y = ynew + origin.y;
return TranslatedPoint;
}
【问题讨论】:
-
为什么要就地修改点参数?
-
您的问题是什么?结果值是多少?
-
您能否也发布您的调用代码以及预期和实际结果?我相信代码有效,您是否正确计算了弧度测量值?
标签: c++ algorithm function math rotation