trigonometry

Filling a polygon

妖精的绣舞 提交于 2021-02-19 08:44:17
问题 I created this function that draws a simple polygon with n number of vertexes: void polygon (int n) { double pI = 3.141592653589; double area = min(width / 2, height / 2); int X = 0, Y = area - 1; double offset = Y; int lastx, lasty; double radius = sqrt(X * X + Y * Y); double quadrant = atan2(Y, X); int i; for (i = 1; i <= n; i++) { lastx = X; lasty = Y; quadrant = quadrant + pI * 2.0 / n; X = round((double)radius * cos(quadrant)); Y = round((double)radius * sin(quadrant)); setpen((i * 255)

sine cosine modular extended precision arithmetic

给你一囗甜甜゛ 提交于 2021-02-18 07:27:52
问题 I've seen in many impletation of sine/cosine a so called extended modular precision arithmetic. But what it is for? For instance in the cephes implemetation, after reduction to the range [0,pi/4], they are doing this modular precision arithmetic to improve the precision. Hereunder the code: z = ((x - y * DP1) - y * DP2) - y * DP3; where DP1, DP2 and DP3 are some hardcoded coefficient. How to find those coefficient mathematically? I've understand the purpose of "modular extension arithmetic"

sine cosine modular extended precision arithmetic

拟墨画扇 提交于 2021-02-18 07:27:05
问题 I've seen in many impletation of sine/cosine a so called extended modular precision arithmetic. But what it is for? For instance in the cephes implemetation, after reduction to the range [0,pi/4], they are doing this modular precision arithmetic to improve the precision. Hereunder the code: z = ((x - y * DP1) - y * DP2) - y * DP3; where DP1, DP2 and DP3 are some hardcoded coefficient. How to find those coefficient mathematically? I've understand the purpose of "modular extension arithmetic"

calculating the bounce of a ball

≯℡__Kan透↙ 提交于 2021-02-11 12:35:18
问题 I essentially just want to make a ball bounce from say 100x to 300x... I looked for parabolic equations and then at trig functions and I can't seem to get it to work right... its been a while since I've done math so I probably am not even approaching this right... Here is my code for the whole bounce, if anyone can point me in the correct equation that would be wonderful. private void btStart_Click(object sender, EventArgs e) { lbBall.Location = new Point(0, 0); bounceBall(lbBall, 100); }

calculating the bounce of a ball

孤人 提交于 2021-02-11 12:35:16
问题 I essentially just want to make a ball bounce from say 100x to 300x... I looked for parabolic equations and then at trig functions and I can't seem to get it to work right... its been a while since I've done math so I probably am not even approaching this right... Here is my code for the whole bounce, if anyone can point me in the correct equation that would be wonderful. private void btStart_Click(object sender, EventArgs e) { lbBall.Location = new Point(0, 0); bounceBall(lbBall, 100); }

How are the trigonometric functions tested in the GNU C Library?

时间秒杀一切 提交于 2021-02-09 06:59:07
问题 I'm trying to figure out how to best write unit tests for scientific and/or mathematical functions. I searched the source code for the GNU C Library for unit tests for the sin() and cos() functions and came across the atest-sincos.c source file, reproduced below. (It can be found here) Can someone walk me through this file and give a rough idea what is being tested here? I see what looks very much like the Runge-Kutta algorithm for numerically solving differential equations, and also possibly

sine wave generation in c++

荒凉一梦 提交于 2021-02-08 19:44:10
问题 I am trying to generate a set of points, which when plotted as a graph represent a sine wave of 1 cycle. The requirements are : a sine wave of 1 cycle lower limit = 29491 upper limit = 36043 no of points = 100 Amplitude = 3276 zero offset = 32767 Code : int main() { ofstream outfile; outfile.open("data.dat",ios::trunc | ios::out); for(int i=0;i<100;i++) { outfile << int(3276*sin(i)+32767) << "\n"; } outfile.close(); return 0; } I am generating and storing the points in a file. When these

sine wave generation in c++

五迷三道 提交于 2021-02-08 19:43:55
问题 I am trying to generate a set of points, which when plotted as a graph represent a sine wave of 1 cycle. The requirements are : a sine wave of 1 cycle lower limit = 29491 upper limit = 36043 no of points = 100 Amplitude = 3276 zero offset = 32767 Code : int main() { ofstream outfile; outfile.open("data.dat",ios::trunc | ios::out); for(int i=0;i<100;i++) { outfile << int(3276*sin(i)+32767) << "\n"; } outfile.close(); return 0; } I am generating and storing the points in a file. When these

sine wave generation in c++

雨燕双飞 提交于 2021-02-08 19:43:54
问题 I am trying to generate a set of points, which when plotted as a graph represent a sine wave of 1 cycle. The requirements are : a sine wave of 1 cycle lower limit = 29491 upper limit = 36043 no of points = 100 Amplitude = 3276 zero offset = 32767 Code : int main() { ofstream outfile; outfile.open("data.dat",ios::trunc | ios::out); for(int i=0;i<100;i++) { outfile << int(3276*sin(i)+32767) << "\n"; } outfile.close(); return 0; } I am generating and storing the points in a file. When these

sine wave generation in c++

被刻印的时光 ゝ 提交于 2021-02-08 19:43:24
问题 I am trying to generate a set of points, which when plotted as a graph represent a sine wave of 1 cycle. The requirements are : a sine wave of 1 cycle lower limit = 29491 upper limit = 36043 no of points = 100 Amplitude = 3276 zero offset = 32767 Code : int main() { ofstream outfile; outfile.open("data.dat",ios::trunc | ios::out); for(int i=0;i<100;i++) { outfile << int(3276*sin(i)+32767) << "\n"; } outfile.close(); return 0; } I am generating and storing the points in a file. When these