Skip to content
Snippets Groups Projects
Commit 88dc9b99 authored by Alexander Rose's avatar Alexander Rose
Browse files

Sphere3D.addVec3

parent fac58a8d
No related branches found
No related tags found
No related merge requests found
...@@ -180,7 +180,7 @@ function getBoundingSphere(lineStart: Float32Array, lineEnd: Float32Array, lineC ...@@ -180,7 +180,7 @@ function getBoundingSphere(lineStart: Float32Array, lineEnd: Float32Array, lineC
const start = calculateBoundingSphere(lineStart, lineCount * 4, transform, transformCount) const start = calculateBoundingSphere(lineStart, lineCount * 4, transform, transformCount)
const end = calculateBoundingSphere(lineEnd, lineCount * 4, transform, transformCount) const end = calculateBoundingSphere(lineEnd, lineCount * 4, transform, transformCount)
return { return {
boundingSphere: Sphere3D.addSphere(start.boundingSphere, end.boundingSphere), boundingSphere: Sphere3D.expandBySphere(start.boundingSphere, end.boundingSphere),
invariantBoundingSphere: Sphere3D.addSphere(start.invariantBoundingSphere, end.invariantBoundingSphere) invariantBoundingSphere: Sphere3D.expandBySphere(start.invariantBoundingSphere, end.invariantBoundingSphere)
} }
} }
\ No newline at end of file
...@@ -83,12 +83,25 @@ namespace Sphere3D { ...@@ -83,12 +83,25 @@ namespace Sphere3D {
return out return out
} }
export function addSphere(out: Sphere3D, sphere: Sphere3D) { const tmpAddVec3 = Vec3.zero()
export function addVec3(out: Sphere3D, s: Sphere3D, v: Vec3) {
const d = Vec3.distance(s.center, v)
if (d < s.radius) return Sphere3D.copy(out, s)
Vec3.sub(tmpAddVec3, s.center, v)
Vec3.sub(tmpAddVec3, s.center, tmpAddVec3)
Vec3.setMagnitude(tmpAddVec3, tmpAddVec3, s.radius)
Vec3.scale(out.center, Vec3.add(tmpAddVec3, tmpAddVec3, v), 0.5)
out.radius = Vec3.distance(out.center, v)
return out
}
/** Expand sphere radius by another sphere */
export function expandBySphere(out: Sphere3D, sphere: Sphere3D) {
out.radius = Math.max(out.radius, Vec3.distance(out.center, sphere.center) + sphere.radius) out.radius = Math.max(out.radius, Vec3.distance(out.center, sphere.center) + sphere.radius)
return out return out
} }
/** Expand sphere by delta */ /** Expand sphere radius by delta */
export function expand(out: Sphere3D, sphere: Sphere3D, delta: number): Sphere3D { export function expand(out: Sphere3D, sphere: Sphere3D, delta: number): Sphere3D {
out.radius = sphere.radius + delta out.radius = sphere.radius + delta
return out return out
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment