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

RT-Thread网络编程:基于STM32F407的TCP客户端实现(含完整代码解析) 本文详细介绍了在STM32F407平台上,基于RT-Thread操作系统和LWIP协议栈实现工业级可靠TCP客户端的完整过程。内容涵盖底层ETH驱动配置、Socket编程、连接保活与断线重连机制、数据收发协议设计以及资源管理,提供了可应用于实际项目的健壮代码框架与调试技巧。 阅读详情

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;
}
《深入浅出多模态》(二):多模态任务及数据集介绍 本文为《深入浅出多模态》系列第二章,《多模态任务介绍与背景》主要介绍多模态模型的概念、技术难点、下游任务(Visual Grounding、VQA、image/Video Captioning等)及各类应用方向数据集展开介绍,本专栏适合从事多模态小白及爱好者学习,欢迎大家关注,如有侵权请联系删除! 阅读详情

相关推荐

Type-c超声波切割刀

接下来,我将提供Type-C超声波切割刀项目的C代码实现示例,代码将按照上述分层架构和模块化设计进行组织。为了达到3000行以上的代码量,我将尽可能详细地实现各个模块的功能,并添加必要的注释和错误处理。通过采用分层架构和模块化设计,我们可以建立一个可靠、高效、可扩展的系统平台,为产品的成功奠定坚实的基础。实际项目中,需要更详细的硬件驱动、更完善的功能模块、更严格的测试验证和更周全的维护升级计划。针对Type-C超声波切割刀这个项目,我将从以下几个方面详细阐述最适合的代码设计架构,并提供具体的C代码实现。

lianmengde的博客 1188

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

DeepSeek如何构建可扩展的 AI 驱动交易系统,基于 MetaTrader 5 与 Python 利用先进的数据处理、机器学习和容器化部署来优化算法交易。

MT5 Python API 架构设计分为三层:通信层:利用异步消息传递(例如 ZeroMQ 或标准套接字编程)支持每秒数万个数据请求。转换层: C++ 动态库有效地将 MT5 命令转换为 Python 对象(反之亦然),从而优化速度和内存使用率。接口层:提供Pythonic API,封装了所有终端功能,包括:1)实时价格订阅(滴答或秒级更新)2)历史数据检索(从M1到更高的时间范围)3)订单流监控(交易详情和市场深度)4)策略执行引擎(用于算法交易)

iCloudEnd的博客 1379

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

带有HSE组件的S32系列芯片中各子系统如何依次启动?

仔细阐述了上电后各个子系统的启动顺序,并给出了详细的启动步骤流程图。

车载系统攻城狮 1700

python利用IQR方法与3σ方法进行异常值处理(含代码)

python利用IQR方法进行异常值处理

weixin_46713695的博客 2031

计算几何 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的博客 721

如何让C++程序生成dump文件?生成dump文件的方式有哪些?如何使用Windbg分析dump文件?

本文详细介绍了如何让C++程序生成dump文件、生成dump文件的多种方式以及如何使用Windbg分析dump文件,并给出了对应的实战分析案例,有一定的实战参考价值。

dvlinker的技术专栏 5万+

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

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

你说的白是什么白_ 3442

Google Cameraserver 看门狗CameraServiceWatchdog超时crash原理分析

本文分析了Android CameraServiceWatchdog机制的工作原理。该看门狗用于监控相机服务关键操作(如close、flush)的超时情况,通过定时器线程检测阻塞问题。文章详细讲解了Watchdog的初始化流程、使能方式、内部定时器机制(默认周期100ms,650次循环触发超时),并提供了configureStreams阶段的客制化实现方案。当检测到超时,Watchdog会触发abort生成tombstone日志,便于调试分析。

1129

SAP BOM反查(可追溯值至顶级)

功能介绍:BOM层数在7层以内的(含7层)的物料,执行后都可以查询到顶级的BOM,逻辑很简单,后期如BOM层数增加,可自行增加查询逻辑。 *&---------------------------------------------------------------------* *& Report ZBOM_CHECK *&---------------------...

SAP阿狸 6059

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的博客 745

ASM准入小助手卸载没有密码的方法:读取明文密码2024年7月有效

在一次工作过程中,电脑中意外的安装了一个ASM准入小助手软件,工作结束以后回来发现没有卸载,然后就决定把它卸载掉,但是居然给了我一个大大的提示框:由于联系不到当时给我安装的那个人了,所以一时陷入了焦灼的状态,因为我安装另一个终端准入,会直接提示冲突了。所以经过注册表(regedit)、任务管理器等各种折腾之后,最后都失败了,然后想起了多年前在吾爱论坛学到过的东西,最后意外的找到了密码,然后就完美成功卸载了。

布啦啦 7802

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...

旺崽的博客 2821

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

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

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

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

dizhuo0219的博客 468

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

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

ACM 计算几何 Intersecting Lines poj1269

继续激情,继续奋斗。 2351

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

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

大太阳 675

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

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

林下的码路 2722

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的博客 235

【计算几何】【直线交点】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 243

【计算几何】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的博客 220

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...

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

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的博客 265

直线与直线的关系判断、求交点: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...

148
上一篇: 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、付费专栏及课程。

余额充值