3 ms·
The math can be optimized by at least an order of magnitude. Trigonometry functions are expensive, especially the reverse ones. If v=0.5, see [1] for how to f
by Const-me 9y ago
The math can be optimized by at least an order of magnitude.
Trigonometry functions are expensive, especially the reverse ones.
If v=0.5, see [1] for how to find out sine/cosine of a maxSpread * v. For angleBetweenCenters + maxSpread * v, see [2] for how to find sine + cosine of a sum of angles.
If you’ll do all that math in the symbolic form (you can use Maple or Mathematica or something similar), you’ll get the equivalent formulae for p1-p4 that won’t use any trigonometry, only simple math and probably a square root.
[1] https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Half-angle_formulae https://en.wikipedia.org/wiki/List_of_trigonometric_identiti...
[2] https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Angle_sum_and_difference_identities https://en.wikipedia.org/wiki/List_of_trigonometric_identiti...
- Const-me 9y agoImplemented a 2D angle class for cases like that, where you would otherwise use these slow trigonometry functions. It’s C++ but should be easy to convert to JavaScript or any other OO language. https://gist.github.com/Const-me/46f90ce7fc2bc65dc12a41442ed51f73 https://gist.github.com/Const-me/46f90ce7fc2bc65dc12a41442ed...