views:

253

answers:

2

hi wanted to calculate the degreee between two triangles where every point of them has a 3d coordinate.... i.e.

triangle 1: point1(x1,y1,z1), point2(x2,y2,z2), point3(x3,y3,z3). triangle 2: point1(x1,y1,z1), point2(x2,y2,z2), point4(x4,y4,z4).

yes, the triangles always share exactly same two points. is there a way to calculate the degree between them efficiently in cuda kernel

+1  A: 

The angle between the triangles is the same as the angle between the planes defined by the three points of each triangle.

Since both Point 1 or Point 2 lie in both planes, figure out the direction cosines from one of those points to Point 3, and then to Point 4. Then, the cosine of the angle between these two lines is just the sum of the products of the corresponding direction cosines.

John at CashCommons
thanks, i know that no problem implementing it in ansi-c. but, what about cuda kernel?
kl
That I don't know.
John at CashCommons
thanks anyways! :)
kl
@John: Cuda supports C, doesn't it? If so, just use their compiler and presumably it'll do a decent job...
BlueRaja - Danny Pflughoeft
I don't think that's correct. In general P3-P1-P4 and P3-P2-P4 will give you two different angles and neither one is the angle between the two planes.For example, let P1 = (1, 1000000, 0)P2 = (1, -1000000, 0)P3 = (0, 0, 0)P4 = (0, 0, 1)
Die in Sente
A: 

For each plane, you need to construct it's normal vector (perpendicular to all lines in that plane). The simple way to do that is to take the cross-product of two non-parallel lines in the triangle. (ex (P3-P1) X (P2-P1) and (P4-P1) X (P2-P1).

Normalize those.

The dot product of those two direction vectors gives you the cosine of the angle.

The tricky bit is to watch out for degenerate triangles! If all 3 points defining either triangle are colinear, (that triangle is just a line) then what you're asking for is undefined, and the cross-product will divide by zero. You need to decide what you're going to do in that case.

Since you're trying to do this on a GPU, you'll ideally want to write this function without any branches, if you're concerned about efficiency. That would mean instead of testing for degenerate triangles with an if clause, you should try and do it with a ternary A ? B : C

Die in Sente