Browse Source

added Sphere.fromBox3D

Alexander Rose 6 years ago
parent
commit
7f76233d8a
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/mol-math/geometry/primitives/sphere3d.ts

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

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -9,6 +9,7 @@ import { Vec3, Mat4, EPSILON } from '../../linear-algebra'
 import { PositionData } from '../common'
 import { OrderedSet } from 'mol-data/int';
 import { NumberArray } from 'mol-util/type-helpers';
+import { Box3D } from './box3d';
 
 interface Sphere3D { center: Vec3, radius: number }
 
@@ -76,6 +77,12 @@ namespace Sphere3D {
         return out
     }
 
+    export function fromBox3D(out: Sphere3D, box: Box3D) {
+        Vec3.scale(out.center, Vec3.add(out.center, box.max, box.min), 0.5)
+        out.radius = Vec3.distance(out.center, box.max)
+        return out
+    }
+
     export function addSphere(out: Sphere3D, sphere: Sphere3D) {
         out.radius = Math.max(out.radius, Vec3.distance(out.center, sphere.center) + sphere.radius)
         return out