我目前是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;
}
最佳答案
本质上,您绕着Y轴旋转了 vector (x,f(x),0)
,因此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;
}
接下来,您需要添加底部的“板”。就像我们上面所做的那样,这只是一堆三角形,将
(0,0,0)
与(1,0,0)
绕Y轴旋转的两个相邻点相连。最后,如果
f(t_functionmaxX)
不为零,则需要添加一个将(t_functionmaxX, f(t_functionmaxX), 0)
连接到(t_functionmaxX, 0, 0)
的边,并再次绕Y轴逐步旋转。请注意,如果y <0,这将做一些奇怪的事情。如何解决取决于您自己。
关于c++ - 是否有一种方法可以根据不同的变量重新计算和方程式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61100193/