Questions tagged [trigonometry]

Trigonometry is a branch of mathematics that studies triangles and the relationships between their sides and the angles between sides

Trigonometry is a branch of mathematics that studies triangles and the relationships between their sides and the angles between sides. Trigonometry defines the trigonometric functions, which describe those relationships and have applicability to cyclical phenomena, such as waves.

Trigonometry can be implemented into many programming languages, such as python. Trigonometry can be used to find an angle in a triangle using the side lengths etc.

References:

3369 questions
28
votes
4 answers

Calculating degrees between 2 points with inverse Y axis

I'm creating a simple 2D game in javascript/canvas. I need to figure out the angle of a certain object relative to my position. So: say I'm at (10,10) and the object is at (10,5) - that would result in 90 degrees (as positive Y is down, negative Y…
Jelle De Loecker
  • 20,999
  • 27
  • 100
  • 142
28
votes
7 answers

Find cosine similarity between two arrays

I'm wondering if there is a built in function in R that can find the cosine similarity (or cosine distance) between two arrays? Currently, I implemented my own function, but I can't help but think that R should already come with one.
defoo
  • 5,159
  • 11
  • 34
  • 39
28
votes
8 answers

Is trigonometry computationally expensive?

I read in an article somewhere that trig calculations are generally expensive. Is this true? And if so, that's why they use trig-lookup tables right? EDIT: Hmm, so if the only thing that changes is the degrees (accurate to 1 degree), would a look…
Dominic K
  • 6,975
  • 11
  • 53
  • 62
28
votes
6 answers

Calculating if an angle is between two angles

So I am making a little game where I am checking if a character can "see" another where character A can see character B if A is within a certain distance of B, and the direction in degrees of A is +/- 45 degrees of the angle B is facing. Currently,…
user1641573
  • 283
  • 1
  • 3
  • 4
27
votes
2 answers

Canvas Rotating Star Field

I'm taking the following approach to animate a star field across the screen, but I'm stuck for the next part. JS var c = document.getElementById('stars'), ctx = c.getContext("2d"), t = 0; // time c.width = 300; c.height = 300; var w =…
27
votes
6 answers

Why is sin(180) not zero when using python and numpy?

Does anyone know why the below doesn't equal 0? import numpy as np np.sin(np.radians(180)) or: np.sin(np.pi) When I enter it into python it gives me 1.22e-16.
MCF
  • 383
  • 1
  • 3
  • 6
25
votes
3 answers

Why does Math.cos(90 * Math.PI/180) yield 6.123031769111... and not zero?

I convert degrees to radians (degrees * Math.PI/180) but why does the following: Math.cos(90 * Math.PI/180) yield 6.123031769111... and not zero? I'm trying to perform 2D rotations uses matrixes and the results are completely out of whack.
Sean
  • 537
  • 1
  • 6
  • 15
25
votes
5 answers

Write code to make CPU usage display a sine wave

Write code in your favorite language and let Windows Task Manager represent a sine wave in CPU Usage History. This is a technical interview quiz from Microsoft China. I think it's a good question. Especially it's worth knowing how candidate…
chagel
  • 495
  • 6
  • 17
24
votes
2 answers

Where is the sine function?

Simple question: Where is sin()? I've searched and only found in the Rust docs that there are traits like std::num::Float that require sin, but no implementation.
Kapichu
  • 3,346
  • 4
  • 19
  • 38
23
votes
3 answers

Rotating object to face mouse pointer on mousemove

I've got a mousemove cursor in my game which will make my object shoot towards my mouse cursor. I'd like my object to always rotate along to be in line with my mousecursor. How can i convert the X and Y of where the cursor is to a degree angle to…
CaptainCarl
  • 3,411
  • 6
  • 38
  • 71
22
votes
4 answers

Why is std::sin() and std::cos() slower than sin() and cos()?

Test code: #include #include const int N = 4096; const float PI = 3.1415926535897932384626; float cosine[N][N]; float sine[N][N]; int main() { printf("a\n"); for (int i = 0; i < N; i++) { for (int j = 0; j < N;…
ornerylawn
  • 524
  • 1
  • 4
  • 9
22
votes
4 answers

How do I generate a sine wave using Python?

I'm trying to generate a sine wave of a given frequency for a given duration and then write it into a .wav file. I'm using numpy's sin function and scipy's wavfile function. I'm getting a weird sound that is definitely not a sine wave. import numpy…
22
votes
3 answers

Stable Cotangent

Is there a more stable implementation for the cotangent function than return 1.0/tan(x);?
Meh.
  • 223
  • 1
  • 2
  • 4
22
votes
6 answers

Create sine lookup table in C++

How can I rewrite the following pseudocode in C++? real array sine_table[-1000..1000] for x from -1000 to 1000 sine_table[x] := sine(pi * x / 1000) I need to create a sine_table lookup table.
user466444
  • 469
  • 3
  • 7
  • 14
22
votes
4 answers

How to approximate a half-cosine curve with bezier paths in SVG?

Suppose I want to approximate a half-cosine curve in SVG using bezier paths. The half cosine should look like this: and runs from [x0,y0] (the left-hand control point) to [x1,y1] (the right-hand one). How can I find an acceptable set of…
janesconference
  • 6,333
  • 8
  • 55
  • 73