【问题标题】:C++ - How to get points of rotating cylinder?C++ - 如何获得旋转圆柱体的点?
【发布时间】:2014-09-09 23:42:11
【问题描述】:

我需要一个“旋转圆柱体”的点。我有一些曲线,并正在寻找一种实现来计算它们周围的 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

如您所见,垂直圆柱体工作正常,但曲线是错误的

【问题讨论】:

    标签: c++ 3d curve


    【解决方案1】:

    这可能会有所帮助。

    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});
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-07
      • 2012-09-26
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-01
      • 2021-05-31
      相关资源
      最近更新 更多