我画了两点A(x,y)--- B(x,y)之间的一条线现在我有第三个点C(x,y).我想知道如果C位于A和B之间的线上.我想用java语言来做.我找到了几个类似的答案.但是,都有一些问题,没有人是完美的.
我有由两个点A(x1,y1,z1)和B(x2,y2,z2)和点p(x,y,z)定义的线段.如何检查该点是否位于线段上?
我该怎么写这个函数?任何例子都赞赏
function isPointBetweenPoints(currPoint, point1, point2):Boolean {
var currX = currPoint.x;
var currY = currPoint.y;
var p1X = point1.x;
var p1y = point1.y;
var p2X = point2.x;
var p2y = point2.y;
//here I'm stuck
}
Run Code Online (Sandbox Code Playgroud) 这类似于这个问题,但恰恰相反.
我有两个地理点(纬度,经度)A和B.假设他们相距40海里.我想计算A点和B点之间A点10海里点的坐标.我确定这是非常基本的数学,但是因为我不得不这样做了数学(我每天使用的其他一些种类),所以我被卡住了.任何指针都将非常感激.我的这个项目的代码是用Python编写的,但是数学不是特定于语言的,所以我并不是真正关心它 - 我只是想知道这个公式.
我有一个点-i,我希望创建一个函数来知道该点是否位于多边形的边界上。
使用:
def point_inside_polygon(x, y, poly):
"""Deciding if a point is inside (True, False otherwise) a polygon,
where poly is a list of pairs (x,y) containing the coordinates
of the polygon's vertices. The algorithm is called the 'Ray Casting Method'"""
n = len(poly)
inside = False
p1x, p1y = poly[0]
for i in range(n):
p2x, p2y = poly[i % n]
if y > min(p1y, p2y):
if y <= max(p1y, p2y):
if x <= max(p1x, p2x):
if p1y != p2y:
xinters …Run Code Online (Sandbox Code Playgroud) 我试图使用shapely的'within'函数来做一个Linestring和一个点文件的'空间连接'(fyi - 点文件是使用线串上的插值函数生成的).问题是 - 什么都没有归还.
我错过了什么?
# this condition is never satisfied
if point.within(line):
# here I write stuff to a file
Run Code Online (Sandbox Code Playgroud)
和
point = POINT (-9763788.9782693591000000 5488878.3678984242000000)
line = LINESTRING (-9765787.998118492 5488940.974948905, -9748582.801636808 5488402.127570709)
Run Code Online (Sandbox Code Playgroud) 我想确定是否在点之间进行了点击,并且大致是在连接这两点的线段上进行了点击.
我的问题类似于如何确定线段上两个点之间的点?但它推迟了两点:
以下代码改编自这个答案,但我不知道如何在线段周围插入公差
a并且b是线段的终点,c是点击的点.我想检查是否c在连接和之间的段之间a和之间bab
PencilTool.prototype._isBetween = function(a,b,c){
//test if a, b and c are aligned
var crossproduct = (c.y - a.y) * (b.x - a.x) - (c.x - a.x) * (b.y - a.y);
if(Math.abs(crossproduct) !== 0){ return false; }
var dotproduct = (c.x - a.x) * (b.x - a.x) + (c.y - a.y)*(b.y - a.y)
if(dotproduct < 0){ return false }
var …Run Code Online (Sandbox Code Playgroud) 我想确定鼠标点击点是否位于SVG折线上.我找到了这个Python代码来确定一个点是否位于另外两个点之间,并在JavaScript中重新实现它.
function isOnLine(xp, yp, x1, y1, x2, y2){
var p = new Point(x, y);
var epsilon = 0.01;
var crossProduct = (yp - y1) * (x2 - x1) - (xp - x1) * (y2 - y1);
if(Math.abs(crossProduct) > epsilon)
return false;
var dotProduct = (xp - x1) * (x2 - x1) + (yp - y1)*(y2 - y1);
if(dotProduct < 0)
return false;
var squaredLengthBA = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
if(dotProduct > …Run Code Online (Sandbox Code Playgroud) 
我的程序中目前有以下行。我还有另外两个整数变量,x和y。
我想看看这个新点是否(x, y)在这条线上。我一直在看以下主题:
我想出了以下几点:
if(x >= x1 && x <= x2 && (y >= y1 && y <= y2 || y <= y1 && y >= y2))
{
float vx = x2 - x1;
float vy = y2 - y1;
float mag = sqrt(vx*vx + vy*vy);
// need to get the unit vector (direction)
float dvx = vx/mag; // this would be the unit vector (direction) x for the line
float dvy = …Run Code Online (Sandbox Code Playgroud)