mapping point from quad to another

Started by
5 comments, last by Dave Eberly 14 years, 7 months ago
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? )
Advertisement
Vec2d point_rel (point_absolut.x / quad.getWidth(), point_absolut.y / quad.getHeight());Vec2d point_absolut_on_another_quad (point_rel.x * another_quad.getWidth(), point_rel.y * another_quad.getHeight());
------------------------------------I always enjoy being rated up by you ...
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

?
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.
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)?
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.
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.

This topic is closed to new replies.

Advertisement