叉积的输出
我正在尝试获得两个向量的“叉积”。这两个向量代表两个平面。所以,我的向量为 a1,b1,-1
和 a2,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这使得 c1 未初始化。使用:
This leaves c1 uninitialized. Use:
数学看起来是正确的。放置快速 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.