在动作脚本中找到同心圆上的一个点

| 我有两个同心圆,其中心在(centerX,centerY)。内圆的半径为100,外圆的半径为400。如果在内圆的圆周上取一个点,我可以从中心到该点画一条线。让我们称该点为x1,y1)。现在,我想将该半径延伸到外部同心圆并计算该外部点(x2,y2)的位置。 我添加一个3px \'点\'只是为了显示x1,y1在屏幕上的位置。 (子问题:我看不到...不知道为什么。) 这是我正在尝试的:
    var x1:Number = 100;
    var y1:Number = 50;
    var x2:Number;
    var y2:Number;
    var centerX:Number = 200;
    var centerY:Number = 200;

    var myAngle:Number = Math.atan2(y1 - centerY, x1-centerX);
    //x2 = x1 + 300 * Math.cos(myAngle);
    //y2 = y1 + 300 * Math.sin(myAngle);
    x2 = centerX + Math.cos(myAngle) * 400;
    y2 = centerY + Math.sin(myAngle) * 400;
    trace(\"x2,y2 = \" + x2 + \",\" + y2);

    var myCenterPoint:Sprite = new Sprite();
    this.graphics.lineStyle(3,0x00ff00); //green, center point
    this.graphics.moveTo(centerX, centerY);
    graphics.drawCircle(centerX,centerY,5);
    addChild(myCenterPoint);

    var myInnerCirclePointMarker:Sprite = new Sprite();
    this.graphics.lineStyle(3,0x0000FF); //blue, inner circle circumf. marker
    this.graphics.moveTo(x1, y1);
    graphics.drawCircle(x1,y1,5);
    addChild(myInnerCirclePointMarker);

    trace(\"x2,y2 = \" + x2 + \",\" + y2);
    var myOuterCirclePointMarker:Sprite = new Sprite();
    this.graphics.lineStyle(3,0xff0000); //red, outer circle circumf. marker
    myOuterCirclePointMarker.graphics.drawCircle(x2,y2,5);
    addChild(myOuterCirclePointMarker);

            this.graphics.moveTo(centerX, centerY);
            this.graphics.lineTo(x2, y2);    //draw line, which should go through 
                                             //x1,y1 and end at x2,y2
我认为这不会正确地向我显示圆的所有360度的外部点。 谢谢。     
已邀请:
        我认为您不在这里,不应该将sin / cos值乘以300。您想从圆心(centerX,centerY)到x2,y2(外圆)画一条线,但您使用x1,y1作为圆心。 x2,y2应该从圆心而不是x1,y1计算;尝试这个
var myAngle:Number = Math.atan2(y1 - centerY, x1 - centerX);
x2 = centerX + Math.cos(myAngle) * 400;
y2 = centerY + Math.sin(myAngle) * 400;
var myCircle:Sprite = new Sprite();

this.graphics.lineStyle(3,0x00ff00);
this.graphics.moveTo(centerX, centerY);
this.graphics.lineTo(x2, y2);

myCircle.graphics.drawCircle(x1,y1,5);
addChild(myCircle);
您的x1,y1圆不出现的原因是它不在内圆上,内圆的边界框为(100,100),(300,300),即(100,50)不在圆内边界框。     

要回复问题请先登录注册