Sign in to follow this  

converting vector on plane to 2d

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Quote:
Original post by utkua
but 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 this post


Link to post
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 normalization
float y1 = 0.0f;
float x2 = dot(secondVector, firstVector);
float y2 = length(secondVector - x2 * firstVector);

Share this post


Link to post
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
Admiral

Share this post


Link to post
Share on other sites
Thanks!
Deffer: Your code lead me various optimizations, there are nice tips.
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this