c++ /MathGL:对向量域的错误理解
C++/MathGL: Missunderstanding of vector fields
我在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)
最好的祝愿,托马斯
- C++中函数的向量返回类型引发错误
- 尝试将unique_ptrs推送到向量时使用纯虚拟函数错误
- 在c++中键入向量中的所有值后,得到分段错误(核心转储)
- 如何使用C++初始化向量;脚本化值不是数组、指针或矢量错误
- 为什么程序在 c++ 中迭代 emtpy 向量时会抛出运行时错误
- 使用全局声明的向量时,C++双重释放错误/损坏
- 代码使用向量成功运行,但使用数组显示错误
- C++ 随机数生成器:尝试将结果作为向量获取,但通过制作 void 函数来执行此操作而出现错误
- 全局向量导致 C++ 程序结束时出现段错误
- 为什么我在向量初始化时收到此错误?
- 在C++中比较来自向量的字符串时出现分段错误
- 将图形表示为unordered_map<字符串、向量>时拓扑排序错误<string>
- 为什么在向量上使用 std::find() 时会出现错误?
- 分割错误:向量中的擦除功能
- 编译错误向量排序和联合
- SIGBART 错误向量<列表<myClass>>
- 编译错误 ::向量 ::迭代器
- 为什么 std::copy 抛出错误向量迭代器 + 偏移量超出范围并且无法复制
- C++STL set_union获取错误向量迭代器+偏移量超出范围
- C++错误向量无法正确输出