Calculation of the minimum distance

gustav
Posts: 12
Joined: Mon Jan 11, 2010 9:40 am

Calculation of the minimum distance

Post by gustav »

Hello everybody! I'm Russian and so excuse me for my English in advance )

I need to calculate a minimal distance between two 3D objects (they can be boxes, spheres, cones or cylinders). How can I do that with Bullet 2.75? ... Thanks to all!

P.S. I'm using Visual C++ 6.0
aleradish
Posts: 22
Joined: Thu Mar 05, 2009 9:41 pm

Re: Calculation of the minimum distance

Post by aleradish »

Hi,

I don't have understood right your problem... but if what I have understood it's right it have to be...

btVector3* VObj1=Object->getWorldTransform()->getOrigin();
btVector3* VObj2=Object2->getWorldTransform()->getOrigin();

after you should make...

btVector3* MinDistance=new btVector3(VObj1->getX()-VObj2->getX(), etc etc.)

you should see well that because there is operator minus (-) between two btVectors but you have to make attenction... with the pointers and references.

I hope that can help you...

Bye!
spy32
Posts: 19
Joined: Fri Aug 01, 2008 1:12 pm

Re: Calculation of the minimum distance

Post by spy32 »

aleradish wrote:Hi,

I don't have understood right your problem... but if what I have understood it's right it have to be...

btVector3* VObj1=Object->getWorldTransform()->getOrigin();
btVector3* VObj2=Object2->getWorldTransform()->getOrigin();

after you should make...

btVector3* MinDistance=new btVector3(VObj1->getX()-VObj2->getX(), etc etc.)

you should see well that because there is operator minus (-) between two btVectors but you have to make attenction... with the pointers and references.

I hope that can help you...

Bye!
What you are calculating is the distance between the objects logical center and not the minimal distance. Calculating the minimal distance is a hard task which needs alot of math forumlars etc. and it's different from shape type to shape type. The only easy to calculate minimal distance between two shapes works with two spheres. Just subtract the both spheres' radius of the distance between the spheres' centers. Hope that'll help.

Have Fun (With Bullet),
spy
gustav
Posts: 12
Joined: Mon Jan 11, 2010 9:40 am

Re: Calculation of the minimum distance

Post by gustav »

aleradish, Thanks, but it's not that I realy need ... I need minimal distance ... I mean it's distance between two points:
1) The Point of the first object closest to the second object
2) The Point of the second object closest to the first object

May be I should ask my question like this: How can I find a point of the one object closest to another object? ...
gustav
Posts: 12
Joined: Mon Jan 11, 2010 9:40 am

Re: Calculation of the minimum distance

Post by gustav »

spy32, thanks

It surprises me that Bullet may not have any method of calculating minimal distance between two 3D objects ... I think that it's very common problem to know how far left before the collision ...
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Calculation of the minimum distance

Post by Erwin Coumans »

You can check out the Demos\CollisionDemo\CollisionDemo.cpp, it is the most basic way to compute the closest points between two arbitrary convex shapes.

There are other ways to compute closest points, using the btCollisionDispatcher, but this seems a bit complicated, so we will include a helper method in upcoming Bullet 2.76.

Thanks,
Erwin
gustav
Posts: 12
Joined: Mon Jan 11, 2010 9:40 am

Re: Calculation of the minimum distance

Post by gustav »

Erwin Coumans wrote:You can check out the Demos\CollisionDemo\CollisionDemo.cpp, it is the most basic way to compute the closest points between two arbitrary convex shapes.

There are other ways to compute closest points, using the btCollisionDispatcher, but this seems a bit complicated, so we will include a helper method in upcoming Bullet 2.76.

Thanks,
Erwin
Thank you, Erwin. I will check out the Demos\CollisionDemo\CollisionDemo.cpp

P.S. When we see a Bullet 2.76?