C ++ - 如何获得旋转圆柱的点?

时间:2014-09-09 23:42:12

标签: c++ 3d curve

我需要一个"旋转圆筒"的点。我已经获得了一些曲线,并寻找一个实现来计算16个点,以便他们获得一个循环。我的实现如下:

QPointF MappingModel::calcThicknessYarns(float fCurrentX, float fCurrentY, int iCurrentCounter)
{
QPointF nextPoint;

int iAmountOfThicknessYarns = 16;
float fSingleAngle = 360.0 / iAmountOfThicknessYarns;

float fCurrentAngle = fSingleAngle * iCurrentCounter;

nextPoint = getXY(fCurrentAngle, 1.0, 1.0, fCurrentX, fCurrentY);

return nextPoint; 
}

QPointF MappingModel::getXY(float angle, float width, float height, float xOffset, float yOffset)       
{
QPointF xy;

float FI = angle*PIdev;
xy.setX((width * qCos(FI)) + xOffset) ;
xy.setY((height * qSin(FI)) - yOffset);

return xy;
}

我看起来像这样:

http://www.directupload.net/file/d/3741/e8bafwni_jpg.htm http://www.directupload.net/file/d/3741/tkykay7w_jpg.htm

如您所见,垂直圆柱体工作正常,但曲线为假

1 个答案:

答案 0 :(得分:0)

这可能有所帮助。

Vertex改为QPointF应该不难。

typedef struct {
    double x;
    double y;
} Vertex;

/**
 * @param radius Radius of circle
 * @param angle Degrees
 * @return The offset of vertex from the center of circle given radius and angle
 */
Vertex getVerticeOffset(double radius, double angle) {
    double yOffset = -radius*cos((90 - angle)*M_PI/180);  // convert to radians
    return Vertex({(angle >= 90 && angle < 270 ? -1 : 1) * sqrt(pow(radius, 2) - pow(yOffset, 2)), yOffset});
}