# mapping point from quad to another

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

## 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 on other sites
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());

##### 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 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 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 on other sites
Quote:
 Original post by rxaBut 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.

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632594
• Total Posts
3007259

×