trigonometry

Finding the coordinates on the edge of a circle [closed]

牧云@^-^@ 提交于 2019-11-30 03:27:01
Using C#: How do I get the (x, y) coordinates on the edge of a circle for any given degree, if I have the center coordinates and the radius? There is probably SIN, TAN, COSIN and other grade ten math involved... :) David M This has nothing to do with C#. There is just some elementary mathematics involved. x = x0 + r * cos(theta) y = y0 + r * sin(theta) theta is in radians, x0 and y0 are the coordinates of the centre, r is the radius, and the angle is measured anticlockwise from the x-axis. But if you want it in C#, and your angle is in degrees: double x = x0 + r * Math.Cos(theta * Math.PI /

Special CUDA Double Precision trig functions for SFU

回眸只為那壹抹淺笑 提交于 2019-11-29 23:47:17
问题 I was wondering how I would go about using __cos(x) (and respectively __sin(x) ) in the kernel code with CUDA. I looked up in the CUDA manual that there is such a device function however when I implement it the compiler just says that I cannot call a host function in the device. However, I found that there are two sister functions cosf(x) and __cosf(x) the latter of which runs on the SFU and is overall much faster than the original cosf(x) function. The compiler does not complain about the _

Calculating Distance Between 2 Cities [closed]

独自空忆成欢 提交于 2019-11-29 21:05:18
How do you calculate the distance between 2 cities? Dana the Sane If you need to take the curvature of the earth into account, the Great-Circle distance is what you're looking for. The Wikipedia article probably does a better job of explaining how the formula works than me, and there's also this aviation formulary page that covers that goes into more detail. The formulas are only the first part of the puzzle though, if you need to make this work for arbitrary cities, you'll need a location database to get the lat/long from. Luckily you can get this for free from Geonames.org , although there

How to compute correctly rounded trigonometric functions in degrees?

ぐ巨炮叔叔 提交于 2019-11-29 19:36:46
问题 How could I define trigonometric functions that take arguments in degrees instead of the usual radians, and compute correctly rounded results for these arguments? Multiplying the argument by M_PI/180.0 before passing it to the corresponding function in radians does not work, because M_PI/180.0 is not π/180. Section 5.5 of the Handbook of Floating-Point Arithmetic offers a method to compute the correctly rounded product of the argument by π/180, but some arguments will still be such that this

No such acos function exists

谁说胖子不能爱 提交于 2019-11-29 17:00:59
I've a problem. I want to get the nearest points on google map in android app. Different points/coordinates are stored in sqlite database. And I have to get the nearest 5 from them. The Query I'm using is: SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 5; But I'm getting an error i.e. "no such function: acos exists". What will be its proper solution IgKh SQLite doesn't support any trigonometric functions by

Why is std::sin() and std::cos() slower than sin() and cos()?

这一生的挚爱 提交于 2019-11-29 16:31:33
问题 Test code: #include <cmath> #include <cstdio> const int N = 4096; const float PI = 3.1415926535897932384626; float cosine[N][N]; float sine[N][N]; int main() { printf("a\n"); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cosine[i][j] = cos(i*j*2*PI/N); sine[i][j] = sin(-i*j*2*PI/N); } } printf("b\n"); } Here is the time: $ g++ main.cc -o main $ time ./main a b real 0m1.406s user 0m1.370s sys 0m0.030s After adding using namespace std; , the time is: $ g++ main.cc -o main $ time .

Sine calculation with Taylor series not working

醉酒当歌 提交于 2019-11-29 16:20:08
I wrote a sine function in Java, that should calculate the sine of x like My function looks like public static double sine(int x) { double result = 0; for(int n = 0; n <= 8; n++) { double temp = 2 * n + 1; result += Math.pow(-1, n) * Math.pow(x, temp) / fact(temp); // fact() calculates faculty } return result; } Only a few decimal places match to Math.sin(), but only if x is smaller then 6 and the limit of n equals to 8. Sometimes, if x is greater than 6 sine() returns even 4.106 or if limit of n is greater than 32, it returns NaN or -Infinity... What am I doing wrong? Hope you can help me and

Math.Cos & Math.Sin in C#

半腔热情 提交于 2019-11-29 13:31:29
I'm trying something that I thought should be reasonably simple. I have an angle, a position and a distance and I want to find the X,Y co-ordinates from this information. With an example input of 90 degrees I convert the value to radians with the following code: public double DegreeToRadian(float angle) { return Math.PI * angle / 180.0; } This gives me 1.5707963267949 radians Then when I use Math.Cos(radians) I end up with an an answer of: 6.12303176911189E-17 What the heck is going on? The cosine of 90 degrees should be 0, so why am I getting such a deviance... and more importantly how can I

Why do sin(45) and cos(45) give different results? [duplicate]

匆匆过客 提交于 2019-11-29 12:16:39
This question already has an answer here: Is floating point math broken? 30 answers This is something I wasn't expecting. I know these numbers are not 100% exact, but I wasn't expecting complementary angles giving different results of sin and cos : This following function returns 0.70710678118654746000000... sin(45 * PI / 180.0); while this follwing function returns 0.70710678118654757000000... cos(45 * PI / 180.0); so, it's: 0.707106781186547**46**000000... vs 0.707106781186547**57**000000... and not only those... sin(1 * PI / 180.0) also returns a slightly different number than cos(89 * PI /

numpy.sin(pi) returns negative value

被刻印的时光 ゝ 提交于 2019-11-29 11:38:12
The following code: a = numpy.sin(2. * numpy.pi) print(a < 0) return "True". But in reality a = 0. How could I fix that? In addition, I have a matrix with a lot of value like "a" and I want to make sure that my matrix contains non-negative value. This because of floating point arithmetic, and accuracy reasons. The result is the best approximation of sin one can get to be representable as a floating point number. Usually you solve near-zero problems like this: a = numpy.sin(2. * numpy.pi) print(abs(a) < 1e-10) You may also want to read this . In reality a <> 0 because in reality numpy.pi is not