Polygon coordinates transformation
- Posted by Tommy Carlier <tommy.carlier at pandora.be> Mar 18, 2004
- 365 views
I want to add a routine to Win32Dib, that can draw a part of a bitmap on another bitmap, but stretched to a polygon. To do this, I need to find an algorithm that transforms coordinates from 1 polygon to another one. I have 2 polygons with each 4 points: polygon_source = {{u1, v1}, {u2, v2}, {u3, v3}, {u4, v4}} polygon_destination = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}} I need to find a formula that transforms a coordinate {x, y} inside polygon_destination to a coordinate {u, v} inside polygon_source. I've looked for tutorials on texture mapping, but didn't find any non-3D transformation formula. I've looked for methods to solve linear equations, but didn't find the right method. Can anyone solve the following set of equations? x1 * a + y1 * b + c = u1 x2 * a + y2 * b + c = u2 x3 * a + y3 * b + c = u3 x4 * a + y4 * b + c = u4 a, b and c are the unknown variables. u?, x? and y? are known values. If these equations can be solved, I can transform coordinates with the 2 simple functions: u = x * a + y * b + c v = x * d + y * e + f -- d, e and f can be found with the same set of equations, but with v? instead of u? This finds the coordinate {u, v} in polygon_source that represent the coordinate {x, y} in polygon_destination. Let's see if there are any math geniuses in the Euphoria-community! -- Tommy Carlier tommy online: http://users.pandora.be/tommycarlier