Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411500 Posts in 69373 Topics- by 58428 Members - Latest Member: shelton786

April 25, 2024, 10:54:13 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)[Math] Interpolating between three points
Pages: [1]
Print
Author Topic: [Math] Interpolating between three points  (Read 7376 times)
Kianis
Level 0
***


self-portrait


View Profile WWW
« on: December 18, 2007, 12:02:47 PM »

Long time lurker finally coming out of my shell... to ask
a question Roll Eyes

There's something I've been wondering for a long time.
How would you interpolate between three points? For instance
for doing things like vertex colors or calculating the normal
of a specific point on a 3d-face, etc etc.

Let's say you have three points and each point got a value
of some kind. If you now iterate over the points inside this
triangle, how would you go about to calculate the value of the
current point?

Hope that makes sense. Smiley
Logged

Chris Whitman
Sepia Toned
Level 10
*****


A master of karate and friendship for everyone.


View Profile
« Reply #1 on: December 18, 2007, 02:26:07 PM »

Those things are actually quite different! Here is the deal with the vertex normal averaging, as opposed to the interpolation part.

Regarding calculating vertex normals from the normals of adjacent triangle, this is not, in the strictest sense, possible on a triangulated mesh, because the surface is not differentiable at the vertices and has no defined normals there. You can still approximate the normal vector as if you were dealing with a differentiable surface, but anything you do is more or less an approximation. The trick I've always used is just to add the normals from adjacent triangles together and normalize the result. This is not super accurate because ideally you should include a bias for the surface area of the nearby triangles, but it works well enough for most purposes.

Of course, if you are dealing with a parameterized surface, you can take the partial derivatives of your parametric equation and then take the cross product of those to get the normal vector at any point, but this is only useful if your surface is based on some equation.

I'll do some figuring on bilinear interpolation from three points and try to get back to this topic in a bit, but for now it is time for breakfast and coffee.
Logged

Formerly "I Like Cake."
raigan
Level 5
*****


View Profile
« Reply #2 on: December 18, 2007, 04:25:16 PM »

You might want to google "barycentric coordinates", they're a way of describing a point inside a convex shape as a combination of that shape's vertices.

In your case, given a point in the triangle, you'd solve to find a barycentric position (w0,w1,w2) given in terms of the triangle vertices. So, if your point is p and the triangle verts are p0,p1,p2, you'd have p = w0*p0 + w1*p1 + w2*p2.

You can use those w values to blend together any other property defined at the vertices. They have other properties like being non-zero and summing to 1 if I recall correctly..

BUT! if this is in the context of a software renderer, there are definitely better ways to do this than to calculate the barycentric coords of each pixel.
Logged
Chris Whitman
Sepia Toned
Level 10
*****


A master of karate and friendship for everyone.


View Profile
« Reply #3 on: December 18, 2007, 04:45:10 PM »

That's sort of one of things I was thinking of, but once again, there are going to be problems with that if you're making a software renderer, in as much as you're also going to need perspective correction.

Simply using a linear combination of basis vectors in projection space are going to mean a constant unit length for nearby or distant portions of the triangle, whereas ideally the unit length should decrease in projection space as distance from the camera increases.

There are lots of ways to interpolate between data points, but the most effective probably depends on what, exactly, you need them for.
Logged

Formerly "I Like Cake."
pkt-zer0
Level 0
**



View Profile
« Reply #4 on: December 19, 2007, 04:22:45 AM »

If the vectors at any point of the triangle can be expressed as a linear function of x,y,z, then for any such V vector V = A*x + B*y + C*z. Then, since you know the values of V at three specific (x,y,z) coordinates, namely, the vertices of the triangle, you can just go ahead an solve for A,B,C. Ta-dah!

Of course, this isn't necessarily practically useful as well, but hey, that's math for you.
Logged
Kianis
Level 0
***


self-portrait


View Profile WWW
« Reply #5 on: December 19, 2007, 07:32:08 AM »

Thank you all for your responses!

Unfortunately I've read far to little math, something I defenitely
plan to change once I'm done with my current studies, so most of this
is way over my head. Sad

The thing is I'm not looking to solve any particular problem, this is just
something I wanted to learn since I thought this would be an increadibly
common (and rather easy Tongue) operation in 3d-graphics.

As a test I used a (2d) triangle with a different color at each vertex
and tried to blend the color over the surface, but couldn't make it work.
Is this something I could use bilinear interpolation for?
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic