Isuue in computing shortest distance between the cone and sphere

Post Reply
bpatra4
Posts: 2
Joined: Tue Aug 30, 2022 4:56 am

Isuue in computing shortest distance between the cone and sphere

Post by bpatra4 »

Hi,

I am trying to find the shortest distance between a cone and a sphere in C++. The information on the cone is as follows. The centre of the base circle of the cone is at {0, 0, -1}, and the vertex of the cone is at {0,0,0}. The radius and height of the cone are 0.58454 and 1, respectively. Similarly, the radius of the sphere is 0.1 centred at {0.9, 0.9, 0.1}. The shortest distance is computed to be 1.3016, and the foot of the perpendicular is found to be inside the cone instead of on the cone. The correct shortest distance is 1.1493.

I am attaching the code here.

Please help me to fix the code. Thanks a lot!
cone_sphere_proximity_check_Forforum.cpp
(3.49 KiB) Downloaded 203 times
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Isuue in computing shortest distance between the cone and sphere

Post by drleviathan »

The comment on this line seems incorrect to me:

Code: Select all

tr[0].setOrigin(btVector3(0, 0, -1)); // centre of the base circle of the cone
I would expect the transform supplied to the btGjkPairDetector::ClosestPointInput() to be that of the shape's origin (its center of mass (COM)), not to be that of a point on the shape's surface.

Which raises the question: Does the Bullet ConeShape use the correct COM of a uniform cone, which would be closer to the base than the tip? Or does it use a simplified COM located midway between the base and its tip? Looking at the code... it appears to use the latter, which kinda makes sense because the math is easier. Specifically, when I say it "appears to use the latter" I'm basing my statement on the implementation of:

Code: Select all

btVector3 btConeShape::coneLocalSupport(const btVector3& v) const
bpatra4
Posts: 2
Joined: Tue Aug 30, 2022 4:56 am

Re: Isuue in computing shortest distance between the cone and sphere

Post by bpatra4 »

Thanks a lot @drleviathan!

Yes, you are right. The input to the btGjkPairDetector::ClosestPointInput() should be the centre of mass of the cone, which is nothing but the located between the centre of the base circle and the vertex of a cone. This has solved my issue.

Thanks again!
Post Reply