actionscript 3 - How can I get polar coordinates represented properly? -


i have following hexagonal grid , trying calculate degrees each edge hexagon center (light blue): enter image description here

the blue highlighted hex correct @ 0 degrees , quadrant (lower right) correct. here angle calculation method:

private static function calculateangle(hex1:hexagon, hex2:hexagon):number {     // hex1 passed in grid center or start     var diffy:number = math.abs(hex2.center.y) - math.abs(hex1.center.y);     var diffx:number = math.abs(hex2.center.x) - math.abs(hex1.center.x);     var radians:number = math.atan(diffy / diffx);      return radians * 180 / math.pi; } 

why remaining angles (text in each hexagon) incorrect?

you're close correct; need compensate periodicity of atan. standard way use atan2, returns signed angle in (-pi, pi] instead of unsigned angle in [0, pi). can this:

var radians:number = math.atan2(     hex2.center.y - hex1.center.y, hex2.center.x - hex1.center.x); 

note didn't include call abs in there: signedness of values needed atan2 know quadrant in!

edit: if you're looking angle in [0, pi], represents minimum angle between center hex , blue-highlighted hex, can take absolute value of result of atan2: return math.abs(radians) * 180 / math.pi; question leaves little unclear 1 you're asking for.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -