local Cos = math.cos
local Sin = math.sin
local Rad = math.rad
obj.x = 100 + Cos(Rad(270)) * 100 ,then the obj.x is equal to 100.
If I know the obj.x equal to 100 can I get the angle ?
100 = 100 + Cos(Rad(angle))*100
local Cos = math.cos
local Sin = math.sin
local Rad = math.rad
obj.x = 100 + Cos(Rad(270)) * 100 ,then the obj.x is equal to 100.
If I know the obj.x equal to 100 can I get the angle ?
100 = 100 + Cos(Rad(angle))*100
Just rearange the equation.
I did it step by step for you, so you know what’s going on.
1. obj.x = 100 + math.cos(math.rad(angle)) \* 100 2. obj.x - 100 = math.cos(math.rad(angle)) \* 100 3. (obj.x - 100) / 100 = math.cos(math.rad(angle)) 4. math.acos((obj.x - 100) / 100) = math.rad(angle) 5. math.deg(math.acos((obj.x - 100) / 100)) = angle
Should work like this if I understood your question correct.
Unless this is for learning sake, I wouldn’t do these calculations on my own.
There is a 2D math plugin to handle all that:
https://store.coronalabs.com/plugin/math2d
Be sure to activate it before using it.
It is also integrated in SSK if you want to grab the source.
Just rearange the equation.
I did it step by step for you, so you know what’s going on.
1. obj.x = 100 + math.cos(math.rad(angle)) \* 100 2. obj.x - 100 = math.cos(math.rad(angle)) \* 100 3. (obj.x - 100) / 100 = math.cos(math.rad(angle)) 4. math.acos((obj.x - 100) / 100) = math.rad(angle) 5. math.deg(math.acos((obj.x - 100) / 100)) = angle
Should work like this if I understood your question correct.
Unless this is for learning sake, I wouldn’t do these calculations on my own.
There is a 2D math plugin to handle all that:
https://store.coronalabs.com/plugin/math2d
Be sure to activate it before using it.
It is also integrated in SSK if you want to grab the source.