scimba_torch.geometry.parametric_hypersurface

A module for parametric hypersurfaces.

Classes

ParametricHyperSurface(parametric_domain, ...)

Base class for representing a parametric hypersurface.

class ParametricHyperSurface(parametric_domain, surface)[source]

Bases: SurfacicDomain

Base class for representing a parametric hypersurface.

\[\{ y = \text{surface}(t) | t \in D \} where D is the parametric domain.\]
Parameters:
  • parametric_domain (VolumetricDomain | list[tuple[float, float]] | Tensor) – The parametric domain.

  • surface (Mapping) – Mapping from the parametric domain to the domain.

Examples

Creating a parametric hypersurface

from pathlib import Path
import matplotlib.pyplot as plt

from scimba_torch.geometry.parametric_hypersurface import (
    ParametricHyperSurface,
)
from scimba_torch.geometry.utils import (
    read_points_normals_from_file,
    write_points_normals_to_file,
)

bean_2d = ParametricHyperSurface.bean_2d()

points, normals = bean_2d.sample(1000)

# print("points: ", points)
# print("normals: ", normals)

points_np = points.cpu().detach().numpy()
normals_np = normals.cpu().detach().numpy()

plt.figure(figsize=(7, 7))
plt.scatter(points_np[:, 0], points_np[:, 1], s=1, label="BC")
plt.quiver(
    points_np[::20, 0],
    points_np[::20, 1],
    normals_np[::20, 0],
    normals_np[::20, 1],
    color="red",
    label="normals",
    alpha=0.5,
)
plt.legend()
plt.show()

filename = "test.xy"
write_points_normals_to_file(points, normals, filename)

points2, normals2 = read_points_normals_from_file(filename)

assert points2.shape == points.shape
assert normals2.shape == normals.shape
assert torch.all(points == points2)
assert torch.all(normals == normals2)

filepath = Path(filename)
if filepath.is_file():
    filepath.unlink()
sample(n)[source]

Sample points on the hypersurface.

Parameters:

n (int) – the number of points to sample.

Return type:

tuple[Tensor, Tensor]

Returns:

A tuple of tensors, the points and the normals.

estimate_bounding_box(nb_samples=2000, inflation=0.1)[source]

Estimate a bounding box for the parametric curve by sampling points on it.

Parameters:
  • nb_samples (int) – the number of points to sample.

  • inflation (float) – the inflation factor for over-estimation.

Return type:

Tensor

Returns:

A bounding box of shape (d,2) containing all the points.

static bean_2d(a=3, b=5, theta=-1.5707963267948966)[source]

Bean 2D curve.

Parameters:
  • a (int)

  • b (int) –

  • theta (float) – the rotation angle.

Return type:

ParametricHyperSurface

Returns:

The Bean 2D as a parametric hypersurface.