# angle and distance problem

For questions about using Classic.

### » Tue Sep 09, 2008 11:29 am

when i use the angle (a,a,b,b) and distance function, they work, but they dont return accurate results, is this normal?

because once it gets past 179.9_ it goes into negatives? which isnt right is it?

also when i use distance it return an innacurate number also, even if the objects are perfectly alligned its givng me 160 as its number?
B
55
S
7
G
6
Posts: 1,949
Reputation: 7,693

### » Tue Sep 09, 2008 2:49 pm

Distance works fine for me... you sure you're hotspots are right or something?

also, the angle goes negative depending on the direction of the object,
either you can have angles going from 0 to 360 or -180 to 180
You should be able to just forget about it, any time you'll probably need the angle (trig) it won't matter that it's going negative. Trig functions are periodic which means for example sin(x)=sin(x+360), so it won't actually make a difference to any calculations you have to do with the angle. (unless you want to display it from 0 to 360 or something).
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

### » Tue Sep 09, 2008 5:02 pm

Faggatron is right, angles can be outside the 0-360 range - 365 degrees "wraps around" back to 5 degrees again, because it's one full rotation plus 5 degrees. Same goes for negative, etc. If you want to display the result, add 180 to it Also, distance will give the distance in pixels, and if you're passing object coordinates, it will measure from their hot spots.
Scirra Founder
B
363
S
216
G
75
Posts: 23,124
Reputation: 180,557

### » Tue Sep 09, 2008 8:10 pm

is distance doing this? or something different entirely

sqrt(((A.x-B.x)^2)+((A.y-B.y)^2))

cause its returning numbers based on quadrants, does it return actual distance?, or does it return the translation amount?
B
55
S
7
G
6
Posts: 1,949
Reputation: 7,693

### » Tue Sep 09, 2008 8:46 pm

Yes, as you would expect the distance() expression uses the Pythagoras theorum as you have written. I'm sure it's working correctly, and it just returns the distance between two points - which is always positive and is unrelated to quadrants. I've used it for several things now and it works fine as far as I know!
Scirra Founder
B
363
S
216
G
75
Posts: 23,124
Reputation: 180,557

### » Tue Sep 09, 2008 8:51 pm

[quote="Ashley":zabexiut]Yes, as you would expect the distance() expression uses the Pythagoras theorum as you have written. I'm sure it's working correctly, and it just returns the distance between two points - which is always positive and is unrelated to quadrants. I've used it for several things now and it works fine as far as I know![/quote:zabexiut]

i dunno why but i tested it using a text(s) as a counter, and i put one text to distance(blalblabla)

and the other too the pytho but got different results?
B
55
S
7
G
6
Posts: 1,949
Reputation: 7,693

### » Tue Sep 09, 2008 8:57 pm

I can't imagine why that would happen. Post a .cap and I'll see whats going on when I get my connection back.
Scirra Founder
B
363
S
216
G
75
Posts: 23,124
Reputation: 180,557

Return to Help & Support using Construct Classic

### Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests