当前位置:网站首页>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);
}
}
}
边栏推荐
猜你喜欢
GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
Shader foundation 01
Get to know unity2 for the first time
Storage of data
Oracle insert single quotation mark
Vscode, idea, VIM development tool shortcut keys
Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template
数据的存储
VIM learning notes from introduction to silk skating
Abstract classes and interfaces
随机推荐
Scite change background color
Display terrain database on osgearth ball
Cesium service deployment, and import and display local 3dfiles data
Osgearth target selection
简易入手《SOM神经网络》的本质与原理
E: Unable to locate package ROS melody desktop full
Haproxy+kept build 01
Installation of PHP FPM software +openresty cache construction
C language - Introduction - essence Edition - take you into programming (I)
MySQL 8
redis集群系列四
Youyou1 of xlua knapsack system
Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
Data analysis exercises
Cesium for unreal quick start - simple scenario configuration
Get to know unity2 for the first time
Simply start with the essence and principle of SOM neural network
Redis data structure
[set theory] order relation (the relation between elements of partial order set | comparable | strictly less than | covering | Haas diagram)
Compilation error: "not in executable format: file format not recognized"“