converting vector on plane to 2d

This topic is 4368 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, Is there a quick way to convert vectors on the same plane to 2d coordinates? I have thought to select an arbitrary 2 vector on plane and cross product difference of them(v1) with the plane normal and find another vector(v2) and project vectors on plane to v1 and v2 to get 2d coordinates, but I this does not seem the best way to do that...

Share on other sites
Quote:
 Original post by utkuabut I this does not seem the best way to do that...

It seems to me like it's the most straightforward way. And those should be preferred - from my experience those are the only fully correct ways implementing math algorithms.

About finding this "arbitrary 2 vector on plane" - I'm doing it like this:

// any orthonormal vector to @v0.xvec orthonormalTo(const vec& v0){  // Who's less paralel?  if ( fabs(v0.z) < fabs(v0.y) ) {    // First shot - right.    xvec xvFirst(0,0,1);    // gramm-schmidt (with predicted dot value).    const float dotS0 = v0.z;    xvFirst -= v0 * dotS0;    return norm(xvFirst);  } else {    // Second shot - up.    xvec xvSec(0,1,0);    // gramm-schmidt (with predicted dot value).    const float dotF0 = v0.y;    xvSec -= v0 * dotF0;    return norm(xvSec);  };};// gives two orthonormal vertices, matching given.void createPlaneBase(const xvec& xvPlaneNormal, vec& vOut1, vec& vOut2){  const xvec xvFirst = orthonormalTo(xvPlaneNormal);  vOut1 = xvFirst;  vOut2 = cross(xvFirst, xvPlaneNormal);};

Share on other sites
If you already have two vectors, then no need to find two more. Just let one of the vectors represent the "x-axis" for the plane, and you can calculate the coordinates (x1,y1) and (x2,y2) for each vector:
float x1 = normalize(firstVector); // Returns the length before normalizationfloat y1 = 0.0f;float x2 = dot(secondVector, firstVector);float y2 = length(secondVector - x2 * firstVector);

Share on other sites
Zipster's method is clean and tidy, but if you're working on accelerated hardware (or even if you're not), you may prefer to take the slightly more intuitive approach of transforming the plane onto a axial hyperplane.
Given any plane in 3-space, there exists a unique rotation that will transform the barycentric coordinates to projected global coordinates, effectively rotating the plane onto the xy, xz, or yz plane (whichever you choose). To convert any coordinate in your domain, you need only multiply by a constant matrix and discard the unused (invariant zero) coordinate. This has the bonus of being conformal, so geometry works as you'd expect.

Regards

Share on other sites
Thanks!
Zipster: Thats really a good point, I only need to calculate the distance to the ray I have on the plane :)
Admiral: I sensed only normal info must be enough to map to 2d, but could not express it. Your method is great.

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 11
• 9
• Forum Statistics

• Total Topics
632562
• Total Posts
3007098

×

Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!