scimba_torch.geometry.parametric_hypersurface¶
A module for parametric hypersurfaces.
Classes
|
Base class for representing a parametric hypersurface. |
- class ParametricHyperSurface(parametric_domain, surface)[source]¶
Bases:
SurfacicDomainBase 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.