How do I get the angle without angle(x) or atan(x)?

Get help using Construct 2

Post » Wed Jul 13, 2016 7:59 pm

I'm try to understante how do i know the angle of two objects... I know about trigonometry.
I got the oppositive and the adjacent.
I got the the sine, consine and tanget.

But, i don't know how know the angle at the first point to second point.
Image

Some one can help me?
B
14
S
6
G
2
Posts: 81
Reputation: 2,241

Post » Wed Jul 13, 2016 8:18 pm

If you're trying to get the angle between to points, I'm pretty sure there's already a built in function. IIRC it's "angle(x1, y1, x2, y2)" where the X and Y correspond to the position of points 1 and 2 respectively.
B
50
S
23
G
17
Posts: 291
Reputation: 12,432

Post » Wed Jul 13, 2016 8:36 pm

Why would you want to do it without angle() or atan()? Internally angle() uses atan anyway.

You could use an infinite power series to calculate atan() in radians without using atan.
Image

Or another method is to use an array to lookup angles from tangent ratios, and using interpolation for the in between values. However this is only as precise as how many values are in the array, not to mention you'd need to populate the array beforehand.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Wed Jul 13, 2016 8:43 pm

R0J0hound wrote:Why would you want to do it without angle() or atan()? Internally angle() uses atan anyway.

You could use an infinite power series to calculate atan() in radians without using atan.
Image

Or another method is to use an array to lookup angles from tangent ratios, and using interpolation for the in between values. However this is only as precise as how many values are in the array, not to mention you'd need to populate the array beforehand.


I got it! I just want to understand how to get the angle... I use and i like to use atan(x) and angle(x), but i wanted to what it does. Anyway thanks!
B
14
S
6
G
2
Posts: 81
Reputation: 2,241

Post » Wed Jul 13, 2016 8:59 pm

Tangent: Given an angle, will return the ratio of the opposite edge over the adjacent edge.

Arctan: Is the inverse of tangent, you input the ratio (based on difference between x and y coordinates of your two points), and get the angle.

The angle expression is a shortcut that uses atan(), except you input the actual coordinates instead of the ratio.

So angle(0,0,10,20) is equal to atan(2). (Difference in Y is your opposite value 20, difference in X is 10 would be your adjacent value. 20/10 would be your ratio of 2).

Alternatively, you can look at it as angle(ax,ay,bx,by) = atan((by-ay)-(bx-ay))
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, David181, fens and 13 guests