检查线的两点之间是否存在坐标 [英] check coordinate exists between two points of line

查看:75
本文介绍了检查线的两点之间是否存在坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两点,假设x1,y1和x2,y2。
和我还有一个点x 3,y 3,
这是问题,我需要检查x 3,y 3坐标是否出现在x 1,y 1和x 2,y 2之间的线中或是否不在javascript中。

I have two points, lets say x1,y1 and x2,y2. and i have one more point x3,y3, here is the question, i need to check is x3,y3 coordinate occurs in the line between x1,y1 and x2,y2 or not occurs in javascript.

预先感谢。

推荐答案

尝试一下:

var point_a = [0, 0];
var point_b = [100, 200];
var coord = [50, 100];

function checkCoordinate(coord) {
    var slope = (point_b[1] - point_a[1]) / (point_b[0] - point_a[0]);
    var newSlope = (point_b[1] - coord[1]) / (point_b[0] - coord[0]);
    if (coord[0] > point_a[0] && coord[0] < point_b[0] && coord[1] > point_a[1] && coord[1] < point_b[1] && slope == newSlope) {
        alert('Yes! they are in the same line.');
    } else {
        alert('No :/');
    }
}
checkCoordinate(coord);

这篇关于检查线的两点之间是否存在坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆