Lines
3D line segments
What is a Line3D?
A Line3D renders as a line segment between two 3D points. Lines are useful for:
- Connecting points
- Visualizing vectors
- Drawing edges of shapes
- Construction lines
Basic Usage
const line = scene.create("line3d", {
start: vec3(0, 0, 0),
end: vec3(5, 3, 2),
color: "cyan",
thickness: 1,
});Styling Lines
Color
Any CSS color string:
scene.create("line3d", {
start: vec3(0, 0, 0),
end: vec3(1, 0, 0),
color: "red",
});Thickness
Control the line width:
scene.create("line3d", {
start: vec3(0, 0, 0),
end: vec3(1, 0, 0),
thickness: 0.5, // Thin
});
scene.create("line3d", {
start: vec3(0, 1, 0),
end: vec3(1, 1, 0),
thickness: 2, // Thick
});Examples
Connecting Two Points
Pass point atoms directly as line endpoints:
const p1 = scene.create("point3d", { coords: vec3(0, 0, 0), color: "red" });
const p2 = scene.create("point3d", { coords: vec3(3, 3, 3), color: "blue" });
scene.create("line3d", {
start: p1.coords,
end: p2.coords,
color: "white",
thickness: 0.5,
});Drag either point and the line follows.
Line with Length Label
const p1 = scene.create("point3d", { coords: vec3(0, 0, 0), color: "red" });
const p2 = scene.create("point3d", { coords: vec3(3, 2, 1), color: "blue" });
scene.create("line3d", {
start: p1.coords,
end: p2.coords,
color: "white",
});
// Label at the midpoint showing the line's length
const midpoint = scene.atom((get) => {
const start = get(p1.coords);
const end = get(p2.coords);
return vec3((start.x + end.x) / 2, (start.y + end.y) / 2, (start.z + end.z) / 2);
});
scene.create("overlay3d", {
position: midpoint,
content: scene.atom((get) => {
const diff = Vec3.subtract(get(p2.coords), get(p1.coords));
return `d = ${Vec3.length(diff).toFixed(2)}`;
}),
anchor: "bottom-left",
offset: vec2(6, -6),
});Updating Properties
const line = scene.create("line3d", {
start: vec3(0, 0, 0),
end: vec3(1, 1, 1),
color: "white",
});
// Update endpoints
line.start.set(vec3(-1, -1, -1));
line.end.set(vec3(2, 2, 2));
// Update styling
line.color.set("pink");
line.thickness.set(2);API Reference
Options
| Property | Type | Default | Description |
|---|---|---|---|
start | Vec3 | { x: 0, y: 0, z: 0 } | Starting point |
end | Vec3 | { x: 0, y: 0, z: 0 } | Ending point |
color | string | "white" | CSS color string |
thickness | number | 1 | Line width |
visible | boolean | true | Whether the line is shown |
pointerEvents | "auto" | "none" | "auto" | Whether the line receives pointer events |
tags | string[] | [] | Custom tags for grouping |
Returned Item
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier |
start | BoundAtom<Vec3> | Start point atom |
end | BoundAtom<Vec3> | End point atom |
color | BoundAtom<string> | Color atom |
thickness | BoundAtom<number> | Thickness atom |
visible | BoundAtom<boolean> | Visibility atom |
pointerEvents | BoundAtom<string> | Pointer events atom |
tags | BoundAtom<string[]> | Tags atom |