Fastest implementation of sine, cosine and square root in C++ (doesn’t need to be much accurate)

Here’s the guaranteed fastest possible sine function in C++: double FastSin(double x) { return 0; } Oh, you wanted better accuracy than |1.0|? Well, here is a sine function that is similarly fast: double FastSin(double x) { return x; } This answer actually does not suck, when x is close to zero. For small x, … Read more

Fast transcendent / trigonometric functions for Java

Computer Approximations by Hart. Tabulates Chebyshev-economized approximate formulas for a bunch of functions at different precisions. Edit: Getting my copy off the shelf, it turned out to be a different book that just sounds very similar. Here’s a sin function using its tables. (Tested in C since that’s handier for me.) I don’t know if … Read more

Calculate second point knowing the starting point and distance

It seems you are measuring distance (R) in meters, and bearing (theta) counterclockwise from due east. And for your purposes (hundereds of meters), plane geometry should be accurate enough. In that case, dx = R*cos(theta) ; theta measured counterclockwise from due east dy = R*sin(theta) ; dx, dy same units as R If theta is … Read more

Calculating the angle between two lines without having to calculate the slope? (Java)

The atan2 function eases the pain of dealing with atan. It is declared as double atan2(double y, double x) and converts rectangular coordinates (x,y) to the angle theta from the polar coordinates (r,theta) So I’d rewrite your code as public static double angleBetween2Lines(Line2D line1, Line2D line2) { double angle1 = Math.atan2(line1.getY1() – line1.getY2(), line1.getX1() – … Read more

Java BigDecimal trigonometric methods

ApFloat is a library which contains arbitrary-precision approximations of trigometric functions and non-integer powers both; however, it uses its own internal representations, rather than BigDecimal and BigInteger. I haven’t used it before, so I can’t vouch for its correctness or performance characteristics, but the api seems fairly complete.