简体   繁体   中英

Find direction of given x,y,z cordinates

i'm new to opencv & it's developing. I have x,y,z coordinates ( 0.00949334694383068, -0.3999829847985352, 0.8449078780010854) by using the given coordinates how could i find the direction.

for an example 
input one : x,y,z =  0.00949334694383068, -0.3999829847985352, 0.8449078780010854
input two : x,y,z =   0.01603883281370779, 0.6066595296580494, 0.5342810849038371

At the finally i want to compare input_one direction and input_two direction. Any help is appreciated

What you're trying to do is called calculating the azimuth. If you're interested in doing this for navigational or geographic purposes and need a thorough understanding of this, you can start here:

http://mobile.codeguru.com/cpp/cpp/algorithms/article.php/c5115/Geographic-Distance-and-Azimuth-Calculations.htm

Otherwise you could look for a library for calculating the azimuth bases on 3d co-ordinates

This is called vector math.

"Coordinates" are a special kind of vector, relative to some origin (in your case x=0,y=0,z=0 ). For that reason, the difference x1-x2, y1-y2, z1-z2 is a vector from point 2 to point 1. The inverse x2-x1, y2-y1, z2-z1 is a vector from point 1 to point 2.

The direction of a vector is usually defined by ignoring its length, or alternatively by setting its length to one. So we need to first define the length, which is L = √(x*x + y*y + z*z) . We can define the vector x/L, y/L, z/L which points in the same direction as x,y,z but with length one.

Finally, to compare two directions we can calculate the inner product of those two directions: x1/L1 * x2/L2 + y1/L1 * y2/L2 + z1/L1 * z2/L2 . If that's one, they point in the same direction. If it's 0, they're orthogonal. If it's -1, they point in opposite directions.

As you can see, the vector 0,0,0 has length 0 and no direction. That can complicate things a bit.

In OpenCV: class Vec . The length function is called norm(v) and the inner product is called v1.mul(v2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM