trigonometry

How do I generate a Sine Sweep in Java (Android)

血红的双手。 提交于 2019-12-02 03:01:30
I found Playing an arbitrary tone with Android to be helpful when I was generating a frequency tone. Now I want the frequency to change while the tone is playing. I modified the genTone to be similar to this: private void genTone(double startFreq, double endFreq, int dur) { int numSamples = dur * sampleRate; sample = new double[numSamples]; double currentFreq = 0, numerator; for (int i = 0; i < numSamples; ++i) { numerator = (double) i / (double) numSamples; currentFreq = startFreq + (numerator * (endFreq - startFreq)); if ((i % 1000) == 0) { Log.e("Current Freq:", String.format("Freq is: %f

Finding Third Points of triangle using other two points with known distances [closed]

限于喜欢 提交于 2019-12-02 02:51:24
In the above image, I have three points (x1,y1) (x2,y2) (x3,y3) . I know the values of x1,y1 and x2,y2 .I know the euclidean distances of (x1,y1)->(x3,y3) and (x2,y2)->(x3,y3) . Having these information how can I find the (x3,y3) ? I expect anything like a code snippet or the logic will be useful... I have tried to solve this using the circle equations but I don't know how to proceed. We can solve this using a bit of trigonometry: Cosine theorem (phi is the inner angle at the first point): d3^2 = d1^2 + d2^2 - 2 d1 d2 cos phi cos phi = (d1^2 + d2^2 - d3^2) / (2 d1 d2) For a given cosine, we

How to make a sprite point at the mouse. XNA C#

こ雲淡風輕ζ 提交于 2019-12-02 02:49:43
问题 If you would look at this diagram link text, I need to find angle A by only knowing the length of all sides of a right triangle. I don't know trig and need some help. 回答1: There are actually 2 questions in your post. How to make a sprite point at the mouse. XNA C#: You will have to calculate the direction between the position of the sprite and the position of the mouse. This can be done using trigonometry functions. In this case: Arctangens2 So let's use the math library: MouseState

Calculating the coordinates of the third point of a triangle

最后都变了- 提交于 2019-12-02 02:12:12
OK, I know this sounds like it should be asked on math.stackoverflow.com, but this is embarrassingly simple maths that I've forgotten from high-school, rather than advanced post-graduate stuff! I'm doing some graphics programming, and I have a triangle. Incidentally, two of this triangle's sides are equal, but I'm not sure if that's relevant. I have the coordinates of two of the corners (vertices), but not the third (these coordinates are pixels on the screen, in case that's relevant). I know the lengths of all three sides. How do I determine the coordinates of the unknown vertex? for oblique

Is there any way to optimize sincos calls in CUDA?

情到浓时终转凉″ 提交于 2019-12-02 02:04:49
问题 I'm writing a program in CUDA that makes a huge amount of calls to the sincos() function, using double precision. I'm afraid this is one of the biggest bottlenecks of the code, and I cannot reduce the number of calls to the function. Is there any decent approximation to sincos in CUDA or in a library I can import? I am also quite concerned with the accuracy, so the better the approximation is, the happier my code will be. I've also thought about building a lookup table or approximating the

Atan2 in C# (or similar lanaguge)

不羁岁月 提交于 2019-12-02 01:24:46
Can anyone point me to a good example of Atan2 defined in C# (or something vaguely close to C#) that doesn't use any internal math methods? This is on .NET Microframework, so there is no such thing as an internal math library. I have already defined Sin()/Cos(), but I am having a lot of trouble with Atain2. There are a few scatter shot math libraries in NETMF, but I have found them all to be flawed or broken. One of the major ones didn't even define PI correctly! An implementation should be quite straight forward starting with the definition on Wikipedia/atan2 and then using the infinite

c++ Sorting 2D Points clockwise

拥有回忆 提交于 2019-12-02 01:20:14
i wrote a program to arrange points on a graph in clockwise manner from 12 o'clock such that, a vector containing these points is sorted in that order. I am using atan2 to get the angle from 12 o'clock and then making adjustments based on the quadrant. i am trying to figure out where the bug is coming from as it is not ordering them correctly. So given 4 random points like those in the photo, it should order then in the containing vector as P1,P2,P3,P4 Here is my code: //sort_points.cpp #include <iostream> #include <math.h> #include <algorithm> #include <vector> using namespace std; class

Obj-C Calculator - Radians to Degrees

泄露秘密 提交于 2019-12-02 00:57:30
问题 I've been watching the Stanford CS193P lectures and I've been working on the assignment calculator. I got through the first assignment fairly easily, and I'm trying to do the extra credit for the assignment now. I'm stuck however at one of the extra credit questions: Implement a user-interface for choosing whether the operand to sin() or cos() is considered radians or degrees. When you call sin(x) in the C library, x is assumed to be in radians (i.e. 0 to 2π goes around the circle once), but

How to find out if the angle between two vectors is external or internal?

隐身守侯 提交于 2019-12-01 22:46:13
I know how to find out angle between 2 vectors, but it always gives me internal angle, but I want it to give me always the angle in anticlockwise direction, even if it is greater then 180. I'm using C++ but it is not really important because I need to get the theory. This is what I am using now You're looking for the atan2(y,x) function ( http://en.wikipedia.org/wiki/Atan2 ). If you give it the two components of a 2D vector, it will give you the angle of the vector from the x axis, in the counter-clockwise direction. To solve your specific problem try: atan2(v_y, v_x) - atan2(u_y, u_x) Then

How to find the nearest points to given coordinates with MATLAB?

孤街醉人 提交于 2019-12-01 22:26:07
问题 I need to solve a minimization problem with Matlab and I'm wondering which is the easiest solution. All the potential solutions that I've been thinking in require lot of programming effort. Suppose that I have a lat/long coordinate point (A,B), what I need is to search for the nearest point to this one in a map of lat/lon coordinates. In particular, the latitude and longitude arrays are two matrices of 2030x1354 elements (1km distance) and the idea is to find the unique indexes in those