3D math question : barycentric interpolation

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

3D math question : barycentric interpolation

Post by madmarx »

Hi!

Not a ogre question, but more 3D math question. I am writing a software renderer that mimics opengl. I have a difficulty to do the interpolation of values from the vertex at the point inside a face in an efficient way. Also I had some difficulties to find information on the internet.
The mathematical problem would be : I got 1 2D triangle (ABC) and 1 point M which lies inside the triangle. How do I interpolate the values from vertex data ABC to get those at the point M ?

What I tried : I calculated the triangle areas ratios (MAB/MBC/MAC), but that is very calculation heavy. Does anyone got a suggestion for faster calculus ?

Best regards,

Pierre
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
User avatar
Daixiwen
Greenskin
Posts: 105
Joined: Fri Feb 08, 2013 11:30 am
Location: Oslo
x 16

Re: 3D math question : barycentric interpolation

Post by Daixiwen »

Can't you just use the distances MA / MB / MC as weight values for the linear interpolation?
Hardware, n.: part of the computer you can kick
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: 3D math question : barycentric interpolation

Post by madmarx »

Thanks , but I don't think it works : Imagine that M is on the edge AB. Then distance MC is not null, so the interpolation is not null for C, while it should be, since M is completely at the opposite.
So I came to the conclusion that I can't use those distances.

But you gave me an idea. if I calculate distance "M to (AB)", "M to (AC)" and "M to (BC)", this might work.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
User avatar
shadowfeign
Goblin
Posts: 213
Joined: Mon Jan 26, 2009 11:51 pm
x 15

Re: 3D math question : barycentric interpolation

Post by shadowfeign »

not sure if this would help or not? but maybe it will. there are five parts to the video, the next one should be pretty easy to find each time though, so I'll just link the first to save some space.

[youtube]E5papKQGrGU[/youtube]
User avatar
Daixiwen
Greenskin
Posts: 105
Joined: Fri Feb 08, 2013 11:30 am
Location: Oslo
x 16

Re: 3D math question : barycentric interpolation

Post by Daixiwen »

madmarx wrote:Thanks , but I don't think it works : Imagine that M is on the edge AB. Then distance MC is not null, so the interpolation is not null for C, while it should be, since M is completely at the opposite.
So I came to the conclusion that I can't use those distances.
Yes of course... duh! I think I should never try to answer a question about geometry without a pencil and a paper ;)
madmarx wrote:But you gave me an idea. if I calculate distance "M to (AB)", "M to (AC)" and "M to (BC)", this might work.
Yes I agree, this looks more like it. And it's probably one of the only ways to make the interpolation linear. That said, as far as complexity goes, you aren't that far away from your first solution with the 3 triangle areas.
Hardware, n.: part of the computer you can kick
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: 3D math question : barycentric interpolation

Post by bstone »

I think weighting components by incident face angles is what is used often, not that calculation heavy too.
User avatar
lunkhound
Gremlin
Posts: 169
Joined: Sun Apr 29, 2012 1:03 am
Location: Santa Monica, California
x 19

Re: 3D math question : barycentric interpolation

Post by lunkhound »

If you are rasterizing a triangle, then you can speed things up a lot by reusing the information from adjacent pixels. If all you want is a single point, then barycentric is a good choice.

For barycentric, I'd use a cross product like (M - A) x (M - B) and then take the dot product of that with the surface normal. That is the fastest way I know to compute the area MAB (its 2x the area actually).
Post Reply