当前位置:网站首页>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)
边栏推荐
- Sword finger offer II 105 Maximum area of the island
- What is web application security testing technology?
- Convert the robot's URDF file to mujoco model
- t10_ Adapting to Market Participantsand Conditions
- Mujoco model learning record
- Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
- Smart factory digital management system software platform
- Vue uses keep alive to cache page optimization projects
- [beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
- Function, condition, regular expression
猜你喜欢

How to write good code - Defensive Programming Guide

New 95 community system whole station source code

2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers

Heavy disclosure! Hundreds of important information systems have been invaded, and the host has become a key attack target

Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?

Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"

Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)

Yuancosmos game farmersworld farmers world - core content of the second conference in China!

Classpath classpath

【Try to Hack】vulnhub DC4
随机推荐
[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
Is online stock account opening safe? Is it reliable?
Heavy disclosure! Hundreds of important information systems have been invaded, and the host has become a key attack target
Is the software of futures pioneer formal and safe? Which futures company is safer to choose?
Yuancosmos game farmersworld farmers world - core content of the second conference in China!
Debiasing word embeddings | talking about word embedding and deviation removal # yyds dry goods inventory #
Bug of QQ browser article comment: the commentator is wrong
期货账户的资金安全吗?怎么开户?
Set the style of QT property sheet control
PIP version problems: PIP problems still occur when installing akshare and using Tsinghua source and Douban source
Check log4j problems using stain analysis
Redis master-slave realizes 10 second check and recovery
Extract the compressed package file and retrieve the password
Euler function: find the number of numbers less than or equal to N and coprime with n
Happy new year | 202112 monthly summary
Oracle TRUNC function processing date format
2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
MySQL -- explain performance optimization
[PHP foundation] realize the connection between PHP and SQL database