Excel表格网

java 点到线段的计算公式

214 2024-02-27 18:31 admin   手机版
java public class PointToLineDistance { public static double distanceToLine(double x1, double y1, double x2, double y2, double x, double y) { double APx = x - x1; double APy = y - y1; double ABx = x2 - x1; double ABy = y2 - y1; double dotProduct = APx * ABx + APy * ABy; double magnitudeAB = Math.sqrt(ABx * ABx + ABy * ABy); double distance = Math.abs(dotProduct) / magnitudeAB; return distance; } public static void main(String[] args) { double distance = distanceToLine(0, 0, 5, 5, 2, 3); System.out.println("点到线段的距离是:" + distance); } }
顶一下
(0)
0%
踩一下
(0)
0%
相关评论
我要评论
用户名: 验证码:点击我更换图片
上一篇:返回栏目
下一篇:javafx timespinner