连接两个线段 [英] Connect two Line Segments

查看:107
本文介绍了连接两个线段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定两条二维线段A和B,我如何计算连接A和B的最短二维线段C的长度?

解决方案

考虑你的两条线段A和B分别由两个点表示:

line A表示为A1(x,y) ,A2(x,y)

由B1(x,y)B2(x,y)表示的行B

首先检查两条线是否使用此算法相交。



如果它们相交,那么两条线之间的距离为零,连接它们的线段就是交点。 p>

如果它们不相交,请使用此方法: http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/ 计算最短距离:


  1. A1点和B点

  2. A2点和B点
  3. 点B1和A线
  4. 点B2和线A

这四条线段中最短的线段是你的答案。


Given two 2D line segments, A and B, how do I calculate the length of the shortest 2D line segment, C, which connects A and B?

解决方案

Consider your two line segments A and B to be represented by two points each:

line A represented by A1(x,y), A2(x,y)

Line B represented by B1(x,y) B2(x,y)

First check if the two lines intersect using this algorithm.

If they do intersect, then the distance between the two lines is zero, and the line segment joining them is the intersection point.

If they do not intersect, Use this method: http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/ to calculate the shortest distance between:

  1. point A1 and line B
  2. Point A2 and line B
  3. Point B1 and line A
  4. Point B2 and line A

The shortest of those four line segments is your answer.

这篇关于连接两个线段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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