Geometry#
Coordinate conversion utilities for spherical geometry.
UV to Spherical (Camera-Relative)#
uv_to_yaw_pitch
#
uv_to_yaw_pitch(u: float, v: float, horizontal_fov: float, vertical_fov: float) -> Tuple[float, float]
Convert UV coordinates to yaw and pitch angles.
Converts normalized image coordinates (0-1 range) to spherical coordinates using the camera field of view parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
float
|
Horizontal coordinate (0-1, left to right). |
required |
v
|
float
|
Vertical coordinate (0-1, top to bottom). |
required |
horizontal_fov
|
float
|
Horizontal field of view in degrees. |
required |
vertical_fov
|
float
|
Vertical field of view in degrees. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Tuple of (yaw, pitch) in degrees. |
float
|
|
Tuple[float, float]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If FOV values are not positive. |
Source code in src/panoocr/geometry.py
yaw_pitch_to_uv
#
yaw_pitch_to_uv(yaw: float, pitch: float, horizontal_fov: float, vertical_fov: float) -> Tuple[float, float]
Convert yaw and pitch angles to UV coordinates.
Converts spherical coordinates to normalized image coordinates using the camera field of view parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaw
|
float
|
Horizontal angle in degrees. |
required |
pitch
|
float
|
Vertical angle in degrees. |
required |
horizontal_fov
|
float
|
Horizontal field of view in degrees. |
required |
vertical_fov
|
float
|
Vertical field of view in degrees. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Tuple of (u, v) in 0-1 range. |
float
|
|
Tuple[float, float]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If FOV values are not positive. |
Source code in src/panoocr/geometry.py
Perspective to Sphere (World Coordinates)#
perspective_to_sphere
#
perspective_to_sphere(u: float, v: float, horizontal_fov: float, vertical_fov: float, yaw_offset: float, pitch_offset: float) -> Tuple[float, float]
Convert perspective image coordinates to spherical coordinates.
Uses proper 3D rotation to handle camera orientation correctly. This is the inverse of py360convert's e2p transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
float
|
Horizontal coordinate (0-1, left to right). |
required |
v
|
float
|
Vertical coordinate (0-1, top to bottom). |
required |
horizontal_fov
|
float
|
Horizontal field of view in degrees. |
required |
vertical_fov
|
float
|
Vertical field of view in degrees. |
required |
yaw_offset
|
float
|
Camera yaw (horizontal rotation) in degrees. |
required |
pitch_offset
|
float
|
Camera pitch (vertical rotation) in degrees. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Tuple of (yaw, pitch) in degrees representing world spherical coordinates. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If FOV values are not positive. |
Source code in src/panoocr/geometry.py
sphere_to_perspective
#
sphere_to_perspective(yaw: float, pitch: float, horizontal_fov: float, vertical_fov: float, yaw_offset: float, pitch_offset: float) -> Tuple[float, float] | None
Convert spherical coordinates to perspective image coordinates.
Uses proper 3D rotation to handle camera orientation correctly. This is the forward transformation matching py360convert's e2p.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaw
|
float
|
World yaw angle in degrees. |
required |
pitch
|
float
|
World pitch angle in degrees. |
required |
horizontal_fov
|
float
|
Horizontal field of view in degrees. |
required |
vertical_fov
|
float
|
Vertical field of view in degrees. |
required |
yaw_offset
|
float
|
Camera yaw (horizontal rotation) in degrees. |
required |
pitch_offset
|
float
|
Camera pitch (vertical rotation) in degrees. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float] | None
|
Tuple of (u, v) in 0-1 range if the point is within the FOV, |
Tuple[float, float] | None
|
None if the point is outside the perspective view. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If FOV values are not positive. |
Source code in src/panoocr/geometry.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
Spherical Centroid#
calculate_spherical_centroid
#
Calculate the centroid of spherical polygon(s) using 3D averaging.
This handles wrap-around at ±180° correctly by converting to 3D Cartesian coordinates, averaging in 3D space, and converting back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygons
|
List[List[Tuple[float, float]]]
|
List of polygons, each polygon is a list of (yaw, pitch) tuples in degrees. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Tuple of (center_yaw, center_pitch) in degrees. |
Source code in src/panoocr/geometry.py
Yaw Normalization#
normalize_yaw
#
Normalize yaw angle to -180 to 180 range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaw
|
float
|
Yaw angle in degrees. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Normalized yaw in -180 to 180 range. |
Source code in src/panoocr/geometry.py
Equirectangular Conversion#
yaw_to_equirectangular_x
#
Convert yaw angle to equirectangular image x coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yaw
|
float
|
Yaw angle in degrees (-180 to 180). |
required |
image_width
|
int
|
Width of the equirectangular image. |
required |
Returns:
| Type | Description |
|---|---|
float
|
X coordinate in pixels. |
Source code in src/panoocr/geometry.py
pitch_to_equirectangular_y
#
Convert pitch angle to equirectangular image y coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pitch
|
float
|
Pitch angle in degrees (-90 to 90). |
required |
image_height
|
int
|
Height of the equirectangular image. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Y coordinate in pixels. |
Source code in src/panoocr/geometry.py
equirectangular_x_to_yaw
#
Convert equirectangular image x coordinate to yaw angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
X coordinate in pixels. |
required |
image_width
|
int
|
Width of the equirectangular image. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Yaw angle in degrees (-180 to 180). |
Source code in src/panoocr/geometry.py
equirectangular_y_to_pitch
#
Convert equirectangular image y coordinate to pitch angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
float
|
Y coordinate in pixels. |
required |
image_height
|
int
|
Height of the equirectangular image. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Pitch angle in degrees (-90 to 90). |