Geometry

Geometry primitives in WiTwin Core

Overview#

WiTwin Core provides a set of differentiable geometry primitives. All primitives inherit from GeometryBase and expose a to_mesh() method that returns (vertices, faces) as PyTorch tensors.

from witwin.core import Box, Sphere, Cylinder
 
box = Box(position=(0.0, 0.0, 0.0), size=(1.0, 2.0, 0.5), device="cuda")
vertices, faces = box.to_mesh()

Common Base Parameters#

All geometry primitives share these constructor parameters:

ParameterDefaultDescription
position(0, 0, 0)Center position in world coordinates
rotationNoneOptional rotation
deviceNonePyTorch device string

Box#

An axis-aligned rectangular box.

Box(position=(0.0, 0.0, 1.5), size=(0.25, 4.0, 3.0), device="cuda")
ParameterDefaultDescription
size(1, 1, 1)Full extent along each axis (width, depth, height)

Sphere#

A sphere centered at position.

Sphere(position=(0.0, 0.0, 0.0), radius=1.0, device="cuda")
ParameterDefaultDescription
radius1.0Sphere radius

Cylinder#

A cylinder aligned along a given axis.

Cylinder(position=(0.0, 0.0, 0.0), radius=0.5, height=2.0, axis="z", device="cuda")
ParameterDefaultDescription
radius1.0Cylinder radius
height1.0Cylinder height
axis"z"Alignment axis. One of "x", "y", "z"

Cone#

A cone with apex at the origin and base along a given axis.

Cone(position=(0.0, 0.0, 0.0), radius=1.0, height=2.0, axis="z", device="cuda")
ParameterDefaultDescription
radius1.0Base radius
height1.0Height
axis"z"Alignment axis

Ellipsoid#

An axis-aligned ellipsoid.

Ellipsoid(position=(0.0, 0.0, 0.0), radii=(1.0, 0.5, 0.5), device="cuda")
ParameterDefaultDescription
radii(1, 1, 1)Semi-axes radii (rx, ry, rz)

Pyramid#

A square-base pyramid.

Pyramid(position=(0.0, 0.0, 0.0), base_size=1.0, height=2.0, axis="z", device="cuda")
ParameterDefaultDescription
base_size1.0Square base side length
height1.0Height
axis"z"Alignment axis

Prism#

A regular prism with num_sides sides.

Prism(position=(0.0, 0.0, 0.0), radius=1.0, height=2.0, num_sides=6, axis="z", device="cuda")
ParameterDefaultDescription
radius1.0Circumradius
height1.0Height
num_sides6Number of sides. Must be >= 3
axis"z"Alignment axis

Torus#

A torus centered at position.

Torus(position=(0.0, 0.0, 0.0), major_radius=1.0, minor_radius=0.25, axis="z", device="cuda")
ParameterDefaultDescription
major_radius1.0Distance from center to tube center
minor_radius0.25Tube radius
axis"z"Normal axis of the torus plane

HollowBox#

A box with a rectangular hollow interior.

HollowBox(
    position=(0.0, 0.0, 0.0),
    outer_size=(2.0, 2.0, 2.0),
    inner_size=(1.8, 1.8, 1.8),
    device="cuda",
)
ParameterDefaultDescription
outer_size(1, 1, 1)Outer box extent
inner_size(0.8, 0.8, 0.8)Inner hollow extent

Mesh#

Load arbitrary triangle geometry from vertex and face arrays.

import numpy as np
from witwin.core import Mesh
 
verts = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0]], dtype=np.float32)
faces = np.array([[0, 1, 2]], dtype=np.int32)
 
mesh = Mesh(vertices=verts, faces=faces, position=(0.0, 0.0, 0.0), device="cuda")

SMPLBody#

A parametric human body geometry based on the SMPL body model. Useful for modeling human blockage in indoor propagation simulations.

from witwin.core import SMPLBody

GeometryBase#

The abstract base class for all geometry primitives. All primitives expose:

geometry.to_mesh(segments=16) — Returns (vertices, faces) as PyTorch tensors. segments controls tessellation quality for curved surfaces.

geometry.signed_distance(xx, yy, zz) — Returns the signed distance field at the given coordinates.

Next Steps#