瀏覽代碼

Adding distanceToVec in sphere3d namespace

giagitom 2 年之前
父節點
當前提交
ac33b4a322
共有 1 個文件被更改,包括 7 次插入1 次删除
  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 };