叉积的输出

发布于 2024-10-18 13:49:14 字数 938 浏览 1 评论 0原文

我正在尝试获得两个向量的“叉积”。这两个向量代表两个平面。所以,我的向量为 a1,b1,-1a2,b2,-1。 (我使用的平面方程为ax+by-z+d=0)。

这是我定义的获取叉积的函数;

vector<double> cross_vector(vector<double> plane1,vector<double> plane2){
vector<double> cross_product;
double a1=plane1.at(0); double a2=plane2.at(0);
double b1=plane1.at(1); double b2=plane2.at(1);
int c1,c2=-1;
double cross_a=(b1*c2)-(b2*c1);
double cross_b=(a2*c1)-(a1*c2);
double cross_c=(a1*b2)-(a2*b1);
cross_product.push_back(cross_a);
cross_product.push_back(cross_;
cross_product.push_back(cross_c);

return cross_product;
}

对于不同平面组合的结果,我得到如下结果;

 523554   -1.3713e+006  -0.00160687

 556340   -1.43908e+006  0.00027957

-568368    1.46225e+006 -0.00034963

 143455   -380017       -0.00027957 

我无法理解像 1.46225e+006 这样的值?我的功能有什么问题吗? 我知道,我得到的交叉向量应该完全水平定向。那么,您能否告诉我如何检查我的交叉向量是否水平? 希望您的建议。

i am trying to get the 'cross product' of two vectors. these two vectors represent two planes. so, my vectors are as a1,b1,-1 and a2,b2,-1. (I used, my plane equation as ax+by-z+d=0).

this was my defined function to get the cross product;

vector<double> cross_vector(vector<double> plane1,vector<double> plane2){
vector<double> cross_product;
double a1=plane1.at(0); double a2=plane2.at(0);
double b1=plane1.at(1); double b2=plane2.at(1);
int c1,c2=-1;
double cross_a=(b1*c2)-(b2*c1);
double cross_b=(a2*c1)-(a1*c2);
double cross_c=(a1*b2)-(a2*b1);
cross_product.push_back(cross_a);
cross_product.push_back(cross_;
cross_product.push_back(cross_c);

return cross_product;
}

for the result i got as below result for different plane combinations;

 523554   -1.3713e+006  -0.00160687

 556340   -1.43908e+006  0.00027957

-568368    1.46225e+006 -0.00034963

 143455   -380017       -0.00027957 

i can't understand the values like 1.46225e+006? is there any wrong with my function?
i know, my resultant cross vector should be directed exactly horizontal. So, could you also tell me how can i check whether my cross-vector is horizontal or not?
hope your advices.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终弃我 2024-10-25 13:49:14
int c1,c2=-1;

这使得 c1 未初始化。使用:

int c1=-1, c2=-1;
int c1,c2=-1;

This leaves c1 uninitialized. Use:

int c1=-1, c2=-1;
遥远的她 2024-10-25 13:49:14

数学看起来是正确的。放置快速 A = <1,0,0>且B=<0,1,0>在<0,0,1>的背面给出了合理的结果。 e 符号表示 e 后面的数字乘以 10 次方。所以这些也可能是合理的,但很难说,因为从你的例子中我无法告诉你的输入值是什么。不过,我个人不会直接返回该值 - 我更愿意作为引用或指针返回,以防止不必要的复制。另外,正如上面的海报提到的,你确实有一个初始化的变量。

The math looks correct. Placing a quick A = <1,0,0> and B = <0, 1, 0> gave a reasonable result on the backside of <0, 0, 1>. The e notatin represent the number times 10 to the power after the e. So those might be reasonable as well, but it's hard to say as from your example I can't tell what your input values were. I wouldn't personnaly return the value directly though - I'd prefer to return as a reference or pointer to prevent needless copying. Also, as the above poster mentioned, you do have an initialized var.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文