From 7f76233d8ab4abbf0ef90eaf4d8426e10495a70b Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Wed, 3 Apr 2019 15:53:17 -0700 Subject: [PATCH] added Sphere.fromBox3D --- src/mol-math/geometry/primitives/sphere3d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mol-math/geometry/primitives/sphere3d.ts b/src/mol-math/geometry/primitives/sphere3d.ts index 94c9593f9..c385ffad4 100644 --- a/src/mol-math/geometry/primitives/sphere3d.ts +++ b/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 -- GitLab