There are a number of minor issues that are getting in your way. The following corrections are assuming you are using the definition you provided by Wikipedia:
The re and im variables should be inside the for loop for variable k, so that they get reset for every element of the output sequence
phi is missing a factor of 2
The signs of some of the sin and cos ...
You should always question whether an angle is actually necessary, or if a vector would suffice.
Here, all we need is the vector from the start to the end:
Vector3 direction = endPos - startPos;
Then you can use that vector to align the forward vector of your transform:
transform.forward = direction;
Or you can compute a new orientation with transform....
Well, this is my final working solution of a function detect_pedestrian
car_velocity = car.body.__GetLinearVelocity()
if car_velocity == (0,0):
car_velocity = (0,1)
car_vector = Box2D.b2Body.__GetTransform(car.body).R.GetYAxis()
pedestrian_vector = pedestrian.body.position - car.body.position
pedestrian_relative = ...
The dot product of two UNIT vectors equals the cosine of the angle between those vectors.
so in order to get what you expect you have to use unit vectors - so be sure to have your two vectors normalized before doing the dot product (looks like you don't do that)
To calculate vector a, you need to use GetPostion() on the bodies, and subtract them, then normalize it.
// Get vector a
b2Vec2 carp = carbody.GetPosition();
b2Vec2 pedp = pedbody.GetPosition();
b2Vec2 a = b2SubV2V2( pedp, carp );
// Get vector b
carbody.GetTransform().R().col1(); // assume car travels in +x, use col2() for +y.
// Determine ...
I solved my problem guys. Trick was to set origin correctly
var degrees = (Math.atan2((aimingPoint.x - xDownPoint).toDouble(), -(aimingPoint.y - yDownPoint).toDouble()) * 180.0 / Math.PI - 180.0f).toFloat()
powerIndicator.rotation = degrees