• ### What is your GameDev Story?

#### Archived

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

# Expressing a point wrt other points

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

## Recommended Posts

Hello all I would like to express a 2D point (P) as a linear combination of three other points (Pa, Pb, Pc), such that P = ca * Pa + cb * Pb + cc * Pc where, obviously, Pa, Pb and Pc are not coincident or collinear. I can think of way of calculating ca, cb and cc, but it involves messing around with line intersections and the like, and is generally a bit clumsy looking. I have a nagging feeling that there is some elegant and easily expressed solution to computing the required coefficients. Does anybody have any ideas? Thanks in advance

##### Share on other sites
so what do we have?
Px = ca * Pax + cb * Pbx + cc * Pcx
Py = ca * Pay + cb * Pby + cc * Pcy

two equations, three unknown.
in other words, there are infinitly many solutions. youll need to set some other condition to find just one solution.
if any solution is ok, just state:

ca = 1 (or whatever you fancy, as long as it isnt 0)

and you can solve the problem using simple linear algebra.

##### Share on other sites
another extra requirement you could set to obtain a unique solution would be that the combined magnitude of the values you solve for should be minimal. otherwise you might end up with a solution like ca=10^154, cb=-10^154, cc or such numbers, and float accuracy would mess up your application, even though its a valid solution.

this would maybe be a bit harder though, i think it would require some sort of iterative process.

##### Share on other sites
The extra condition that is usually imposed is ca+cb+cc=1. These are called "barycentric coordinates".

##### Share on other sites
What you're trying to do is a linear transformation from R3 to R3. To do this, you can multiply a point by an appropriate matrix.

Any such transformation matrix can be thought of as changing the basis vectors of your coordinate system. Typically, we use these:

i = (1, 0, 0)
j = (0, 1, 0)
k = (0, 0, 1)

Which is why an identity matrix looks like it does.
Actually, each column , not each row, represents an axis.

Now if you have three OTHER vectors, then the matrix uses each of those vectors as a column. If we call these vectors u , v , and w , then this matrix transforms a point from uvw space to xyz space.

What you're looking for is the inverse of this matrix - to go from xyz space to uvw space.

It can be found using Gaussian elimination , or by using a calculator. Unfortunately, the general solution is way too long for me to type right here. Hope this helps point you on your way though.

[edited by - TerranFury on March 6, 2004 5:21:21 PM]

##### Share on other sites
Now that I think about it, your expression doesn''t even make sense if the weights don''t add up to 1.

Let me explain the solution with an example:

We want to write P=(3,3) as a combination of X=(0,1), Y=(6,3) and Z=(4,6). So
P = x*X+y*Y+z*Z
(3,3) = x*(0,1)+y*(6,3)+z*(4,6)
(3,3) = (0,x)+(6*y,3*y)+(4*z,6*z)
(3,3) = (6*y+4*z,x+3*y+6*z)

6*y+4*z = 3
x+3*y+6*z = 3
x+y+z = 1

Solve the system of linear equations (Gaussian elimination would be fine for that) and you get your coordinates.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015448
×