reconstruct a quadric from 9 points and ray-render it¶
Keywords: quadric · quadric_from_points · ray · refine · analyze · join
Embeds nine points in the 3D projective quadric space, reconstructs the quadric
through them as the join of the point embeddings (join([...])), and draws
the raw Quadric3D (analytic ray renderer) next to its refined Ellipsoid
(standard mesh pipeline).
Run¶
Source¶
ga/quadric/quadric3d_raycast.py
Code¶
# SPDX-License-Identifier: Apache-2.0
# Copyright 2021 Christian Perwass
"""quadric3d_raycast.py — reconstruct a quadric from 9 points and ray-render it.
Embeds nine points in the 3D projective quadric space, reconstructs the quadric
through them as the **join** of the point embeddings (``join([...])``), and draws
the raw ``Quadric3D`` (analytic ray renderer) next to its refined ``Ellipsoid``
(standard mesh pipeline).
Run with: uv run python py/examples/ga/quadric/quadric3d_raycast.py
Keywords: quadric, quadric_from_points, ray, refine, analyze, join
"""
import math
from pytanga.algebra import join
from pytanga.geometry import Geometry, Point, analyze, refine
from pytanga.quadric import BasisQ3
from pytanga.viz import Visualizer
# Nine points on the ellipsoid x²/4 + y²/9 + z²/16 = 1.
a, b, c = 2.0, 3.0, 4.0
s = math.sqrt(3.0)
points = [
(a, 0.0, 0.0),
(-a, 0.0, 0.0),
(0.0, b, 0.0),
(0.0, -b, 0.0),
(0.0, 0.0, c),
(0.0, 0.0, -c),
(a / s, b / s, c / s),
(a / s, b / s, -c / s),
(a / s, -b / s, c / s),
]
geo = Geometry(BasisQ3())
mv = join([geo(Point(*p)) for p in points]) # grade-9 quadric blade
raw = analyze(mv) # raw Quadric3D (rendered via the ray proxy by default)
specific = refine(raw) # Ellipsoid (mesh pipeline)
viz = Visualizer(title="Tanga — quadric through 9 points")
viz.add(raw, label="Quadric3D (ray)")
viz.add(specific, label="Ellipsoid (mesh)")
print(f"Reconstructed quadric refined to: {type(specific).__name__}")
viz.show()
viz.wait()