Coordinate Transforms#
Coordinate transforms between Cartesian and spherical/polar parameterizations.
The 3D functions use spherical coordinates \((r, \theta, \phi)\) with \(\theta\) the polar angle and \(\phi\) the azimuth. The 2D functions use polar coordinates \((r, \theta)\) or just the angle \(\theta\) on the unit circle.
- spherical_inr.coords.r2_to_rt(r2_coords: Tensor) Tensor[source]#
Convert Cartesian coordinates in \(\mathbb{R}^2\) to polar form \((r, \theta)\).
- Parameters:
r2_coords (torch.Tensor) – Tensor with shape (…, 2) representing \([x, y]\).
- Returns:
Tensor with shape (…, 2) containing \([r, \theta]\).
- Return type:
torch.Tensor
- Raises:
ValueError – If the last dimension of
r2_coordsis not 2.
- spherical_inr.coords.r2_to_t(r2_coords: Tensor) Tensor[source]#
Project Cartesian coordinates on the unit circle to their angle \(\theta\).
- Parameters:
r2_coords (torch.Tensor) – Tensor with shape (…, 2) representing \([x, y]\).
- Returns:
Tensor with shape (…, 1) containing \([\theta]\).
- Return type:
torch.Tensor
- Raises:
ValueError – If the last dimension of
r2_coordsis not 2.
- spherical_inr.coords.r3_to_rtp(r3_coords: Tensor) Tensor[source]#
Convert Cartesian coordinates to spherical coordinates \((r, \theta, \phi)\).
- Parameters:
r3_coords (torch.Tensor) – Tensor with shape (…, 3) representing \([x, y, z]\).
- Returns:
Tensor with shape (…, 3) containing \([r, \theta, \phi]\).
- Return type:
torch.Tensor
- Raises:
ValueError – If the last dimension of
r3_coordsis not 3.
- spherical_inr.coords.r3_to_tp(r3_coords: Tensor) Tensor[source]#
Project Cartesian coordinates on the unit sphere to angles \((\theta, \phi)\).
- Parameters:
r3_coords (torch.Tensor) – Tensor with shape (…, 3) representing \([x, y, z]\).
- Returns:
Tensor with shape (…, 2) containing \([\theta, \phi]\).
- Return type:
torch.Tensor
- Raises:
ValueError – If the last dimension of
r3_coordsis not 3.
- spherical_inr.coords.rt_to_r2(rt_coords: Tensor) Tensor[source]#
Map polar coordinates \((r, \theta)\) to Cartesian coordinates in \(\mathbb{R}^2\).
- Parameters:
rt_coords (torch.Tensor) – Tensor with shape (…, 2) representing \([r, \theta]\).
- Returns:
Tensor with shape (…, 2) containing \([x, y]\).
- Return type:
torch.Tensor
- Raises:
ValueError – If the last dimension of
rt_coordsis not 2.
- spherical_inr.coords.rtp_to_r3(rtp_coords: Tensor) Tensor[source]#
Map spherical coordinates \((r, \theta, \phi)\) to Cartesian coordinates.
The conversion follows
\[x = r \sin\theta \cos\phi,\quad y = r \sin\theta \sin\phi,\quad z = r \cos\theta.\]- Parameters:
rtp_coords (torch.Tensor) – Tensor with shape (…, 3) representing \([r, \theta, \phi]\).
- Returns:
Tensor with shape (…, 3) containing \([x, y, z]\).
- Return type:
torch.Tensor
- Raises:
ValueError – If the last dimension of
rtp_coordsis not 3.
- spherical_inr.coords.t_to_r2(t_coords: Tensor) Tensor[source]#
Convert an angle on the unit circle to Cartesian coordinates.
- Parameters:
t_coords (torch.Tensor) – Tensor with shape (…, 1) containing the angle \(\theta\).
- Returns:
Tensor with shape (…, 2) containing \([x, y]\) on the unit circle.
- Return type:
torch.Tensor
- Raises:
ValueError – If the last dimension of
t_coordsis not 1.
- spherical_inr.coords.tp_to_r3(tp_coords: Tensor) Tensor[source]#
Map unit-sphere angles \((\theta, \phi)\) to Cartesian coordinates.
- Parameters:
tp_coords (torch.Tensor) – Tensor with shape (…, 2) representing \([\theta, \phi]\).
- Returns:
Tensor with shape (…, 3) containing \([x, y, z]\) on the unit sphere.
- Return type:
torch.Tensor
- Raises:
ValueError – If the last dimension of
tp_coordsis not 2.