Created
January 14, 2021 04:23
-
-
Save zensharp/6adf7d2851c02e239e1f3c8863ddab52 to your computer and use it in GitHub Desktop.
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
public bool TryGetSecant(Vector3 position, Vector3 velocity, Vector3 acceleration, float arcDistance, out Vector3 secant) { | |
if (acceleration == Vector3.zero) { | |
secant = velocity; | |
return false; | |
} | |
var axis = Vector3.Cross(velocity, acceleration); | |
if (axis == Vector3.zero) { | |
secant = velocity; | |
return false; | |
} | |
var radius = Mathf.Pow(velocity.magnitude, 3.0F) / axis.magnitude; | |
var inwards = Vector3.Cross(axis, velocity).normalized; | |
var radiusVector = -inwards * radius; | |
var center = position + -radiusVector; | |
var angle = arcDistance / radius; | |
var rotation = Quaternion.AngleAxis(angle * Mathf.Rad2Deg, axis); | |
var endpoint = center + rotation * radiusVector; | |
secant = position - endpoint; | |
return !(secant == Vector3.zero); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment