Intersecting Lines POJ - 1269(计算几何判断直线位置关系+求直线交点)

82、yolov11检测模型迁移瑞芯微rk3588和使用昇腾设备300i DUO卡推理 batch=1/3,支持昇腾NMS迁移npu推理 本文介绍了使用昇腾设备进行分割推理的测试流程,包括两种测试方式(cann+onnx和om)。首先验证300iDUO卡的可用性,随后创建Docker镜像和容器以搭建独立环境。通过从指定仓库拉取Ubuntu 20.04镜像,创建容器并映射目录。进入容器后安装必要组件(Python3、GCC等)和系统工具(pciutils、net-tools等),为后续模型转换和迁移做准备。整个流程旨在构建可交付给第三方的标准化测试环境。 阅读详情

Intersecting Lines POJ - 1269

We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (i.e. they are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect.
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. All numbers required by this problem will be reasonable, say between -1000 and 1000.

Input
The first line contains an integer N between 1 and 10 describing how many pairs of lines are represented. The next N lines will each contain eight integers. These integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4. Thus each of these input lines represents two lines on the plane: the line through (x1,y1) and (x2,y2) and the line through (x3,y3) and (x4,y4). The point (x1,y1) is always distinct from (x2,y2). Likewise with (x3,y3) and (x4,y4).
Output
There should be N+2 lines of output. The first line of output should read INTERSECTING LINES OUTPUT. There will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: none, line, or point. If the intersection is a point then your program should output the x and y coordinates of the point, correct to two decimal places. The final line of output should read “END OF OUTPUT”.
Sample Input

5
0 0 4 4 0 4 4 0
5 0 7 6 1 0 2 3
5 0 7 6 3 -6 4 -3
2 0 2 27 1 5 18 5
0 3 4 0 1 2 2 5

Sample Output

INTERSECTING LINES OUTPUT
POINT 2.00 2.00
NONE
LINE
POINT 2.00 5.00
POINT 1.07 2.20
END OF OUTPUT
分析:

先判断两条直线是不是同线,不是的话再判断是否平行,再不是的话就只能是相交的,求出交点。

1)如何判断是否同线?

由叉积的原理知道如果p1,p2,p3p1,p2,p3共线的话那么(p2−p1)×(p3−p1)=0(p2−p1)×(p3−p1)=0。因此如果p1,p2,p3p1,p2,p3共线,p1,p2,p4p1,p2,p4共线,那么两条直线共线。求p1p2与p1p3p1p2与p1p3的叉积和p1p2与p1p4p1p2与p1p4的叉积,叉积都为0说明共线。

2)如何判断是否平行?

由向量可以判断出两直线是否平行。如果两直线平行,那么向量p1p2、p3p4p1p2、p3p4也是平行的。即((p1.x−p2.x)(p3.y−p4.y)−(p1.y−p2.y)(p3.x−p4.x))=0((p1.x−p2.x)(p3.y−p4.y)−(p1.y−p2.y)(p3.x−p4.x))=0说明向量平行。

3)如何求出交点?

假设交点为p0=(x0,y0)p0=(x0,y0)

则有:

(p1−p0)×(p2−p0)=0(p1−p0)×(p2−p0)=0

(p3−p0)×(p4−p0)=0(p3−p0)×(p4−p0)=0

展开后得到

(y1−y2)x0+(x2−x1)y0+x1y2−x2y1=0(y1−y2)x0+(x2−x1)y0+x1y2−x2y1=0

(y3−y4)x0+(x4−x3)y0+x3y4−x4y3=0(y3−y4)x0+(x4−x3)y0+x3y4−x4y3=0

相当于解二元一次方程组

a1x+b1y+c1=0a1x+b1y+c1=0

a2x+b2y+c2=0a2x+b2y+c2=0

所以解为

x=c1b2−c2b1a2b1−a1b2x=c1b2−c2b1a2b1−a1b2

y=a2c1−a1c2a1b2−a2b1y=a2c1−a1c2a1b2−a2b1

直接带入即可

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-8;
struct Point{
    double x,y;
};
double isline(Point a,Point b,Point c){
    return (c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x);
}
double isparl(Point a,Point b,Point c,Point d){
    return (b.x - a.x) * (d.y - c.y) - (b.y - a.y) * (d.x - c.x);
}
void solve(Point p1,Point p2,Point p3,Point p4){
    if(isline(p1,p2,p3) == 0 && isline(p1,p2,p4) == 0)
        puts("LINE");
    else if(isparl(p1,p2,p3,p4) == 0)
        puts("NONE");
    else{
        double a1 = p1.y - p2.y;
        double b1 = p2.x - p1.x;
        double c1 = p1.x * p2.y - p2.x * p1.y;
        double a2 = p3.y - p4.y;
        double b2 = p4.x - p3.x;
        double c2 = p3.x * p4.y - p4.x * p3.y;
        double x = (b2 * c1 - b1 * c2) / (b1 * a2 - b2 * a1);
        double y = (a2 * c1 - a1 * c2) / (a1 * b2 - a2 * b1);
        printf("POINT %.2f %.2f\n",x,y);
    }
}
int main(){
    int n;
    Point p1,p2,p3,p4;
    while(scanf("%d",&n) != EOF){
        printf("INTERSECTING LINES OUTPUT\n");
        while(n--){
            scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y,&p3.x,&p3.y,&p4.x,&p4.y);
            solve(p1,p2,p3,p4);
        }
        printf("END OF OUTPUT\n");
    }
    return 0;
}
Windows上MSYS2的安装和使用 MSYS2这个工具我是越用越喜欢,很多东西放在Linux上如鱼得水但是放在Windows上就没那么好用,比如ffmpeg,opencv等直接引用就行了,这个工具真的很省事。接下来带你们看看它的妙用。1、好好研究确实妙用无穷。 阅读详情

相关推荐

算法交易VWAP&TWAP

VWAP的一些算法模型细节参考博客地址http://blog.sina.com.cn/s/blog_ad47bc5b01014elx.html 日内交易量预测模型http://blog.sina.com.cn/s/blog_976461170102v43p.html 算法交易其实主要是用在基金公司、券商量化比较多。例如我已经选好股,要大量买入,但是单凭交易员的操作海量单而且要完

shulixu的博客 1万+

UVA - 378 Intersecting Lines【基础计算几何】

【题目描述】 We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) in...

inv0ker的博客 298

WebRTC音频传输实战:从采集到播放的完整链路解析(附RTP包处理细节)

本文深入解析了WebRTC音频传输的完整链路,从麦克风采集、音频处理与编码,到RTP打包、网络发送,再到接收端的NetEQ抗抖动处理与最终播放。文章以Linux PulseAudio为例,详细剖析了线程模型、缓冲区管理及RTP包处理等关键细节,旨在帮助开发者优化实时音频应用的延迟、卡顿与回声问题。

tea88的博客 858

poj 1269 Intersecting Lines(直线相交)

Intersecting Lines Time Limit:1000MS Memory Limit:10000K Total Submissions:8637 Accepted:3915 Description We all know that a pair of distinct points on a plane defi...

weixin_34293141的博客 250

matlab snr矩阵计算公式_基于MATLAB和Adams的悬置系统解耦计算方法对比

一、概述动力总成悬置系统主要有两个作用:一是固定和支撑动力总成,限制动力总成在各种工况下的位移量,防止与其它部件碰撞;二是隔振作用,将动力总成的振动尽可能少的传递到车身。悬置系统隔振性能的核心就是解决刚体模态的频率分配和振动耦合问题,简言之就是关注动力总成的刚体模态和解耦率。动力总成悬置系统的刚体模态频率和能量解耦分析,行业内的主流计算方法分两种:一是用MATLAB编程进行分析计算,二是...

weixin_33416900的博客 1452

Android11,无障碍服务模拟多手势使用dispatchGesture时总是onCancelled

AccessibilityService的dispatchGesture去模拟多手势,总是onCancelled的一种解决办法

m0_49953943的博客 2117

计算几何 POJ 1269 Intersecting Line

Problem We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) i...

FrankDura的博客 727

对halcon形状匹配算法的一点分析

基于Intel VTune Profiler对halcon形状匹配算法的一点分析

manuoo的专栏 580

15.计算几何:点、直线、线段的位置关系及其它关系

文章目录直线的表示 直线的表示 直线有多种表示方法。编程时,可以灵活使用这些方法:

你说的白是什么白_ 3455

089、NPU的Chiplet设计:多Die互联与封装

本文深入探讨了NPU Chiplet设计中的多Die互联与封装挑战。作者基于实践经验指出,Chiplet技术虽能突破单芯片算力限制,但面临协议死锁、信号完整性、电源完整性等复杂问题。文章比较了UCIe/BoW等互联协议优劣,分析了硅中介层与EMIB封装方案的取舍,并强调协议轻量化设计的重要性。通过真实案例(如第47层卷积死锁问题)说明credit机制等关键技术细节,给出均衡器优化、调试端口预留等实用建议。最后提出五项核心经验:避免过度依赖标准协议、重视测试点预留、做好电源仿真、优化热管理、建立故障模型,为高

m0_50546716的博客 130

POJ 1269 Intersecting Lines(判断两直线的位置关系)

Intersecting Lines Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection beca

Spectacules的博客 746

《AgentScope-Java 深入浅出教程》第2章 环境搭建与第一个智能体

创建// 【导入说明】/*** 时间相关工具类* 工具类是普通的 Java 类,通过注解声明为工具。* 智能体可以根据用户需求自动调用这些工具。*/// 【工具定义】获取当前时间@Tool(name = "get_current_time", // 工具名称:LLM 看到的名称description = "获取指定时区的当前时间" // 工具描述:帮助 LLM 理解何时使用// 【参数定义】// @ToolParam 的 name 属性是必需的!

步子哥的博客 431

POJ 1269 Intersecting Lines

POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection...

旺崽的博客 2824

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

判断两条直线的位置关系 POJ 1269 Intersecting Lines

两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交。 那给定两条直线怎么判断他们的位置关系呢。还是用到向量的叉积 例题:POJ1269 题意:这道题是给定四个点p1, p2, p3, p4,直线L1,L2分别穿过前两个和后两个点。来判断直线L1和L2的关系 这三种关系一个一个来看: 1. 共线。 如果两条直线共线的话,那么另外一条直线上的点一定在这...

dizhuo0219的博客 469

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

ACM-计算几何之Intersecting Lines——poj1269

ACM 计算几何 Intersecting Lines poj1269

继续激情,继续奋斗。 2354

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

poj 1269 Intersecting Lines(两直线交点)

http://poj.org/problem?id=1269 Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13425   Accepted: 5977 Description We all know that

大太阳 679

Intersecting Lines(直线相交判断,求相交交点)

Link:http://poj.org/problem?id=1269 Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12491   Accepted: 5576 Description We

林下的码路 2724

POJ 1269 Intersecting Lines (两直线位置关系+求交点)

题意:给出两直线位置,求是平行、重合还是有交点,若有交点,输出。 题解:两直线位置关系+求交点 套板子。 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<queue> #include<stack> #inclu

gongyuandaye的博客 236

【计算几何】【直线交点】Intersecting Lines

POJ 1269 至今不明白为什么POJ中把G++改成C++就对了 题目: 求两直线的关系,若相交求其交点 题解: #include<cstdio> #include<cmath> #include<string.h> #include<iostream> using namespace std; const int N=1e3+10; const ...

ygmjsjdboy的博客 252

POJ 1269 Intersecting Lines(简单计算几何 · 直线与直线的位置关系)

一、传送门 http://poj.org/problem?id=1269 二、算法分析说明 三、代码 #include<cstdio> #include<cmath> #pragma warning(disable:4996) template<class _Ty> struct point { _Ty x, y; }; unsigned n; point&l...

COFACTOR 244

【计算几何】POJ 1269 Intersecting Lines

POJ 1269 Intersecting Lines【传送门】 Intersecting Lines Time Limit:1000MS Memory Limit:10000K Total Submissions:20497 Accepted:8658 Description We all know that a pair of disti...

lesileqin的博客 222

Intersecting Lines POJ 1269(计算几何+判断直线间关系+求直线的交点)

Intersecting LinesPOJ - 1269 We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersectio...

勉強しているユキさんです 597

POJ 1269 Intersecting Lines (判断直线位置关系)

题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection...

G19850917的博客 268

直线与直线的关系判断、求交点:POJ1269

POJ1269 题解 两直线ab和cd平行:ab×cd = 0 两直线重合:在平行的基础上满足ac×ad = 0 否则求交点。 代码 #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #i...

FlyingJack 280

POJ_1269_Intersecting Lines_求直线交点

POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no...

149
上一篇: Segments POJ - 3304(计算几何基础判断两直线相交)
下一篇: Alphabetic Removals(思维+模拟)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址