我有两个同心圆,其中心位于(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度圆圈的外部点。
感谢。
答案 0 :(得分:0)
我认为你在这里是触发器,你不应该将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)不在边界框中