Jump to content
• Advertisement

# mapping point from quad to another

This topic is 3381 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

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

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

#### Share this 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

##### 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

##### 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

##### 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.

#### Share this 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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5
• Advertisement

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013378
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!