当前位置:网站首页>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);
}
}
}
边栏推荐
- Simple demo of solving BP neural network by gradient descent method
- Editor Extensions
- Clion toolchains are not configured configure disable profile problem solving
- P1596 [USACO10OCT]Lake Counting S
- 【云原生】微服务之Feign的介绍与使用
- Transplantation of tslib Library
- One dimensional array two dimensional array (sort Max insert sort)
- Pit & ADB wireless debugging of vivo real machine debugging
- Haproxy+kept build 01
- Chocolate installation
猜你喜欢
Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)
Dotween plug-in
UE4 source code reading_ Bone model and animation system_ Animation node
Transplantation of freetype Library
数据的存储
C#课程设计之学生教务管理系统
Easy touch plug-in
Chocolate installation
Explain sizeof, strlen, pointer, array and other combination questions in detail
随机推荐
P2704 [noi2001] artillery position (shape pressure DP)
Golang 时间格式整理
Haproxy+kept cluster setup 02
Shader foundation 01
Unity4.3.1 engine source code compilation process
Golang中删除字符串的最后一个字符
Transplantation of freetype Library
matlab神经网络所有传递函数(激活函数)公式详解
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)
Conversion between JSON and object
Base64编码简介
Osgearth starry background
Clion toolchains are not configured configure disable profile problem solving
100 GIS practical application cases (78) - Multi compliance database design and data warehousing
MySQL containerization (1) docker installation MySQL
Golang 字符串分割,替换和截取
Transfinite hacker cognition
Chain length value
Introduction to hexadecimal coding
Sequence of map implementation classes