Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: camera pose from spherical coordinate system #20

Merged
merged 13 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
equator working
  • Loading branch information
yxlao committed Sep 23, 2023
commit b84dd5180b6380e65a98078cda6edf6371a35857
30 changes: 23 additions & 7 deletions playground/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import numpy as np
import open3d as o3d

np.set_printoptions(precision=4, suppress=True)


def euler_to_R(yaw, pitch, roll):
"""
Expand Down Expand Up @@ -92,20 +94,33 @@ def polar_to_T_towards_origin(radius, theta, phi):

Args:
r (float): Radius, distance from the origin.
theta (float): Inclination, angle in the x-y plane.
phi (float): Azimuth, angle from the z-axis.
theta (float): Inclination, angle w.r.t. positive polar (+z) axis.
Range: [0, pi].
phi (float): Azimuth, rotation angle from the initial meridian (x-y) plane.
Range: [0, 2*pi].

Returns:
T of shape (4, 4).
"""
print(f"radius: {radius:.4f}, theta: {theta:.4f}, phi: {phi:.4f}")
x = radius * np.sin(theta) * np.cos(phi)
y = radius * np.sin(theta) * np.sin(phi)
z = radius * np.cos(theta)

# Camera looking from the origin towards the Y-axis, up is Z-axis.
init_R = euler_to_R(0, 0, -np.pi / 2)
print(f"x: {x:.4f}, y: {y:.4f}, z: {z:.4f}")

# Before : look at +Z, up is -Y.
# After init: look at +X, up is +Z.
init_R = euler_to_R(np.pi / 2, 0, -np.pi / 2)
theta_R = np.eye(3)
phi_R = np.eye(3)

# Rotating along z axis for phi degrees.
theta_R = euler_to_R(phi, 0, 0)

R = phi_R @ theta_R @ init_R
pose = np.eye(4)
pose[:3, :3] = init_R
pose[:3, :3] = R
pose[:3, 3] = [x, y, z]
T = ct.convert.pose_to_T(pose)

Expand All @@ -132,8 +147,9 @@ def main():
# # Create camera at x-y plane in a circle around the origin.
num_cams = 12
radius = 1.0
thetas = np.linspace(0, 2 * np.pi, num_cams, endpoint=False)
Ts = [polar_to_T_towards_origin(radius, theta, 0) for theta in thetas]
thetas = np.linspace(0, np.pi, num_cams, endpoint=False)
phis = np.linspace(0, 2 * np.pi, num_cams, endpoint=False)
Ts = [polar_to_T_towards_origin(radius, np.pi / 2, phi) for phi in phis]
Ks = [K for _ in range(num_cams)]

cameras = ct.camera.create_camera_ray_frames(Ks=Ks, Ts=Ts)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Homepage = "https://github.com/yxlao/camtools"
dev = [
"black>=22.1.0",
"pytest>=6.2.2",
"ipdb",
]

[tool.setuptools]
Expand Down