angle() function question

Discussion and feedback on Construct 2

» Tue Nov 11, 2014 10:14 pm

Hello,

I would like to know why angle() function goes into negatives after 180°. I would like it to go to 360° because my algorithm based on angle detected between an object and touch input fails for:

If value angle(x1,y1,x2,y2) is between values 135°&225° --->do something. it fails after 180°.
It also fails if i do: 135°&-135°

I figured this out with another way but again I have the feeling that this function is broken.

Plus the angle values are invetrted compared to the normal angle behavior in construct. (I've included an image)
You do not have the required permissions to view the files attached to this post.
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

» Tue Nov 11, 2014 10:39 pm

180, and -180 are the same, just as 0, and 360 are the same, as far as the circle goes.
360- 180= 180
360 + negative 180= ?
Think of it as two semicircles.
B
176
S
50
G
200
Posts: 8,632
Reputation: 124,565

» Tue Nov 11, 2014 10:42 pm

It's working correctly, it gives the angle in the range from -180 to 180 because of the math behind it.
If you want it in the range of 0 to 360 then you can convert it with (a+360)%360.

I don't have the second issue. Are you putting the coordinates in the correct order? It finds the angle from point 1 to point 2.
B
98
S
36
G
131
Posts: 5,521
Reputation: 83,505

» Tue Nov 11, 2014 10:54 pm

How would you decide the correct order?
Thus far I've just gone with the same order as they are put into conditions.
B
176
S
50
G
200
Posts: 8,632
Reputation: 124,565

» Tue Nov 11, 2014 10:58 pm

@newt I know that. But construct somehow didn't.

I used this logic and it didn't work. Past the 180° C2 was considering it's over the angle limit (maybe with the final else event but i don't see the point)

So basically once the angle did not match the width of the DragLine was returned to 0. And it happened at 180° instead of 225°. Because the angle started to decrementing. And i proved it with putting from 135to (-135) as the angle condition. The line even failed to appear so it has a problem with negative angles. Something is broken. I would like to know what.
You do not have the required permissions to view the files attached to this post.
Last edited by Uniform on Tue Nov 11, 2014 11:11 pm, edited 4 times in total.
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

» Tue Nov 11, 2014 11:01 pm

I resolved this issue with this logic but in my case the angle() didn't work properly. I would like to know why.
You do not have the required permissions to view the files attached to this post.
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

» Tue Nov 11, 2014 11:08 pm

R0J0hound wrote:I don't have the second issue. Are you putting the coordinates in the correct order? It finds the angle from point 1 to point 2.

I tried both. angle(x1,y1,x2,y2) and angle (x2,y2,x1,y1). Same problem.
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

» Tue Nov 11, 2014 11:16 pm

But yeah I could simply covert the 180° ranged angles to a 360° and this will probably work. I was just surprised that C2 does not recognise -135° as 225°
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

» Tue Nov 11, 2014 11:26 pm

System compare isn't the best way to go. Ideally you would do all the comparisons in the actions, rather than the conditions.
Maybe you could say what you are trying to do?
B
176
S
50
G
200
Posts: 8,632
Reputation: 124,565

» Tue Nov 11, 2014 11:36 pm

just to draw a line from a start.X&start.Y to a perpendicular direction depending of the relative touch.x&touch.y position.

But it's okay i resolved the stuff. Would be cool if angle did automatically convert to a 360° based value automatically. I don't see the point of decrementing after 180°.

Plus the angles are inverted compared to the normal construct angles logic. with angle() 0 is where 180 normally is.

Next time i will just write my own angle() function that adds 360 in case that that you have a negative.
Last edited by Uniform on Tue Nov 11, 2014 11:41 pm, edited 1 time in total.
B
9
S
3
G
1
Posts: 128
Reputation: 1,116

Next