#### Archived

This topic is now archived and is closed to further replies.

# Transforming 2D polygon coordinates

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

## Recommended Posts

I have 2 two-dimensional polygons, each with 4 coordinates:
P1 = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}
P2 = {{u1, v1}, {u2, v2}, {u3, v3}, {u4, v4}} 
I need to find a way to transform coordinates of points inside P1 to the corresponding coordinates inside P2. In pseudo-code:
for each point (x, y) in P1 do
(u, v) = transform(x, y)
end for

The point (u, v) is the point inside P2 that corresponds to the point (x, y) inside P1. Does anyone know how to do this?

##### Share on other sites
In general I´d say a point (x,y) inside P1 can end up anywhere within (maybe not even nessecarily within) P2 but this probably isn´t the answer you were looking for, so:

Assume linearity:
Split your polygon into triangles (two of them in this case). A point (x,y) in T1= {(x1,y1),(x2,y2),(x3,y3)} can be written as:
(x,y) = (x1,y1) + a*((x2,y2)-(x1,y1)) + b*((x3,y3)-(x1,y1)).
Let a and b remain unchanged under your transformation (which is what I meant by linearity):
(u,v) = (u1,v1) + a*((u2,v2)-(u1,v1)) + b* (...)

##### Share on other sites
I already tried splitting the polygon in triangles, and rendering each triangle separately, but it doesn''t work like it should: the polygon is distorted.
The transformation from 1 triangle to another one works like it should, but the transformation depends only on the 3 points of the triangle and not on the 4 points of the polygon.

##### Share on other sites
just a few thoughts; I won´t write anything more here this evening as I´m quite drunk now (have been offered a diploma thesis and thus had a good reason/excuse to open a bottle of wine) and don´t want to flood this forum with potentially stupid stuff ...

- What do you actually try to do? I thought something like you have a texture bitmap in your polygon that you want to transform.

- What do you mean by "distorted"?

- Did you actually check that the point you transform is within the triangle you are using (0<= a,b <=1) ?

- >> but the transformation depends only on the 3 points of the
>> triangle and not on the 4 points of the polygon.
right. The 4th point is covered by the 2nd triangle.

- to explicitely point it out, you:
1) check in which one of the triangles your point lies.
2) transform the point according to the rules of the triangle it lies in.

##### Share on other sites
What I was trying to do? 2D Texture-mapping. Mapping a polygonal region of a bitmap onto a different polygon.

By the way: I already found a solution for my problem. I was going to program it in Euphoria, and I also posted my problem to the Euphoria Mailing List. My luck was that somebody had already done something similar, and he sent me his code, which I could just adjust a little and implement in my bitmap manipulation library Win32Dib.

1. 1
2. 2
frob
16
3. 3
Rutin
12
4. 4
5. 5

• 13
• 12
• 59
• 14
• 15
• ### Forum Statistics

• Total Topics
632124
• Total Posts
3004243

×