如何从节点js中的另一个xy vlaue中找到xy坐标值?

时间:2018-08-20 10:00:59

标签: javascript node.js image-processing canvas

我检测到汽车图像以获得x,y像素值。现在,我需要从90度中找到另一个x,y像素值。 尝试了一些方法,但是没有用:

 exports.strokeLine=(request, response)=>{

function lineDistance( point1, point2 ){
    var xs = 0;
    var ys = 0;

    xs = point2.x - point1.x;
    xs = xs * xs;

    ys = point2.y - point1.y;
    ys = ys * ys;

    return Math.sqrt( xs + ys );
}

// var pos = lineDistance(206.543869972229, 204.03305053710938);
var pos2 = lineDistance(206.543869972229, 204.03305053710938 );

//show result of end point
 console.log(pos2);

 }

1 个答案:

答案 0 :(得分:0)

您编写lineDistance函数的方式需要两个{ x: Number, y: Number }形式的参数,所以两个点对象分别具有一个x和一个y坐标。由于您仅在示例中传递了两个数字,因此无法使用。

有关工作示例,请参见下文:

function lineDistance( point1, point2 ){
    let xs = point2.x - point1.x;
    xs = xs * xs;

    let ys = point2.y - point1.y;
    ys = ys * ys;

    return Math.sqrt( xs + ys );
}


const pos = lineDistance({x : 206.54, y: 300.76}, {x : 204.03, y: 505.37});

document.querySelector(".distance").textContent = pos;
<p class="distance"></p>