当前位置:网站首页>Calculation of intersection of two line segments
Calculation of intersection of two line segments
2022-07-01 18:26:00 【zjjxFPGAer】
problem
Known line segments P1P2 and Q1Q2, Determine whether they have intersections , If you have any , Find the intersection point .
1. Judge whether line segments intersect
Pictured , Judge whether line segments intersect , It can be carried out through a series of experiments .
Rapid rejection experiment
If the P1P2 and Q1Q2 Rectangles that are diagonal do not intersect , be P1P2 It must not intersect
Only when
min(p1.x,p2.x) <= max(q1.x,q2.x)
min(q1.x,q2.x) <= max(p1.x,p2.x)
min(p1.y,p2.y) <= max(q1.y,q2.y)
min(q1.y,q2.y) <= max(p1.y,p2.y)
When all four formulas are satisfied , Two line segments can intersect , Otherwise, it will not intersect . This is Rapid rejection experiment .
Straddle experiment
According to the picture above , Even after passing the rapid rejection experiment , Two straight lines do not necessarily intersect , therefore , We need to further pass the so-called Straddle experiment Judge .
For this part, please refer to link
2. Calculation of intersection of line segments
set up P 1 ( x 1 , y 1 ) , P 2 ( x 2 , y 2 ) , Q 1 ( x 3 , y 3 ) , Q 2 ( x 4 , y 4 ) P_1(x_1,y_1),P_2(x_2,y_2),Q_1(x_3,y_3),Q_2(x_4,y_4) P1(x1,y1),P2(x2,y2),Q1(x3,y3),Q2(x4,y4), be P 1 P 2 P_1P_2 P1P2 and Q 1 Q 2 Q_1Q_2 Q1Q2 The intersection of is calculated as follows :
The reason why I think the straddle experiment is of little significance , It is because there is no great difference between the calculation of the straddle experiment and that of the direct calculation of the intersection , We can calculate the intersection of straight lines directly , Then judge whether the intersection is on the line segment , The criteria for judgment are as follows :
m a x ( x 1 , x 2 ) ≥ x o ≥ m i n ( x 1 , x 2 ) max(x_1,x_2)\ge x_o\ge min(x_1,x_2) max(x1,x2)≥xo≥min(x1,x2) m a x ( x 3 , x 4 ) ≥ x o ≥ m i n ( x 3 , x 4 ) max(x_3,x_4)\ge x_o\ge min(x_3,x_4) max(x3,x4)≥xo≥min(x3,x4)
边栏推荐
- Is the software of futures pioneer formal and safe? Which futures company is safer to choose?
- Subnet division and summary
- What are the legal risks of NFT brought by stars such as curry and O'Neill?
- The new server is packaged with the source code of H5 mall with an operation level value of several thousand
- 徽商期货是正规期货平台吗?在徽商期货开户安全吗?
- Gold, silver and four job hopping, interview questions are prepared, and Ali becomes the champion
- About selenium element positioning being overwritten
- Relationship between sensor size, pixel, dpi resolution, inch and millimeter
- Computer network interview assault
- Data query language (DQL)
猜你喜欢
Intel's open source deep learning tool library openvino will increase cooperation with local software and hardware parties and continue to open
This is the latest opportunity of the London bank trend
Mujoco's biped robot Darwin model
Thinkphp6 - CMS multi wechat management system source code
The method of real-time tracking the current price of London Silver
Samba basic usage
LeetCode 148. Sort linked list
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
Mysql database design
随机推荐
540. Single element in ordered array
[C supplement] [string] display the schedule of a month by date
transform. Forward and vector3 Differences in the use of forward
目前炒期货在哪里开户最正规安全?怎么期货开户?
Redis主从实现10秒检查与恢复
Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
Batch export all pictures in PPT in one second
传感器尺寸、像素、DPI分辨率、英寸、毫米的关系
Set the style of QT property sheet control
SLO is increasingly used to achieve observability | Devops
Penetration practice vulnhub range Tornado
Penetration practice vulnhub range Nemesis
Review Net 20th anniversary development and 51aspx growth
June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries
Wechat applet blind box - docking wechat payment
Xia CaoJun ffmpeg 4.3 audio and video foundation to engineering application
golang中的select详解
DRF --- response rewrite
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Convert the robot's URDF file to mujoco model