I am trying to understand a certain implementation of calculating the shortest vector between a vector and a truncated cone in 3D. The original idea is introduced in this paper.

So if we have two spherical objects: Object A with radius $r_A$, position $p_A$ and velocity $v_A$ and Object B with radius $r_B$, position $p_B$ and velocity $v_B$, then we can represent this in a simpler way calculating the relative position and relative velocity and assuming that object A is a point and the radius of object B is $r_A$ + $r_B$.

In 2D, this will look like doing the transformation from figure (a) to figure (b) where $\tau$ is just a scalar factor: enter image description here

The 3D figure is similar but instead of circles, we have spheres.

Now, if the relative velocity vector lies in the grayed truncated cone, we should find the vector $\mathbf{u}$ which is the smallest change to the relative velocity $\mathbf{V}$ to move it to the circumference of the cone as depicted in the following figure (note: $\mathbf{P}$ is the relative position): enter image description here

This has two cases:

  1. If the relative velocity is below the center of the cut-off circle (below the dashed blue line). In this case $\mathbf{u}$ will be on the cut-off circle (the smaller circle).

  2. The second case, which I don't understand how it is calculated, is when the relative velocity is above the center of the small circle(sphere), in this case $\mathbf{u}$ will be projected on the tangents of the cone. The intersection of the plane represented by $\mathbf{P}$ and $\mathbf{V}$ vectors and the big sphere is a circle that $\mathbf{u}$ will lie on.

        const Vector3 relativePosition = other->position_ - position_;
        const Vector3 relativeVelocity = velocity_ - other->velocity_;
        const float distSq = absSq(relativePosition);
        const float combinedRadius = radius_ + other->radius_;
        const float combinedRadiusSq = sqr(combinedRadius);
        Plane plane;
        Vector3 u;
        if (distSq > combinedRadiusSq) {
            /* No collision. */
            const Vector3 w = relativeVelocity - tau * relativePosition;
            /* Vector from cutoff center to relative velocity. */
            const float wLengthSq = absSq(w);
            const float dotProduct = w * relativePosition;
            if (dotProduct < 0.0f && sqr(dotProduct) > combinedRadiusSq * wLengthSq) {
                /* Project on cut-off circle. */
                const float wLength = std::sqrt(wLengthSq);
                const Vector3 unitW = w / wLength;
                plane.normal = unitW;
                u = (combinedRadius * tau - wLength) * unitW;
            else {
                **/* Project on cone. I Don't understand this! */
                const float a = distSq;
                const float b = relativePosition * relativeVelocity;
                const float c = absSq(relativeVelocity) - absSq(cross(relativePosition, relativeVelocity)) / (distSq - combinedRadiusSq);
                const float t = (b + std::sqrt(sqr(b) - a * c)) / a;
                const Vector3 ww = relativeVelocity - t * relativePosition;
                const float wwLength = abs(ww);
                const Vector3 unitWW = ww / wwLength;
                plane.normal = unitWW;
                u = (combinedRadius * t - wwLength) * unitWW;**

I know in the end we need to find $\mathbf{t}$ to scale $\mathbf{P}$. However, I don't understand how the cross product is utilized here and what does the quadratic equation that we are trying to solve represent.

This function can be found here.


Your Answer

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

Browse other questions tagged or ask your own question.