Sign in to follow this  
rxa

mapping point from quad to another

Recommended Posts

Hello, at first glance this problem seemed quite easy but when I sat down with this I just could not get anything solved :,(. So the problem is: I have quad Q0 (polygon with four points) in 2d-cartesian coords. Then I have a point P which I in this case is known that it is located inside the Q0. I'd like to calculate the relative position on quad, two values in range of [0,1] so I could map this point on any quad Qn. Any suggestions how to achieve this? (I do not have any graphics API functionality in use. In case of opengl I could rotate the quad (or both quads) axis aligned, and then do the transform and rotate back maybe? )

Share this post


Link to post
Share on other sites
Quad is not axis-aligned, will this work? Or do I have to use to get width and height:

sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0)) , where x, y are quad points.

And absolute position is P.x-x0, P.y-y0

?

Share this post


Link to post
Share on other sites
There have been posts on this which you might be able to find. Your three basic options are,
1 - Split your quads into triangles and do barycentric interpolation. This is very easy.
2 - Use bilinear interpolation. This has the advantage over #1 of avoiding a "kink" where the two triangles meet.
3 - Find a homography mapping one quad to the other. This only works for certain quads (I think it works for all convex quads), but has the advantage of preserving lines.

Share this post


Link to post
Share on other sites
But in case of bilinear interpolation I knwo the point, so I need to solve the U and V. So this will be bilinear interpolation inversely. Instead of solving

x,y from p00, p01, p10, and p11, with u and v -coords, I must solve u and v from x and y. Seems quite tricky.

EDIT: And wouldn't bilinear interpolation require the quad to be axis-aligned (regular grid)?

Share this post


Link to post
Share on other sites
Quote:
Original post by rxa
But in case of bilinear interpolation I knwo the point, so I need to solve the U and V. So this will be bilinear interpolation inversely.


IIRC that's what was done. See this thread which covers basically all the options I summarized above. In this thread,
1 - erissian showed how to use the bilinear approach
2 - Dave Eberly advocated the use of homographies and gave a link to a PDF he'd written on the subject.
3 - I ran through how to do barycentric interpolation.

Share this post


Link to post
Share on other sites
This page has links to the PDF and implementations of both bilinear and perspective mappings for convex quads to convex quads. See the section with files Wm4QuadToQuadTransforms.{h,cpp}. The description for the bilinear mapping is in comments in the header file.

Share this post


Link to post
Share on other sites

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