2012-10-10 17 views

回答

1

从您给出的描述中,我认为您正在寻找距离公式。

Sqrt((y2-y1)^2 + (x2-x1)^2)

例如:

你有一个半径限定和点的阵列:

var radius:int = 20; 
var myDots = new Array ({'x':0, 'y': 0}, {'x': 5, 'y': 5}, {'x': 10, 'y': 5}, {'x': 10, 'y': 5}, {'x': 10, 'y': 10}); 

被点击的点是(5,5)并且假设有一个确定半径r = 20。 现在,把所有的点withing半径r,由点迭代:

function getDotsWithinRadius(x,y){ 
     for(var i= 0; i<myDots.length;i++){ 
      var x2 = myDots[i].x; 
      var y2 = myDots[i].y; 
      var val = Math.sqrt(Math.pow(y2-y,2) + Math.pow(x2-x, 2)); 
      if(val <=radious){ 
       /*The dot is with the radius of the give location. 
       This is the place where you tell the current dot to show up or 
       something like that. 
       */ 
      } 
     } 
    } 

我没有测试的代码,但我真的希望这给你的理解。

+0

谢谢,我用距离公式来解决这个问题。但忘了发布答案。谢谢你的时间。 – justnajm

相关问题