Archived

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

Blast...triangle interpolation...

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

Recommended Posts

I''ve tried this with several different implementations and it hasn''t worked for any of them, at least the way I coded them. I''ve got a 3D triangle points (CVector3s) a, b, and c, and the X,Z coordinates of a point on the triangle. How do I get the Y co-ordinate of the point? I''ve searched around, both on Google and this site, but every time I''ve tried to implement it, it didn''t work. eg. float PointOnTriangleY(CVector3 a, CVector3 b, CVector3 c, float pX, float pY) { //huh? } Thanks!

Share on other sites

1)Find the plane equation of the triangle (say your Vectors are P1, P2, P3)

a) Find the vectors of two sides of the triangle that share a common point, eg the vectors between P1P2 and P1P3

b) Get the normal of the triangle plane by taking the cross product of the vectors P1P2 and P1P3.

N=P1P2 X P1P3

c) Normalise this normal.

d) Equation of a plane is aX+bY+cZ=d,

Where (a,b,c)is your plane Normal vector calulated above
Use this and a point on your triangle P1=(X1,Y1,Z1) to find d

ie d= aX1+bY1+xZ1

2) substitute your X,Z coordinates into the plane equation above to get Y

ie Y = (d - aX -cZ)/b

Cheers

Keef

Share on other sites
Thanks, that''s one way

Is it possible you could write it in code? I tried using this method before, and my code was horribly unsuccessful...

Thanks again!

Share on other sites
I usually fudge it somewhere around the cross-products.

Share on other sites
Hmm, tried it. Got wacky results

Here''s my code:
float PointOnTriangle(CVector3 a, CVector3 b, CVector3 c, float Cx, float Cz){	CVector3 nVect = vNormalize(Cross(VectorDiff(a,b),VectorDiff(a,c)));	float d = (nVect.x * a.x) + (nVect.y * a.y) + (nVect.z + a.z);	return((d - (nVect.x * Cx) - (nVect.z * Cz)) / nVect.y);}

Anything wrong?

Share on other sites

1)
This bit
(nVect.x * a.x) + (nVect.y * a.y) + (nVect.z + a.z);

should I think be
(nVect.x * a.x) + (nVect.y * a.y) + (nVect.z * a.z);

(you are adding the z component, not multiplying!)

Your code is nice and concise but hard to debug. Try to spread things out a bit to give yourself a chance of debugging. Cramped code is hard to debug! Once you''ve got it working then optimise.

2) Try drawing the normal for the triangle when you render the triangle. I found this very useful for debugging all sorts of stuff like this (you''ll probably need to scale up the normal then draw it as a line from point on you triangle)

Cheers

Keef

Share on other sites
Woo hoo! It works! Thank you very much! I squished my code together for the post, I suppose that''s a bad thing

1. 1
2. 2
frob
15
3. 3
4. 4
5. 5

• 13
• 13
• 14
• 68
• 15
• Forum Statistics

• Total Topics
632137
• Total Posts
3004314

×