I do not know how to find the angle from x & y starting positions to new_x & new_y final positions, I need a 360 degrees value.
An example, I have an object at (x24, y440) and I want to know the angle from there to (x240, y320) in a 360 degrees value
I do not know crap about math functions :'(
angle1 = atan(y1 / x1)
angle2 = atan(y2 / x2)
angle = abs(angle1 - angle2)
Holy crap BLizz thanks, I myself have been trying to figure this out ._.
That is if you are rotating it around (x0,y0).
It does not return a 0...360 value :shy:
I'm using this to test it
module Math
def self.w_angle(x1, y1, x2, y2)
angle1 = atan(y1 / x1)
angle2 = atan(y2 / x2)
angle = (angle1 - angle2).abs
return angle
end
end
p Math.w_angle(24, 24, 390, 240)
It returns the angle in radians. Use this to convert to degrees:
return (angle * 180 / Math::PI)
It still not working for me :(
def self.w_angle(x1, y1, x2, y2)
angle1 = atan(y1 / x1)
angle2 = atan(y2 / x2)
angle = (angle1 - angle2).abs
return (angle * 180 / Math::PI)
end
end
p Math.w_angle(272, 208, 390, 0)
That is not supposed to return 0.0
Try this:
def self.w_angle(x1, y1, x2, y2)
angle1 = atan2(y1, x1)
angle2 = atan2(y2, x2)
angle = (angle1 - angle2).abs
return (angle * 180 / Math::PI)
end
Pretty sure he wants the angle from the first point to the second. With this code, zero is to the right, and the angle is measured counterclockwise.
def self.w_angle(x1, y1, x2, y2)
angle = atan2(y1-y2, x2-x1) * 180 / Math::PI
if (angle < 0) angle += 360
return angle
end
But that doesn't make any sense. #_#
Yes Winkio! Thats exactly what I was trying to say! :shy:
Thanks both of you, seriously n.n
I'm not male ._.
If my suggested reason doesn't make sense: well, say you wanted to fire a projectile off at a random angle. Or maybe she is trying to make a particle system, or a geometry puzzle, or something that requires a geometric angle.
If my suggested code doesn't make sense: I reversed the y coordinates to make the value negative, to account for the fact that +y is down. atan2 has the domain from -pi/2 to pi/2, thus after I convert into degrees, i need to add 360 to any negative values to put them between 0 and 360.
I meant that it didn't make sense to subtract the coordinates. But if the coordinates were the center and the point laying on the hypotenuse, then it does make sense. My bad, I wasn't sure what you were thinking about.