Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript x y平面坐标-查找是上面列表中距离小于或等于半径的点的数量_Javascript - Fatal编程技术网

Javascript x y平面坐标-查找是上面列表中距离小于或等于半径的点的数量

Javascript x y平面坐标-查找是上面列表中距离小于或等于半径的点的数量,javascript,Javascript,您好,我是JavaScript新手,我有一个学校的小项目,我正在努力。我们有一个数据数组集,比如[{x:-33,y:83},{x:81,y:-99},{x:-13,y:-89},{x:13,y:-22},{x:-17,y:55},{x:78,y:-96}, {x:77,y:99},{x:-81,y:27}]。我必须使用这个[公式][1] [1] :要计算它,我们需要找到上面列表中有多少点位于距离用户提供的点小于或等于半径的位置。感谢您的帮助!谢谢我将向您展示一种解决此问题的体面方法,但您需要自己

您好,我是JavaScript新手,我有一个学校的小项目,我正在努力。我们有一个数据数组集,比如[{x:-33,y:83},{x:81,y:-99},{x:-13,y:-89},{x:13,y:-22},{x:-17,y:55},{x:78,y:-96}, {x:77,y:99},{x:-81,y:27}]。我必须使用这个[公式][1]


[1] :要计算它,我们需要找到上面列表中有多少点位于距离用户提供的点小于或等于半径的位置。感谢您的帮助!谢谢

我将向您展示一种解决此问题的体面方法,但您需要自己实现逻辑

var pts = [{x:-33,y:83},{x:81,y:-99},{x:-13,y:-89},{x:13,y:-22},{x:-17,y:55},{x:78,y:-96}, {x:77,y:99},{x:-81,y:27}];

var allowedDistance = 40;
var pt = {x: 0, y: 0}; //the radius point the user provides

let validPts = pts.filter(function (currPt){
    let distance = //use formula here to calculate distance between pt and currPt
    return //return true if the distance is within your allowed distance otherwise false
});

console.log(validPts); //or validPts.length if you just want to know how many points are within allowedDistance

你会被否决,因为你没有提供任何代码,听起来你想让我们帮你做功课。如果你遇到问题,有一个特定的问题,我们可以帮助你,因为你已经有了配方,为什么需要我们的帮助?