Getting angle back from a sin/cos conversion
atan2(s_y, s_x) should give you the correct angle. Maybe you have reversed the order of s_x and s_y. Also, you can use the acos and asin functions directly on s_x and s_y respectively.
atan2(s_y, s_x) should give you the correct angle. Maybe you have reversed the order of s_x and s_y. Also, you can use the acos and asin functions directly on s_x and s_y respectively.
If you don’t need the actual euclidean angle, but something that you can use as a base for angle comparisons, then changing to taxicab geometry may be a choice, because you can drop trigonometry and it’s slowness while MAINTAINING THE ACCURACY (or at least with really minor loosing of accuracy, see below). In main modern … Read more
Is this what you’re looking for? startX = x; startY = y; endX = x + 40 * Math.sin(angle); endY = y + 40 * Math.cos(angle); And draw a line from (startX, startY) to (endX, endY) in whatever API you’re using. Also note that angle is in radians. If you had it in degrees, you … Read more
Here’s the mathematical solution which can be applied in any language: x = x0 + r * cos(theta) y = y0 + r * sin(theta) x0 and y0 are the coordinates of the centre, r is the radius, and theta is in radians. The angle is measured anticlockwise from the x-axis. This is the code … Read more
Why is this happening? Trigonometric functions generally expect units in radians, while 90 is in degrees. This also applies for other functions such as cosine and tangent, not just the sine function. Most programming languages require trigonometric functions to provide their arguments in radians. This simplifies many things, especially on the implementation side as code … Read more
Haversine and Vincenty are two algorithms for solving different problems. Haversine computes the great circle distance on a sphere while Vincenty computes the shortest (geodesic) distance on the surface of an ellipsoid of revolution. So the answer to your question can be broken into 2 parts: Do you want to compute the distance on a … Read more
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
This is more a math problem than a Swift problem: let sinus = sin(90.0 * Double.pi / 180) print(“Sinus \(sinus)”) let cosinus = cos(90 * Double.pi / 180) print(“Cosinus \(cosinus)”) let tangent = tan(90 * Double.pi / 180) print(“Tangent \(tangent)”) prints Sinus 1.0 Cosinus 6.12323399573677e-17 Tangent 1.63312393531954e+16 Sinus of 90 degrees is 1 (correct) Cosinus … Read more
You have a 19-digit literal, but double usually has 15-17 digit precision. As a result, you can get a small relative error (when converting to double), but big enough (in the context of sine calculation) absolute error. Actually, different implementations of the standard library have differences in treating such large numbers. For example, in my … Read more