trigonometry

Python: Calculate sine/cosine with a precision of up to 1 million digits

我的梦境 提交于 2019-11-29 11:08:51
Question is pretty self-explanatory. I've seen a couple of examples for pi but not for trigo functions. Maybe one could use a Taylor series as done here but I'm not entirely sure how to implement that in python. Especially how to store so many digits. I should mention: this ideally would run on vanilla python i.e. no numpy etc. Thanks! Edit: as said, I know the question has been asked before but it's in java and I was looking for a python implementation :) Edit 2: wow I wasn't aware people here can be so self-absorbed. I did try several approaches but none would work. I thought this a place

NAudio playing a sine wave for x milliseconds using C#

家住魔仙堡 提交于 2019-11-29 10:39:33
I am using NAudio to play a sinewave of a given frequency as in the blog post Playback of Sine Wave in NAudio . I just want the sound to play() for x milliseconds and then stop. I tried a thread.sleep, but the sound stops straightaway. I tried a timer, but when the WaveOut is disposed there is a cross-thread exception. I tried this code, but when I call beep the program freezes. public class Beep { public Beep(int freq, int ms) { SineWaveProvider32 sineWaveProvider = new SineWaveProvider32(); sineWaveProvider.Amplitude = 0.25f; sineWaveProvider.Frequency = freq; NAudio.Wave.WaveOut waveOut =

Rotate point in rectangle

大兔子大兔子 提交于 2019-11-29 09:04:44
问题 I have a point in a rectangle that I need to rotate an arbitrary degree and find the x y of the point. How can I do this using javascript. Below the x,y would be something like 1,3 and after I pass 90 into the method it will return 3,1. |-------------| | * | | | | | |-------------| _____ | *| | | | | | | | | _____ |-------------| | | | | | *| |-------------| _____ | | | | | | | | |* | _____ Basically I am looking for the guts to this method function Rotate(pointX,pointY,rectWidth,rectHeight

C++ (and maths) : fast approximation of a trigonometric function

百般思念 提交于 2019-11-29 06:46:31
问题 I know this is a recurring question, but I haven't really found a useful answer yet. I'm basically looking for a fast approximation of the function acos in C++, I'd like to know if I can significantly beat the standard one. But some of you might have insights on my specific problem: I'm writing a scientific program which I need to be very fast. The complexity of the main algorithm boils down to computing the following expression (many times with different parameters): sin( acos(t_1) + acos(t

Given an angle and length, how do I calculate the coordinates

大城市里の小女人 提交于 2019-11-29 06:02:03
问题 Assuming the upper left corner is (0,0) and I'm given an angle of 30 degrees, a starting point of (0,300), a line length of 600, how do I calculate the ending point of the line so that the line is representative of the angle given. The C pseudo-code is main() { int x,y; getEndPoint(30, 600, 0, 300, &x, &y); printf("end x=%d, end y=%d", x, y); } // input angle can be from 0 - 90 degrees void getEndPoint(int angle, int len, int start_x, int start_y, int *end_x, int *end_y) { calculate the

How can I work around the fact that in C++, sin(M_PI) is not 0?

浪子不回头ぞ 提交于 2019-11-29 03:36:07
In C++, const double Pi = 3.14159265; cout << sin(Pi); // displays: 3.58979e-009 it SHOULD display the number zero I understand this is because Pi is being approximated, but is there any way I can have a value of Pi hardcoded into my program that will return 0 for sin(Pi)? (a different constant maybe?) In case you're wondering what I'm trying to do: I'm converting polar to rectangular, and while there are some printf() tricks I can do to print it as "0.00", it still doesn't consistently return decent values (in some cases I get "-0.00") The lines that require sin and cosine are: x = r*sin

Accuracy of Math.Sin() and Math.Cos() in C#

ε祈祈猫儿з 提交于 2019-11-29 02:23:16
I am terribly annoyed by the inaccuracy of the intrinsic trig functions in the CLR. It is well know that Math.Sin(Math.PI)=0.00000000000000012246063538223773 instead of 0. Something similar happens with Math.Cos(Math.PI/2) . But when I am doing a long series of calculations that on special cases evaluate to Math.Sin(Math.PI/2+x)-Math.Cos(x) and the result is zero for x=0.2, but not zero for x=0.1 (try it). Another issue is when the argument is a large number, the inaccuracy gets proportionally large. So I wonder if anyone has coded some better representation of the trig functions in C# for

Determine if angle lies between 2 other angles

馋奶兔 提交于 2019-11-29 01:20:17
I am trying to figure out whether a angle lies between 2 other angles. I have been trying to create a simple function to perform this but none of my techniques will work for all possible values of the angles. Can you help me edit my function to correctly determine if a angle lies between 2 other angles? In the above picture; I use the green point as the central point, then I determine the angle of each line to the green point. I then calculate the angle of the black point to the green point. I am trying to check if the angle of the black dot is BETWEEN the 2 lines' angles. NOTE: In my case; an

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

房东的猫 提交于 2019-11-29 00:38:42
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . 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... :) 回答1: This has nothing to do with C#. There is just some elementary mathematics involved. x = x0 + r

How to calculate the angle of a vector from the vertical?

拈花ヽ惹草 提交于 2019-11-28 23:42:53
Im trying to find out the angle (in degrees) between two 2D vectors. I know I need to use trig but I'm not too good with it. This is what I'm trying to work out (the Y axis increases downward): I'm trying to use this code at the moment, but it's not working at all (calculates random angles for some reason): private float calcAngle(float x, float y, float x1, float y1) { float _angle = (float)Math.toDegrees(Math.atan2(Math.abs(x1-x), Math.abs(y1-y))); Log.d("Angle","Angle: "+_angle+" x: "+x+" y: "+y+" x1: "+x1+" y1: "+y1); return _angle; } These are my results (There constant when providing a