Last active
November 12, 2023 08:02
-
-
Save mortik/495a4e59f7b92c4c20ab1f2f07c12b67 to your computer and use it in GitHub Desktop.
Star Citizen Quantum Traveltimes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const calculateTravelTime = ( | |
a1: number, | |
a2: number, | |
vmax: number, | |
distance: number, | |
) => { | |
const dc = distance - (4 * vmax ** 2 * (2 * a1 + a2)) / (3 * (a1 + a2) ** 2); | |
if (dc < 0) { | |
// drive does not reach vmax | |
return ( | |
((4 * a1 * vmax) / (a2 ** 2 - a1 ** 2)) * | |
(2 * | |
Math.cos( | |
(1 / 3) * | |
Math.acos( | |
(3 * (a2 - a1) ** 2 * (a1 + a2) ** 2 * distance) / | |
(8 * vmax ** 2 * a1 ** 3) - | |
1, | |
), | |
) - | |
1) | |
); | |
} | |
// drive reaches vmax | |
return ( | |
(4 * vmax) / (a1 + a2) + | |
distance / vmax - | |
(4 * vmax * (2 * a1 + a2)) / (3 * (a1 + a2) ** 2) | |
); | |
}; | |
export const calculateTravelTimeReal = ( | |
a1: number, | |
a2: number, | |
vmax: number, | |
distance: number, | |
) => { | |
const dc = distance - (4 * vmax ** 2 * (2 * a1 + a2)) / (3 * (a1 + a2) ** 2); | |
if (dc < 0) { | |
// drive does not reach vmax | |
const z = | |
(3 * (a2 - a1) ** 2 * (a1 + a2) ** 2 * distance) / | |
(8 * vmax ** 2 * a1 ** 3) - | |
1; | |
if (z > 1) { | |
return ( | |
((4 * a1 * vmax) / (a2 ** 2 - a1 ** 2)) * | |
(2 * Math.cosh(-Math.log(z - Math.sqrt(z ** 2 - 1)) / 3) - 1) | |
); | |
} | |
return ( | |
((4 * a1 * vmax) / (a2 ** 2 - a1 ** 2)) * | |
(2 * Math.cos((1 / 3) * Math.acos(z)) - 1) | |
); | |
} | |
// drive reaches vmax | |
return ( | |
(4 * vmax) / (a1 + a2) + | |
distance / vmax - | |
(4 * vmax * (2 * a1 + a2)) / (3 * (a1 + a2) ** 2) | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment