Reputation: 4142
I am looking to generate some 3D trajectory data for an aircraft simulation.
The idea is that the aircraft takes off at some location x
and continues to ascend at some average ascent velocity a_v
and angle a_theta
until it reaches a maximum altitude m_a
. The aircraft would then continue at its m_a
until it reaches a certain distance d_d
from its destination, at which point it will begin its descent at some angle d_theta
with an average descent velocity of d_v
. Finally, the aircraft lands at destination y
.
I would like the function to return a list of 3D points.
I am looking to implement this in either Python (preferred) or C#.
For illustration purposes:
Does anyone know how I can achieve this? Is there perhaps some open source project which does this? I have been looking for a while now, but have not found anything.
Upvotes: 6
Views: 1611
Reputation: 54233
You didn't write any code, so I won't write any either. Python with math
package is more than enough to solve this problem.
Required steps:
a_theta
. Find the point where it reaches m_a
altitude.d_theta
. Find the point where it reaches m_a
altitude.EarthRadius + m_a
For a list of 3D points, you don't need either a_v
, d_v
or d_d
.
Upvotes: 0
Reputation: 17262
I recommend you to solve the problem in 2 independent steps so that the airplane does not pass through the ground :
For 1. you can use the spherical interpolation techniques on Quaternions.
Quaternion slerp(Quaternion v0, Quaternion v1, double t) {
// Only unit quaternions are valid rotations.
// Normalize to avoid undefined behavior.
v0.normalize();
v1.normalize();
// Compute the cosine of the angle between the two vectors.
double dot = dot_product(v0, v1);
const double DOT_THRESHOLD = 0.9995;
if (fabs(dot) > DOT_THRESHOLD) {
// If the inputs are too close for comfort, linearly interpolate
// and normalize the result.
Quaternion result = v0 + t*(v1 – v0);
result.normalize();
return result;
}
// If the dot product is negative, the quaternions
// have opposite handed-ness and slerp won't take
// the shorter path. Fix by reversing one quaternion.
if (dot < 0.0f) {
v1 = -v1;
dot = -dot;
}
Clamp(dot, -1, 1); // Robustness: Stay within domain of acos()
double theta_0 = acos(dot); // theta_0 = angle between input vectors
double theta = theta_0*t; // theta = angle between v0 and result
Quaternion v2 = v1 – v0*dot;
v2.normalize(); // { v0, v2 } is now an orthonormal basis
return v0*cos(theta) + v2*sin(theta);
}
Upvotes: 0