I have a task to do a coarse check if cuboids intersect by assuming they are spheres. So I have cuboid class with three arrays stored as x, y, z coordinates of each of 8 points:
Now I am trying to compare if the distance between geometrical centers is larger than sum of sphere radius's but I know that I cannot simply deduce tuple from tuple:
1 2 3
if (getGeometricalCenter() - other.getGeometricalCenter() > (getSphereRadius()+other.getSphereRadius()))
returnfalse;
I appreciate much if someone could help me with that if statement for tuples. Also if anyone has additional comments if I did smth wrong please correct me , thank you very much
you are making this too hard, maybe?
you have 3 distances. object a to object b centers. object a's radius. object b's radius.
distances are not 'tuples'. distances are a single value. Do you know the 3-d distance formula? Its just like 2-d, just one more value... sqrt (x*x+y*y+z*z) where x is x1-x2 and so on... right?
is the a to b distance less than arad + brad?
if yes, you need to check the precise collisions, if not, you can skip the harder check.
but it gets better, if your data is what I am thinking it is... ?
Ill ask it again. is the radius of a and b in some known range that is relatively small?
If so, read on!
you need to do this problem in 2-d and then upscale to 3-d once you understand it better.
in 2-d, if you have a bunch of circles with a radius between 1 and 3 in a 1000x1000 box, for example, and say you sorted all the circles by their distance from the center of the box, 0,0? Get that image in your head, and now think: can 2 things collide if they are say, 10 units apart? No, they can't. So if you have in hand, a new circle that you want to create, you know where it is. there are 2 rings from the universe's 0,0 coordinate, one at your new guy-3 and one at new guy +3 radius rings. Any collisions MUST be in this area. With your list sorted by radius from the universe center, there are a group of circles that could be collisions in that band and the rest can be ignored. This combines 2 of the techniques we talked about, one is slicing your space up and the other is checking collisions with spheres. With the two, you have a great many you don't check at all, a few that you check with quick sphere checks, and a very few left from that which you check with the full correct algorithm for precise collisions. I think, with you talking about billions, you need to approach it this way, using both techniques.