当前位置:网站首页>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);
}
}
}
边栏推荐
- Advanced OSG collision detection
- Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
- Golang中删除字符串的最后一个字符
- Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
- LinkList
- MySQL 8
- 100 GIS practical application cases (78) - Multi compliance database design and data warehousing
- About Wireshark's unsuccessful installation of npcap
- Unity learning notes
- Chocolate installation
猜你喜欢
随机推荐
P2704 [noi2001] artillery position (shape pressure DP)
C#课程设计之学生教务管理系统
matlab神经网络所有传递函数(激活函数)公式详解
What does (+) in Oracle mean
Introduction to hexadecimal coding
Chain length value
Cesium for unreal quick start - simple scenario configuration
[updating] wechat applet learning notes_ three
【音视频】ijkplayer错误码
About Wireshark's unsuccessful installation of npcap
Introduction to Base64 coding
Simple demo of solving BP neural network by gradient descent method
Pit & ADB wireless debugging of vivo real machine debugging
Basic operation and process control 2
Mall management system of database application technology course design
P1596 [USACO10OCT]Lake Counting S
796 · unlock
Xlua task list youyou
redis集群系列四
Unity learning notes