trigonometry

C++ - Play back a tone generated from a sinusoidal wave

三世轮回 提交于 2019-12-12 07:19:06
问题 Hey everyone, I'm currently trying to figure out how to play back a tone I have generated using a sinusoidal wave. Here's my code: #include <iostream> #include <OpenAL/al.h> #include <OpenAL/alc.h> #include <Math.h> using namespace std; int main (int argc, char * const argv[]) { int number = 0; int i, size; double const Pi=4*atan(1); cout << "Enter number of seconds:" << endl; scanf("%d", &number); size = 44100*number; unsigned char buffer [size]; //buffer array for(i = 0; i < size; i++){

Circle to Circle Segment Collision

那年仲夏 提交于 2019-12-12 07:12:40
问题 I'm struggling to find a rock solid solution to detecting collisions between a circle and a circle segment. Imagine a Field of View cone for a game enemy, with the circles representing objects of interest. The diagram at the bottom is something I drew to try and work out some possible cases, but i'm sure there are more. I understand how to quickly exlude extreme cases, I discard any targets that don't collide with the entire circle, and any cases where the center of the main circle is within

Calculate points around a circle in android

一世执手 提交于 2019-12-12 05:38:58
问题 I'm programming a game in android where an enemy ship needs to fire in a star pattern around itself. Basically, for any X number of shots I set the enemy ship to fire, I want it to divide 360 degrees around itself by the number of shots and fire the shots off at exactly equilateral angles. So, 3 shots would be fired off with the first shot at 360 degrees, the second shot at 120 degrees and the third shot at 240 degrees. 4 shots would be 360,90,180,270 and so on. Then each shot will travel

JavaScript floating point precision issue

隐身守侯 提交于 2019-12-12 05:28:46
问题 I am encountering a floating point precision issue, does anybody know why this happens? Why is it that the cosine function is affected, but not he sine function. Math.sin(90 * Math.PI / 180); // returned: 1, expected: 1 1 - Math.sin(90 * Math.PI / 180); // returned: 0, expected: 0 Math.cos(90 * Math.PI / 180); // returned: 6.123233995736766e-17, expected: 0 1 - Math.cos(90 * Math.PI / 180); // returned: 0.9999999999999999, expected: 1 回答1: The canonical answer to this one is What Every

maxima multiple trigonometric equations

巧了我就是萌 提交于 2019-12-12 04:52:12
问题 I'm trying to solve an equation using maxima 13.04.2 but the answer isn't what I expect. Example: y2=A2*cos(2*pi*f2*t+phase2) we know A2=.4,f2=6.4951,t=1, trying to find **phase2** y2=.4*cos(2*pi*6.4951+phase2) I tried to solve the y2 equation for phase2 in maxima but it got rid of the cos function kill(all); A:A; phase:phase; solve(A*cos(2*pi*f*t+phase)=0,phase); The answer that came back was I thought something like this was suppose to come back y2 = A2×cos(2πf2t + φ2) ⇒ y2/A2 = cos(2πf2t +

Implement Sine in Java without Math.sin function

不想你离开。 提交于 2019-12-12 04:32:52
问题 I'm trying to implement the sine function in Java without using Math.sin(x) . So I'm trying to realize this with the Taylor series. Unfortunately, this code gives the wrong result(s). If you don't know what the Taylor series is, have a look: Here's the code snippet I created: public static double sin(double a) { double temp = 1; int denominator = -1; if(a == Double.NEGATIVE_INFINITY || !(a < Double.POSITIVE_INFINITY)) { return Double.NaN; } if(a != 0) { for (int i = 0; i <= a; i++) {

SceneKit Child node position not changed during Parent node rotation

江枫思渺然 提交于 2019-12-12 03:49:41
问题 I'm trying to recode the camera management in SceneKit. For that, I use UIPanGestureRecognizer for the rotation of camera around an object (In this case around the centre of scene). Next I get the different ratio or length to determinate the angle to add at axes (X, Y, Z) of imaginary sphere where camera is attached (cameraOrbit in code). My problem is that I use the position of camera to determinate the angle to add at sphere. But the position is constant. When I change the sphere rotation,

Rotate line around center

半城伤御伤魂 提交于 2019-12-12 03:35:49
问题 I have to use a propriertary graphics-engine for drawing a line. I can rotate the whole drawing by its origin point (P1). What I want, is to rotate it around its center point(M). So basically that it looks like L_correct instead of L_wrong. I think, it should be possible to correct it, by moving it from P1 to P2. But I cannot figure out what formula could be used, to determine the distance. It must probably involve the angle, width and height... So basically my question is, if there is a

Calculating small angle between large vectors in 3D

雨燕双飞 提交于 2019-12-12 03:32:58
问题 I'm calculating small angle between large vectors in 3D. I use common formula: double angle = atan2(norm(cross_product), dot_product); In general I'm trying to get angle between my vector on Earth and Normal to Earth elipsoid(gravitational vector) to align my vector to gravitational vector. I store my vector in ECEF coordinates. And values are about: normal_ecef[2853169.5286430484, 2139463.4659523461, 5254245.1411450412] v_ecef[11.4893763275, 9.3040978122, 16.5129716340] cross_product

How to calculate absolute position of transformed div

試著忘記壹切 提交于 2019-12-12 02:54:01
问题 When you use transform on div, absolute positioning not working as you expected anymore, and seems like it needs to be calculated manually. For instance when you want your div to be at the bottom of container you do: div{ position:absolute; bottom:0%; } But if you transform this div like -webkit-transform:rotateX(angle); it won't be at the bottom of container. Is places somewhere in between of container depends of its size. I create jsfiddle to illustrate this, and also show what i'm trying