# vector results inconsistent what am I doing?[SOLVED]

Hi, I am getting 2 different vector-cross product results, one from OpenCV and different from OpenCV but same with each other from Symbolab Vector-Cross Calculator & the following video 6.17 tutorial on calculating plane equation.

Here are the 2 vectors PQ & PR. Try them initially with OpenCV and Symbolab:

Mat PQ = (Mat_<float>(3, 1) << 1.0, -1.0, 0.0);
Mat PR = (Mat_<float>(3, 1) << 1.0, 0.0, -1.0);

Mat vec_cross_result = (Mat_<float>(3, 1) << 0.0, 0.0, 0.0);
cv::multiply(PR, PQ, vec_cross_result);
std::cerr << PQ << " " << PR << "  " << std::endl << "Result: " << std::endl << vec_cross_result << std::endl;
[1,-0,-0]  //OpenCV result


Using dedicated vectors Vec3f below instead of a 3 x 1 matrix above, and got the same OpenCV as with Mats, to no surprise...

cv::Vec3f A(1.0, -1.0, 0.0), B(1.0, 0.0, -1.0), vector_cross;
std::cerr << A << std::endl;
std::cerr << B << std::endl;
multiply(A, B, vector_cross);
std::cerr << "Vector result:" << vector_cross << std::endl;


Symbolab result is [1,1,1]. Video tutorial the same 6:17.. What am I overlooking?

edit retag close merge delete

Sort by ยป oldest newest most voted

cv::multiply is not a cross product. It is an element-wise product.

You want to do

vec_cross_result = PQ.cross(PR);

more

Excellent! Thank you!

std::cout << "by Mat" << std::endl;
Mat PQ = (Mat_<float>(3, 1) << 1.0, -1.0, 0.0);
Mat PR = (Mat_<float>(3, 1) << 1.0, 0.0, -1.0);
Mat  vec_cross_result = (Mat_<float>(3, 1) << 0.0, 0.0, 0.0);
vec_cross_result = PQ.cross(PR);
std::cerr << PQ << " " << PR << "  " << std::endl << "Result: " << std::endl << vec_cross_result << std::endl;


Result [1,1,1] - correct

    std::cout << "by vector";
cv::Vec3f A(1.0, -1.0, 0.0), B(1.0, 0.0, -1.0), vec_cr_result;
std::cerr << A << " " << B << " " << vec_cr_result << std::endl;
vec_cr_result = A.cross(B);
std::cerr << A << " " << B << "  " << std::endl << "Result: " << vec_cr_result<<std::endl;


Result[1,1,1]-correct

( 2020-01-19 10:50:26 -0500 )edit

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2020-01-18 20:50:33 -0500

Seen: 115 times

Last updated: Jan 19