Skip to content

Latest commit

 

History

History
97 lines (71 loc) · 3.81 KB

sphere.md

File metadata and controls

97 lines (71 loc) · 3.81 KB
title sphere
description Create a sphere in TypeScript with Code3D. Learn radius versus diameter, centered coordinates, reference axes, volume and editing defaults.
sourceReview
packageVersion sources
0.0.1-alpha.14
path sha256 commit
packages/core/src/library/sphere.ts
9974cb225e92aeb4fee483663e13cecd080903719750e4c3f20a742a4d4f0542
1baef99a1318fc694825ec0a48d4d39635a3a130
path sha256
packages/core/src/library/validation.ts
dae9300aea522c8aee83ef09e6716f31cd17f0cf6fb6df537218ecb72c63419d
sidebar
hidden
true
head
tag content
title
sphere() — Create a spherical solid in TypeScript | Code3D

Create a spherical solid for a ball, rounded feature or Boolean tool. One radius determines the size in every direction.

Example

import {sphere} from '@code3d/core';

export const ball = sphere(6);

The sphere(6) solid from the Code3D basic shapes example.

Select ball in the App to inspect this solid. Select a numeric argument and press Tab to edit it.

Complete example: basic shapes.

Signature

function sphere(radius: number): SolidModel;

Import sphere and, when needed, type SolidModel from @code3d/core. The same call works in the App and Node; Node initializes the kernel automatically.

Parameters

Parameter Meaning Accepted values
radius Distance from the center to the surface Finite and greater than zero

The parameter is required in TypeScript. Lengths use the model's common units; see export scale.

Result and coordinates

Returns a SolidModel<CanonicalElements> centered at the local origin. X, Y and Z each span -radius to radius. The example has a diameter of 12 and bounds from [-6, -6, -6] to [6, 6, 6].

The initial .origin and .center coincide at [0, 0, 0]. Its .axis is a +Y reference line through that point, useful for placement even though the sphere has no unique physical rotation axis. Directional bounds identify extreme positions; .up and .down are not planar caps on the sphere.

For an elongated or flattened shape with independent radii, use ellipsoid.

The solid provides frame, origin, center, axis and directional bound references. It supports Boolean operations, fillets, chamfers, shelling, materials and relations. Derived operations return new model values; see model values and local coordinates.

Measurements

Volume is (4 / 3) * Math.PI * radius ** 3; surface area is 4 * Math.PI * radius ** 2. For sphere(6), .volume is approximately 904.778684 and .area is approximately 452.389342.

These measure the curved solid, not the volume or area of its bounding box.

Validation and editing defaults

The radius must be a positive finite number. Zero, negative values, NaN, infinities, null and numeric strings throw radius must be a positive finite number..

While an incomplete call is being edited, omitted or undefined arguments use radius = 5. These runtime defaults let the editor complete a call; they do not remove the required TypeScript arguments. The resulting dimensions must still satisfy all constraints. Very small dimensions or clearances can also encounter the modeling kernel's tolerance.

Related APIs

  • ellipsoid gives X, Y and Z independent radii.
  • Booleans combine a sphere with other solids or use it as a cutter.
  • Solid primitives compares the available starting shapes.