当前位置:网站首页>Find the intersection of line segments
Find the intersection of line segments
2022-07-03 08:26:00 【T.D.C】
Find the intersection of line segments
- Copy the :https://www.geeksforgeeks.org/program-for-point-of-intersection-of-two-lines/
public struct Point{
public double x;
public double y;
public Point(double x, double y){
this.x = x;
this.y = y;
}
public static Point lineLineIntersection(Point A, Point B, Point C, Point D)
{
// Line AB represented as a1x + b1y = c1
double a1 = B.y - A.y;
double b1 = A.x - B.x;
double c1 = a1 * (A.x) + b1 * (A.y);
// Line CD represented as a2x + b2y = c2
double a2 = D.y - C.y;
double b2 = C.x - D.x;
double c2 = a2 * (C.x) + b2 * (C.y);
double determinant = a1 * b2 - a2 * b1;
if (determinant == 0)
{
// The lines are parallel. This is simplified
// by returning a pair of FLT_MAX
return new Point(double.MaxValue, double.MaxValue);
}
else
{
double x = (b2 * c1 - b1 * c2) / determinant;
double y = (a1 * c2 - a2 * c1) / determinant;
return new Point(x, y);
}
}
}
边栏推荐
猜你喜欢

jupyter远程服务器配置以及服务器开机自启

animation

Introduction to Base64 coding

數據庫應用技術課程設計之商城管理系統

Basic operation and process control 2

L'installateur a été installé avec une erreur inattendue

Vscode, idea, VIM development tool shortcut keys
![[cloud native] introduction and use of feign of microservices](/img/39/05cf7673155954c90e75a8a2eecd96.jpg)
[cloud native] introduction and use of feign of microservices

Dealing with duplicate data in Excel with xlwings

【云原生】微服务之Feign的介绍与使用
随机推荐
swagger文档配置
GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
Golang's range
What does (+) in Oracle mean
P1896 [scoi2005] non aggression (shape pressure DP)
Osgearth north arrow display
Base64 and base64url
数据分析练习题
C#课程设计之学生教务管理系统
matlab神經網絡所有傳遞函數(激活函數)公式詳解
Redis cluster series 4
Visual Studio (VS) shortcut keys
Map的实现类的顺序性
Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)
Golang json格式和结构体相互转换
Jupyter remote server configuration and server startup
Creation and content of mapnode -- osgearth rendering engine series (2)
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
Golang中删除字符串的最后一个字符
Transplantation of freetype Library