trigonometry

Calculate saw and triangle wave from specific data

纵饮孤独 提交于 2019-12-03 20:27:33
I need to calculate a triangle and saw wave but it is a little complicate because of my model and the data I'm able to work with (but maybe I'm just confused). I'm able to calculate my sine wave but I'm not really using a frame counter. What I do is, calculate a theta_increment variable which I can use the next time I need to calculate a sample. This works like this: float x = note.frequency / AppSettings::sampleRate; float theta_increment = 2.0f * M_PI * x; float value = 0; if(waveType == SINE){ value = sin(note.theta) * fixedAmplitude; } Now that I have the value of the currend frame/sample

Find the Angle between two Bearings

喜你入骨 提交于 2019-12-03 17:18:11
问题 Given two bearing, how do I find the smallest angle between them? So for example if 1 heading is 340 degrees and the second is 10 degrees the smallest angle will be 30 degrees. I've attached a picture to show what I mean. I've tried subtracting one from the other but that didn't work because of the wrap around effect of a circle. I've also tried using negative degrees (180 - 359 being -180 to 0) but that got messed up when trying to calculate the angle between positive and negative number. I

How to calculate Heading using Gyro and magnetometer

强颜欢笑 提交于 2019-12-03 16:14:58
I have raw data of Gyroscope and magnetometer. on basis of this data, i have to calculate Heading information with an accuracy of 1Deg. I would like to know, is there any algorithm which can help me to get heading info using available information with mentioned accuracy? Any article or any link also will be helpful. Thanks I am assuming you are using phone to collect gyroscope+magnetometer data. You cannot calculate Heading with Gyro+Magnetometer unless you know initial state of device. You have to try Accelerometer+Magnetometer . You can get heading values from rotation-matrix' or yaw`

Fit sine wave with a distorted time-base

百般思念 提交于 2019-12-03 15:50:34
I want to know the best way to fit a sine-wave with a distorted time base, in Matlab. The distortion in time is given by a n-th order polynomial (n~10), of the form t_distort = P(t) . For example, consider the distortion t_distort = 8 + 12t + 6t^2 + t^3 (which is just the power series expansion of (t-2)^3 ). This will distort a sine-wave as follows: I want to be able to find the distortion given this distorted sine-wave. (i.e. I want to find the function t = G(t_distort) , but t_distort = P(t) is unknown.) Here's an analytical driven route that takes asin of the signal with proper unwrapping

Plot the sine and cosine functions

我的梦境 提交于 2019-12-03 15:06:50
I'm currently having some problems regarding my homework. Here's the Exercise: (Plot the sine and cosine functions) Write a program that plots the sine function in red and the cosine function in blue. hint: The Unicode for Pi is \u03c0 . To display -2Pi, use g.drawString("-2\u03c0", x, y). For a trigonometric function like sin(x), x is in radians. Use the following loop to add the points to a polygon p for (int x = -170; x <= 170; x++) { p.addPoint(x + 200, 100 - (int)(50 * Math.sin((x / 100.0) * 2 * Math.PI))); -2Pi is at ( 100, 100 ), the center of the axis is at ( 200, 100 ), and 2Pi is at

Calculating angles between line segments (Python) with math.atan2

六眼飞鱼酱① 提交于 2019-12-03 14:12:15
I am working on a spatial analysis problem and part of this workflow is to calculate the angle between connected line segments. Each line segment is composed of only two points, and each point has a pair of XY coordinates (Cartesian). Here is the image from GeoGebra. I am always interested in getting a positive angle in 0 to 180 range . However, I get all kind of angles depending on the order of vertices in input line segments. The input data I work with is provided as tuples of coordinates. Depending on the vertex creation order, the last/end point for each line segment can be different. Here

How to calculate Heading using Gyro and magnetometer

空扰寡人 提交于 2019-12-03 13:46:38
问题 I have raw data of Gyroscope and magnetometer. on basis of this data, i have to calculate Heading information with an accuracy of 1Deg. I would like to know, is there any algorithm which can help me to get heading info using available information with mentioned accuracy? Any article or any link also will be helpful. Thanks 回答1: I am assuming you are using phone to collect gyroscope+magnetometer data. You cannot calculate Heading with Gyro+Magnetometer unless you know initial state of device.

math.sin incorrect result

丶灬走出姿态 提交于 2019-12-03 13:44:30
>>> import math >>> math.sin(68) -0.897927680689 But sin(68) = 0.927 (3 decimal places) Any ideas about why I am getting this result? Thanks. >>> import math >>> print math.sin.__doc__ sin(x) Return the sine of x (measured in radians). math.sin expects its argument to be in radians, not degrees, so: >>> import math >>> print math.sin(math.radians(68)) 0.927183854567 by default angle in Python is calculated in radians. So, you can try to multiply the angle ( degrees ) by 0.01745 - to convert it to degrees and input the values. print(math.sin(60*0.01745)) 0.8659266112878228 来源: https:/

3D coordinate of 2D point given camera and view plane

一笑奈何 提交于 2019-12-03 13:13:25
I wish to generate rays from the camera through the viewing plane. In order to do this, I need my camera position ("eye"), the up, right, and towards vectors (where towards is the vector from the camera in the direction of the object that the camera is looking at) and P, the point on the viewing plane. Once I have these, the ray that's generated is: ray = camera_eye + t*(P-camera_eye); where t is the distance along the ray (assume t = 1 for now). My question is, how do I obtain the 3D coordinates of point P given that it is located at position (i,j) on the viewing plane? Assume that the upper

Vectorized Trig functions in C?

℡╲_俬逩灬. 提交于 2019-12-03 12:58:46
I'm looking to calculate highly parallelized trig functions (in block of like 1024), and I'd like to take advantage of at least some of the parallelism that modern architectures have. When I compile a block for(int i=0; i<SIZE; i++) { arr[i]=sin((float)i/1024); } GCC won't vectorize it, and says not vectorized: relevant stmt not supported: D.3068_39 = __builtin_sinf (D.3069_38); Which makes sense to me. However, I'm wondering if there's a library to do parallel trig computations. With just a simple taylor series up the 11th order, GCC will vectorize all the loops, and I'm getting speeds over