Hi Everyone.
What is the easiest way to calculate an angle?
I have three sprites on the stage. The first even (through mySprite and
A_Sprite)
and the second even (through mySprite and B_Sprite) form an angle at
mySprite.
I want to calculate that angle in degrees. The point of origin is on the
left bottom
of the stage. Division by zero isn´t solved yet.
Any help is very welcome.

regards
rAlf.

property stageWidth
property stageHeight
property A_Sprite
property B_Sprite
property mySprite
property xA, yA, xB, yB, xP, yP -- coordinates
property m1, m2 -- inclination of the even
property angleRad
property angleDeg

on beginSprite me
  A_Sprite = sprite(15)
  B_Sprite = sprite(16)
  mySprite = sprite(me.spriteNum)
  stageWidth  = the stageRight - the stageLeft
  stageHeight = the stageBottom - the stageTop
  the floatPrecision = 4
end beginSprite me

on prepareFrame me
  xA = A_Sprite.locH.float
  yA = (stageHeight - A_Sprite.locV).float -- point of origin is on the
left bottom of the stage.
  xB = B_Sprite.locH.float
  yB = (stageHeight - B_Sprite.locV).float
  xP = mySprite.locH.float
  yP = (stageHeight - mySprite.locV).float
  m1 = (yA - yP) / (xA - xP)
  m2 = (yB - yP) / (xB - xP)
  angleRad = (m2-m1) / (m1*m2 +1).atan
  angleDeg = angleRad * 180 / pi -- convert from RAD to DEG.
  put angleRad into member("angleRad")
  put angleDeg into member("angleDeg")
end prepareFrame me



[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to