Browse Source

Adding distanceToVec in sphere3d namespace

giagitom 2 years ago
parent
commit
ac33b4a322
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/mol-math/geometry/primitives/sphere3d.ts

+ 7 - 1
src/mol-math/geometry/primitives/sphere3d.ts

@@ -277,6 +277,12 @@ namespace Sphere3D {
     export function distance(a: Sphere3D, b: Sphere3D) {
         return Vec3.distance(a.center, b.center) - a.radius + b.radius;
     }
+
+    /** Get the distance of v from sphere. If negative, v is inside sphere */
+    export function distanceToVec(sphere: Sphere3D, v: Vec3): number {
+        const { center, radius } = sphere;
+        return Vec3.distance(v, center) - radius;
+    }
 }
 
-export { Sphere3D };
+export { Sphere3D };