Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
Planar2Dof.hpp
Go to the documentation of this file.
1// Vulcan 2-DOF Planar Dynamics
2// Pure stateless functions for planar point mass and pendulum computations
3#pragma once
4
6
7#include <janus/janus.hpp>
8
9namespace vulcan::dynamics {
10
11// =============================================================================
12// 2-DOF Planar Point Mass
13// =============================================================================
14
25template <typename Scalar>
26Vec2<Scalar> planar_acceleration(const Scalar &force_x, const Scalar &force_y,
27 const Scalar &mass) {
28 return Vec2<Scalar>{force_x / mass, force_y / mass};
29}
30
37template <typename Scalar>
38Vec2<Scalar> planar_acceleration(const Vec2<Scalar> &force,
39 const Scalar &mass) {
40 return force / mass;
41}
42
50template <typename Scalar>
51Vec2<Scalar>
52planar_acceleration_gravity(const Scalar &force_x, const Scalar &force_y,
53 const Scalar &mass, const Scalar &gravity) {
54 return Vec2<Scalar>{force_x / mass, force_y / mass + gravity};
55}
56
57// =============================================================================
58// Spherical Pendulum (2-DOF on sphere)
59// =============================================================================
60
78template <typename Scalar>
79Scalar
80spherical_pendulum_theta_ddot(const Scalar &theta, const Scalar &theta_dot,
81 const Scalar &phi_dot, const Scalar &length,
82 const Scalar &gravity, const Scalar &zeta) {
83 Scalar sin_theta = janus::sin(theta);
84 Scalar cos_theta = janus::cos(theta);
85 Scalar omega_n = janus::sqrt(gravity / length);
86
87 // θ̈ = sin(θ)cos(θ)φ̇² - (g/L)sin(θ) - 2ζω_n θ̇
88 return sin_theta * cos_theta * phi_dot * phi_dot -
89 (gravity / length) * sin_theta -
90 Scalar(2) * zeta * omega_n * theta_dot;
91}
92
106template <typename Scalar>
107Scalar spherical_pendulum_phi_ddot(const Scalar &theta, const Scalar &theta_dot,
108 const Scalar &phi_dot, const Scalar &length,
109 const Scalar &gravity, const Scalar &zeta) {
110 Scalar sin_theta = janus::sin(theta);
111 Scalar cos_theta = janus::cos(theta);
112 Scalar omega_n = janus::sqrt(gravity / length);
113
114 // Regularized cot(θ) to avoid division by zero
115 Scalar cot_theta = cos_theta / (sin_theta + Scalar(1e-10));
116
117 // φ̈ = -2cot(θ)θ̇φ̇ - 2ζω_n φ̇
118 return Scalar(-2) * cot_theta * theta_dot * phi_dot -
119 Scalar(2) * zeta * omega_n * phi_dot;
120}
121
128template <typename Scalar>
129Vec3<Scalar> spherical_pendulum_position(const Scalar &theta, const Scalar &phi,
130 const Scalar &length) {
131 Scalar sin_theta = janus::sin(theta);
132 Scalar cos_theta = janus::cos(theta);
133 Scalar sin_phi = janus::sin(phi);
134 Scalar cos_phi = janus::cos(phi);
135
136 return Vec3<Scalar>{
137 length * sin_theta * cos_phi, // x
138 length * sin_theta * sin_phi, // y
139 length * cos_theta // z (down from pivot)
140 };
141}
142
152template <typename Scalar>
153Scalar spherical_pendulum_energy(const Scalar &theta, const Scalar &theta_dot,
154 const Scalar &phi_dot, const Scalar &length,
155 const Scalar &mass, const Scalar &gravity) {
156 Scalar sin_theta = janus::sin(theta);
157 Scalar cos_theta = janus::cos(theta);
158
159 // Kinetic energy: T = 0.5 * m * L² * (θ̇² + sin²(θ)φ̇²)
160 Scalar KE =
161 Scalar(0.5) * mass * length * length *
162 (theta_dot * theta_dot + sin_theta * sin_theta * phi_dot * phi_dot);
163
164 // Potential energy: V = m*g*L*(1 - cos(θ)) [zero at bottom]
165 Scalar PE = mass * gravity * length * (Scalar(1) - cos_theta);
166
167 return KE + PE;
168}
169
170// =============================================================================
171// Simple Pendulum (1-DOF special case: phi = 0)
172// =============================================================================
173
184template <typename Scalar>
185Scalar simple_pendulum_acceleration(const Scalar &theta,
186 const Scalar &theta_dot,
187 const Scalar &length, const Scalar &gravity,
188 const Scalar &zeta) {
189 Scalar omega_n = janus::sqrt(gravity / length);
190 return -(gravity / length) * janus::sin(theta) -
191 Scalar(2) * zeta * omega_n * theta_dot;
192}
193
197template <typename Scalar>
198Scalar simple_pendulum_period(const Scalar &length, const Scalar &gravity) {
199 return Scalar(2) * Scalar(M_PI) * janus::sqrt(length / gravity);
200}
201
205template <typename Scalar>
206Scalar simple_pendulum_omega(const Scalar &length, const Scalar &gravity) {
207 return janus::sqrt(gravity / length);
208}
209
210} // namespace vulcan::dynamics
Definition Guided5Dof.hpp:13
Vec2< Scalar > planar_acceleration_gravity(const Scalar &force_x, const Scalar &force_y, const Scalar &mass, const Scalar &gravity)
Definition Planar2Dof.hpp:52
Vec2< Scalar > planar_acceleration(const Scalar &force_x, const Scalar &force_y, const Scalar &mass)
Definition Planar2Dof.hpp:26
Definition GravityTypes.hpp:7
Definition MassProperties.hpp:12
Scalar gravity(const Scalar &altitude)
US Standard Atmosphere 1976 - Gravitational Acceleration (table-based).
Definition USSA1976.hpp:248