Skip to content

TorusKnotGeometry

Generated geometry representing a torus knot.

TorusKnotGeometry constructs a mesh for a (p, q) torus knot, a closed curve that winds p times around the torus's axis of rotational symmetry and q times around a circle in its interior. The tube is extruded along this curve using a Frenet-style frame. When p and q are coprime the result is a true knot; otherwise it forms a link of multiple loops.

cpp
auto geometry = vglx::TorusKnotGeometry::Create({
    .radius = 1.0f,
    .tube = 0.4f,
    .tubular_segments = 64,
    .radial_segments = 8,
    .p = 2,
    .q = 3
});

auto material = vglx::PhongMaterial::Create({.color = 0xFF6E00});

my_scene->Add(vglx::Mesh::Create(geometry, material));

INFO

Derives from Geometry and inherits all public properties and methods.

Construction

Constructors


TorusKnotGeometry()

Constructs a torus knot geometry.

cpp
TorusKnotGeometry::TorusKnotGeometry(const Parameters& params);
ParameterDescription
paramsInitialization parameters that control the shape and tessellation of the torus knot.

Factories preferred


TorusKnotGeometry::Create() std::shared_ptr<TorusKnotGeometry>

Creates a shared instance of TorusKnotGeometry with default parameters.

cpp
static std::shared_ptr<TorusKnotGeometry> TorusKnotGeometry::Create();

TorusKnotGeometry::Create() std::shared_ptr<TorusKnotGeometry>

Creates a shared instance of TorusKnotGeometry with custom parameters.

cpp
static std::shared_ptr<TorusKnotGeometry> TorusKnotGeometry::Create(const Parameters& params);
ParameterDescription
paramsInitialization parameters used to generate the torus knot.

Types

TorusKnotGeometry::Parameters struct

Parameters for constructing a TorusKnotGeometry object.

ParameterDescription
radius floatRadius of the torus the knot is wound around.
tube floatRadius of the tube extruded along the curve.
tubular_segments unsignedSegments along the length of the curve.
radial_segments unsignedSegments around the tube cross-section.
p unsignedNumber of windings around the axis of rotational symmetry.
q unsignedNumber of windings around the interior of the torus.

Released under the MIT License.