Skip to main content

Overview

The Curve primitive represents a curve in 3D space defined by a series of control points. Currently, the curve is represented as a polyline through these control points. It is an open path (non-closed) and is useful for creating smooth or complex curved paths. Use Cases:
  • Creating curved paths and contours
  • Spline-like representations
  • Profile curves for sweep operations
  • Offset operations for parallel curves
  • Complex path definitions

Constructor

let curve = OGCurve::new(id: String);

Rust Constructor Parameters

id
String
required
Unique identifier for the curve instance

TypeScript Constructor Parameters

options
ICurveOptions
Configuration options for the curve
options.ogid
string
Optional unique identifier (auto-generated if not provided)
options.controlPoints
Vector3[]
required
Array of control points defining the curve path
options.color
number
required
Curve color as a hexadecimal number (e.g., 0x00aa55)

Methods

set_config

curve.set_config(control_points: Vec<Vector3>);
Updates the curve’s control points and regenerates geometry.

generate_geometry

curve.generate_geometry();
Generates vertices and edges connecting the control points sequentially.

get_geometry_serialized

let geometry: String = curve.get_geometry_serialized();
Returns serialized vertex buffer data as a JSON string.

get_offset_serialized

let offset_data = curve.get_offset_serialized(
    distance: f64,
    acute_threshold_degrees: f64,
    bevel: bool
);
Generates an offset curve parallel to the original at the specified distance. The curve is treated as an open path.
distance
number
required
Distance to offset the curve (positive or negative)
acuteThresholdDegrees
number
default:"35.0"
Angle threshold for beveling acute corners
bevel
boolean
default:"true"
Enable beveling at acute angles

get_brep_serialized

let brep: String = curve.get_brep_serialized();
Returns the complete BREP representation including vertices and edges.

dispose

curve.dispose();
Clears the BREP and control points to free memory.

Properties

id
String
Unique identifier for the curve instance
control_points
Vec<Vector3>
Array of control points defining the curve
brep
Brep
Internal BREP representation containing vertices and edges
color
number
Curve color (TypeScript only, settable)

Code Examples

Creating a Simple Curve

use opengeometry::primitives::OGCurve;
use openmaths::Vector3;

let mut curve = OGCurve::new("curve-1".to_string());
let control_points = vec![
    Vector3::new(0.0, 0.0, 0.0),
    Vector3::new(5.0, 0.0, 3.0),
    Vector3::new(10.0, 0.0, 2.0),
    Vector3::new(15.0, 0.0, 5.0),
];
curve.set_config(control_points);

Creating a Wave Pattern

// Generate a sine wave using control points
const controlPoints = [];
for (let i = 0; i <= 20; i++) {
  const x = i * 2;
  const z = Math.sin(i * 0.5) * 5;
  controlPoints.push(new Vector3(x, 0, z));
}

const wave = new Curve({
  controlPoints,
  color: 0x0088ff
});

Generating Offset Curves

let offset_data = curve.get_offset_serialized(2.0, 35.0, true);
let result: OffsetResult = serde_json::from_str(&offset_data).unwrap();

println!("Offset points: {}", result.points.len());
println!("Is closed: {}", result.is_closed);  // false for curves

Creating Multiple Parallel Curves

const baseCurve = new Curve({
  controlPoints: [
    new Vector3(0, 0, 0),
    new Vector3(10, 0, 5),
    new Vector3(20, 0, 3),
    new Vector3(30, 0, 8)
  ],
  color: 0xff0000
});

// Create offset curves on both sides
const distances = [2, 4, 6];
const upperCurves = distances.map(d => {
  const offset = baseCurve.getOffset(d);
  return new Curve({
    controlPoints: offset.points,
    color: 0x0000ff
  });
});

const lowerCurves = distances.map(d => {
  const offset = baseCurve.getOffset(-d);
  return new Curve({
    controlPoints: offset.points,
    color: 0x00ff00
  });
});

Updating Curve Control Points

curve.setConfig({
  controlPoints: [
    new Vector3(0, 0, 0),
    new Vector3(8, 0, 4),
    new Vector3(16, 0, 1),
    new Vector3(24, 0, 6)
  ],
  color: 0xffff00
});

// Change color
curve.color = 0xff00ff;

Bezier-like Curve Approximation

// Approximate a quadratic bezier with control points
function quadraticBezier(
  p0: Vector3, 
  p1: Vector3, 
  p2: Vector3, 
  segments: number
): Vector3[] {
  const points = [];
  for (let i = 0; i <= segments; i++) {
    const t = i / segments;
    const x = (1-t)*(1-t)*p0.x + 2*(1-t)*t*p1.x + t*t*p2.x;
    const y = (1-t)*(1-t)*p0.y + 2*(1-t)*t*p1.y + t*t*p2.y;
    const z = (1-t)*(1-t)*p0.z + 2*(1-t)*t*p1.z + t*t*p2.z;
    points.push(new Vector3(x, y, z));
  }
  return points;
}

const bezierPoints = quadraticBezier(
  new Vector3(0, 0, 0),
  new Vector3(10, 0, 10),
  new Vector3(20, 0, 0),
  20
);

const bezierCurve = new Curve({
  controlPoints: bezierPoints,
  color: 0xff00ff
});
Last modified on March 7, 2026