# Math

**URL:** <https://forum.kirupa.com/t/math/273559>\
**Category:** Uncategorized\
**Created:** [October 16, 2008, 9:46pm UTC](https://forum.kirupa.com/t/math/273559 "2008-10-16T21:46:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenBart](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@BenBart](https://forum.kirupa.com/u/BenBart)\
**Post date:** [October 16, 2008, 9:46pm UTC](https://forum.kirupa.com/t/math/273559/1 "2008-10-16T21:46:29Z")

</div>

I’m trying to make a movieclip push out from the center of the stage, but I’m having a problem with the math.

I made an function, but it pushes out in a diamond shape.

```auto
function newCords(newX:Number, newY:Number, distance){
    var centerX = Stage.width/2;
    var centerY = Stage.height/2;
    var slope;
    newX-=centerX;
    newY-=centerY;
    
    if(newX>0 && newY>0){
        slope = (newY)/(newX);
        
        trace("Slope: "+slope);
        newX = distance/(Math.sqrt(1+slope));
        newY = slope * newX;
    
        newX+=centerX;
        newY+=centerY;
    }else{
        
        if(newX<0 && newY<0){
            slope = (newY)/(newX);
            newX = distance/(Math.sqrt(1+slope));
            newY = slope * newX;

            
        newX= centerX-newX;
        newY= centerY-newY;
        trace(newX);
        
        }else{
            slope = -(newY)/(newX);
                if(newY<0){        
                     newX = distance/(Math.sqrt(1+slope));
                    newY = slope * newX;
                    newY = -newY;
                }
        
                if(newX<0){
                    newX = distance/(Math.sqrt(1+slope));
                    newY = slope * newX;
                    newX = -newX;
                }
            newX+=centerX;
            newY+=centerY;
        }
    }
    
    return ([newX, newY]);
}
////// to test the function... you will see that it moves in a diamond shape
point1.onEnterFrame = function(){
centerPoint._x = Stage.width/2;
centerPoint._y = Stage.height/2;
var tempArray = newCords(point1._x,point1._y, 100);
point2._x = tempArray[0];
point2._y = tempArray[1];

}

point1.onMouseDown = function(){
    startDrag(this);
trace("click");

}

point1.onMouseUp = function(){
    stopDrag();
trace("click");

}

```
