首页 > 解决方案 > 有没有一种方法可以根据不同的变量重新计算和方程?

问题描述

我目前是 AP Calculus BC 的大四学生,并接受了在 C++ Qt 中复制主题的挑战。本主题涵盖了曲线下面积的积分,以及所述区域的旋转以形成具有确定体积的实体模型。

在此处输入图像描述

我已经成功旋转了一个自定义方程,定义为:

double y = abs(qSin(qPow(graphXValue,graphXValue))/qPow(2, (qPow(graphXValue,graphXValue)-M_PI/2)/M_PI))

或者

方程

我的问题是如何围绕 Y 轴而不是 X 轴旋转这样的方程。有没有什么方法可以用 y 而不是 x 来近似求解这个方程?目前是否有此类任务的任何实现?

请记住,我正在计算 3D 坐标系中转换的每个点:

for (float x = 0.0f; x < t_functionMaxX - t_projectionStep; x+=t_projectionStep)
{
    currentSet = new QSurfaceDataRow;
    nextSet = new QSurfaceDataRow;

    float x_pos_mapped = x;
    float y_pos_mapped = static_cast<float>(ui->customPlot->graph(0)->data()->findBegin(static_cast<double>(x), true)->value);

    float x_pos_mapped_ahead = x + t_projectionStep;
    float y_pos_mapped_ahead = static_cast<float>(graph1->data()->findBegin(static_cast<double>(x + t_projectionStep), true)->value);

    QList<QVector3D> temp_points;
    for (float currentRotation = static_cast<float>(-2*M_PI); currentRotation < static_cast<float>(2*M_PI); currentRotation += static_cast<float>((1) * M_PI / 180))
    {
        float y_pos_calculated = static_cast<float>(qCos(static_cast<qreal>(currentRotation))) * y_pos_mapped;
        float z_pos_calculated = static_cast<float>(qSin(static_cast<qreal>(currentRotation))) * y_pos_mapped;

        float y_pos_calculated_ahead = static_cast<float>(qCos(static_cast<qreal>(currentRotation))) * y_pos_mapped_ahead;
        float z_pos_calculated_ahead = static_cast<float>(qSin(static_cast<qreal>(currentRotation))) * y_pos_mapped_ahead;

        QVector3D point(x_pos_mapped, y_pos_calculated, z_pos_calculated);
        QVector3D point_ahead(x_pos_mapped_ahead, y_pos_calculated_ahead, z_pos_calculated_ahead);

        *currentSet << point;
        *nextSet << point_ahead;

        temp_points << point;
    }
    *data << currentSet << nextSet;


    points << temp_points;
}

标签: c++qtalgebracalculusqcustomplot

解决方案


本质上,您(x,f(x),0)围绕 Y 轴旋转矢量,因此 Y 值保持不变,但 X 和 Y 部分会根据旋转而变化。

static_cast<float>我还通过显式调用构造函数替换了所有部分float,这(我发现)读起来更好一些。

// Render the upper part, grow from the inside
for (float x = 0.0f; x < t_functionMaxX - t_projectionStep; x+=t_projectionStep)
{
    currentSet = new QSurfaceDataRow;
    nextSet = new QSurfaceDataRow;

    float x_pos_mapped = x;
    float y_pos_mapped = float(ui->customPlot->graph(0)->data()->findBegin(double(x), true)->value);

    float x_pos_mapped_ahead = x + t_projectionStep;
    float y_pos_mapped_ahead = float(graph1->data()->findBegin(double(x + t_projectionStep), true)->value);

    QList<QVector3D> temp_points;
    for (float currentRotation = float(-2*M_PI); currentRotation < float(2*M_PI); currentRotation += float((1) * M_PI / 180))
    {
        float x_pos_calculated = float(qCos(qreal(currentRotation))) * x_pos_mapped;
        float z_pos_calculated = float(qSin(qreal(currentRotation))) * x_pos_mapped;

        float x_pos_calculated_ahead = float(qCos(qreal(currentRotation))) * x_pos_mapped_ahead;
        float z_pos_calculated_ahead = float(qSin(qreal(currentRotation))) * x_pos_mapped_ahead;

        QVector3D point(x_pos_calculated, y_pos_mapped, z_pos_calculated);
        QVector3D point_ahead(x_pos_calculated_ahead, y_pos_mapped_ahead, z_pos_calculated_ahead);

        *currentSet << point;
        *nextSet << point_ahead;

        temp_points << point;
    }
    *data << currentSet << nextSet;


    points << temp_points;
}

接下来,您需要添加底部“盘子”。这只是一堆三角形,它们与围绕 Y 轴(0,0,0)旋转的两个相邻点连接(1,0,0),就像我们在上面所做的那样。

最后,如果f(t_functionmaxX)不为零,则需要添加连接(t_functionmaxX, f(t_functionmaxX), 0)到的边(t_functionmaxX, 0, 0),再次绕 Y 轴逐步旋转。

请注意,如果 y < 0,这会做一些奇怪的事情。你想如何解决这个问题取决于你。


推荐阅读