It is not possible to get the angle between two points

Discuss issues specific to the Flash/AS3 port of Box2D
gramcracker
Posts: 21
Joined: Wed Feb 25, 2015 10:36 am

It is not possible to get the angle between two points

Postby gramcracker » Mon Aug 03, 2015 2:02 pm

I just wanted to demonstrate that actionscript/flash is not capable of determining the angle between two points.

Below I try several different methods to do the calculation and get a different angle each time, which is always wrong.



protected function angleCalc (x1:Number, y1:Number, x2:Number, y2:Number):Number
{
var dx:Number = x2 - x1;
var dy:Number = y2 - y1;
var j:Number = Math.atan2(dy,dx) * Constants.RADIANS_TO_DEGREES;
return j;
}

switch(Constants.weapon)
{

case 1:

var div:int = 360 / 9;

var targetAngle:Number = angleCalc(bombObject.body.GetPosition().x,
bombObject.body.GetPosition().y,
car.GetPosition().x,
car.GetPosition().y);

var deltaX=bombObject.body.GetPosition().x - car.GetPosition().x;
var deltaY=bombObject.body.GetPosition().y - car.GetPosition().y;

var realAngle:Number = 180.0 / Math.PI * Math.atan2(bombObject.body.GetPosition().x - car.GetPosition().x, bombObject.body.GetPosition().y - car.GetPosition().y);

var cantGetAngle:Number = Math.atan(deltaY / deltaX) * 180 / Math.PI;

var impossibleToGetAngle:Number = (targetAngle + 90) - 180;
trace("Angles: ",altAngle,targetAngle,90);



The trace result is a bunch of different angles that correspond to nothing, and never match the measurement provided by this website https://www.easycalculation.com/algebra ... -angle.php

Either someone is playing a joke on me, or I've stepped into the twilight zone.

Return to “Flash”



Who is online

Users browsing this forum: Baidu [Spider] and 1 guest