【问题标题】:how to find xy coordinates value from another xy vlaue in node js?如何从节点 js 中的另一个 xy 值中找到 xy 坐标值?
【发布时间】:2019-01-26 10:32:43
【问题描述】:

我已检测汽车图像以获取 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);

 }

【问题讨论】:

    标签: javascript node.js image-processing canvas


    【解决方案1】:

    您编写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>

    【讨论】:

    • 感谢回复.. 如何通过给出两个数字和角度来获取像素?
    • 我不太确定你想要什么......通过上面的修复,你可以计算两点之间的euclidean distance。我假设这就是您根据代码所需要的。但如果你想找到一个新的点,那就完全不同了。那个点应该在哪里?如果您只有一个不足以找到新坐标角度,那么您还需要一个距离。也许看看polar coordinate system
    猜你喜欢
    • 2017-11-18
    • 2018-09-11
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多