c++ /MathGL:对向量域的错误理解

C++/MathGL: Missunderstanding of vector fields

本文关键字:错误 向量 MathGL c++      更新时间:2023-10-16

我在Windows 10下使用MathGL 2.3.5.1 (http://mathgl.sourceforge.net/doc_en/Main.html)与Qt 4.8.7。

我有问题使用MathGL的矢量场。有一个MathGL的文档,文件名为MathGL -2.3.5.eng.pdfhttps://sourceforge.net/projects/mathgl/files/mathgl/mathgl%202.3.5/"4.15向量字段"一节描述了"Vect"方法的用法。当然,在"2.8向量场示例"一节中有一个向量场示例。

首先,我对向量场的理解是,有点(在我的情况下,它总是在2D中)和(数学上)向量。所以点P1(1,1)和向量V1(1,1)的组合意味着箭头从点P1(1,1)开始,到点P2(2,2)结束,这是一个简单的向量加法:P2 = P1 + V1。

现在回到MathGL。我说的是这个方法:void Vect (const mglDataA &x, const mglDataA &y, const mglDataA &ax, const mglDataA &ay, const char *sch=", const char *opt=");

如果我正确理解了参数,那么

  • x表示箭头的起始点,单位为x
  • y表示箭头的起始位置,单位为y
  • ax表示x方向上的单位(数学上)向量
  • ay表示y方向上的单位(数学上)向量

让我们从编码开始。

int sample(mglGraph *gr)
{
    long cols=2;
    long rows=2;
    mglData x;    x.Create(cols, rows);
    x.a[0] = 1.0;    x.a[1] = 0.0;    x.a[2] = 0.0;    x.a[3] = 0.0;
    mglData y;    y.Create(cols, rows);
    y.a[0] = 1.0;    y.a[1] = 0.0;    y.a[2] = 0.0;    y.a[3] = 0.0;
    mglData ax;    ax.Create(cols, rows);
    ax.a[0] = 1.0;    ax.a[1] = 0.0;    ax.a[2] = 0.0;    ax.a[3] = 0.0;
    mglData ay;    ay.Create(cols, rows);
    ay.a[0] = 1.0;    ay.a[1] = 0.0;    ay.a[2] = 0.0;    ay.a[3] = 0.0;
    gr->Title("Vector field P1(1,1) V1(1,1)");
    gr->SetRanges(0, 3, 0, 3);
    gr->Vect(x, y, ax, ay, "<");
    gr->Box();
    gr->Axis();
    gr->Grid("xy", "h:");
    return 0;
}

首先,我不能为x y ax和ay创建"列向量"这意味着我不能写:

long cols=1;
long rows=2;
mglData x; x.Create(cols, rows); x.a[0] = 1.0; x.a[1] = 0.0;
mglData y; y.Create(cols, rows); y.a[0] = 1.0;  y.a[1] = 0.0;
mglData ax; ax.Create(cols, rows); ax.a[0] = 1.0; ax.a[1] = 0.0;
mglData ay; ay.Create(cols, rows); ay.a[0] = 1.0; ay.a[1] = 0.0;

Then gr->Vect(x, y, ax, ay, "<");将此消息放在控制台中:

MathGL message - Vect: data dimension(s) is too small
在这段代码中,我们设置了Point P1: x.a[0] = 1.0;y.a[0] = 1.0;向量V1应该用ax表示。A [0] = 1.0;和啊。A [0] = 1.0;.

生成的图形显示一个从P1(1,1)开始但不结束于P2(2,2)的箭头。

谁能帮我解决这个问题?

问候,托马斯

为了我的目的,我找到了一个解决方案。我用手画"向量"。因此,我只使用以下代码来绘制矢量:

mglGraph gr;
gr.Line(1,1, 2,2), "BA_"); // a vector from (1,1) to (2,2)

最好的祝愿,托马斯