dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Calculate the angle between 2 movie clips

  1. #1
    Junior Member
    Join Date
    Apr 2006
    Posts
    19

    Calculate the angle between 2 movie clips

    Hi guys!
    How can I calculate the angle made by 2 movie clips. Each one representing a line.
    Thanks,

  2. #2
    Qwaizang:syntax_entity_ Q__Hybrid's Avatar
    Join Date
    Aug 2005
    Posts
    270
    use this:
    Code:
    // pass references to your movieclips using vectorInputN
    // NOTE: the angle returned depends on relationship of vectorInputs!
    
    function solveAngle(	vectorInput1:Object,
    			vectorInput2:Object,
    			convertToDegrees:Boolean):Number {
    
    	var nOutput:Number = null;
    
    	var opp:Number = -(vectorInput2._y - vectorInput1._y);
    	var adj:Number =   vectorInput2._x - vectorInput1._x;
    
    	nOutput = 	(convertToDegrees) ?
    			Math.atan2(opp, adj) * (180 / Math.PI) :
    			Math.atan2(opp, adj);
    
    	return nOutput;
    }
    +Q__
    Qwaizang \kw-'zan\ n [origin unknown] 1 : abstract designer, esp. of complex real-time experiments, c. 21st century

  3. #3
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    nice code

  4. #4
    Junior Member
    Join Date
    Apr 2006
    Posts
    19
    Thanks Q__Hybrid ! I'm really grateful!

  5. #5
    Member
    Join Date
    Jul 2005
    Posts
    36
    angle = Math.Atan2(movieClip1._y - movieClip2._y, movieClip1._x - movieClip2._x)*180/Math.PI

  6. #6
    Advance Motion Management
    Join Date
    Mar 2006
    Location
    India
    Posts
    84
    the angle returned depends on relationship of vectorInputs


    --
    Vini
    Its in my Blood, B+



  7. #7
    brunocfer
    Join Date
    Jul 2006
    Location
    So Paulo, Brasil
    Posts
    1
    For future refernce : "atan2" not Atan2

    angle = Math.atan2(movieClip1._y - movieClip2._y, movieClip1._x - movieClip2._x)*180/Math.PI

    Lame first post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center