4
\$\begingroup\$

So while researching for a method to detect collisions in a 3D space between (arbitrary rotated) boxes, I stumbled upon this excellent question with great resources for my further research and great answers: How many and which axes to use for 3D OBB collision with SAT

I now managed to implement nearly everything in C++, and I understand why I have to check all 15 axis and why they are important. Yet I don't understand, how to calculate a0, a1, a2, b0, b1 and b2 (the normals of A and B). Since I only have cuboids for collision detection, I would rather use normals instead of the edges. It does seem to be easier.

To be more precise: First of all, my data structure to save a OBB is a loose collection of 8 vertices of the cuboid 1]. I understand, how to calculate a normal mathematically. I just calculate the cross product of two edges... But I don't know which two edges to choose. If I look at a face of the cubiod, I have 4 edges I could use to calculate the normal for that face. Another problem is, that using the above mentioned data structure, I can't tell whether two vertices belong to one face.

So what can I do to get the 3 normals of a cuboid programmatically?

Do I have to expand my data structure, or can the missing information be derived somehow in a easy way?

1] Example for a cuboid in my data structure (represented in JSON, with (x,y,z) being a point in double^3):

[(0,0,0), (0,1,0), (1,0,1), (1,1,1), (0,1,1), (1,1,0), (1,0,0), (0,0,1)]

\$\endgroup\$
1
\$\begingroup\$

I now managed to solve the problem by myself. I changed my data structure, so that the normals are saved separately. When initializing the cuboid, I know what vertices belong to which surface. I then just take three vertices (namely p_1, p_2, p_3) of one surface (for example the surface which faces to positive x). The three vertices form a triangle on the surface. Now let p_2 be the vertex which is at the right angle of the triangle. Then I proceed to calculate the edges with:

e_1 = p_1 - p_2

e_2 = p_3 - p_2

Now the normal can be calculated with n_x = e_1 x e_2 (x = cross product)

The normals n_y and n_z can be calculated accordingly. I then just save the normals in the data structure and use them later when the collision detection begins.

I think that it would have been to complicated to calculate the normals with a loose collection of points, since the cuboids could have an arbitrary rotation. Thats why I rather changed the data structure.

Technically, this doesn't answer the whole question, since I didn't manage to calculate the normal by just using the collection of points where I don't know which point belongs to which surface, but I spent a lot of time and I think that it is not efficiently possible, though I cannot prove this statement.

\$\endgroup\$
  • \$\begingroup\$ Please note: I will accept this answer for now, but if someone comes up with a better answer, I will happily change this. Even if the answer just proves that it is not efficiently possible \$\endgroup\$ – CharlyDelta Nov 18 '15 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.