JAVA 三点定位相关计算(一,两圆关系)

判断两圆相交

两圆圆心坐标(X1,Y1),(X2,Y2),半径分别为r1,r2。
1,直线距离
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离

double s = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));

2,两圆相交

if (s < (r1 + r2)) 

3,同心圆

if (x1 == x2 && y1 == y2)

4,相离

if (s > r1 + r2)

5,内含

if (s < Math.abs(r1 - r2))

6,相切,并计算切点

if (s = Math.abs(r1 - r2)|| s == r1 + r2){
   
	if (y1 == y2 && x1 != x2) {
   
		double x = 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
三点定位算法是通过已知的三个点的位置,推算出一个未知点的位置。这个算法有多种实现方式,下面是一种基于三角形相似性原理的实现方式。 1. 首先定义一个Point类,用于存储点的坐标信息。 ``` public class Point { public double x; public double y; public Point(double x, double y) { this.x = x; this.y = y; } } ``` 2. 定义一个三点定位的方法,输入参数为三个已知点的坐标和它们与未知点的距离。输出为未知点的坐标。 ``` public Point trilateration(Point p1, double d1, Point p2, double d2, Point p3, double d3) { // 计算三个点之间的距离 double a = p2.x - p1.x; double b = p2.y - p1.y; double c = Math.sqrt(a * a + b * b); double e = (p3.x - p1.x) / c; double f = (p3.y - p1.y) / c; double d = 2 * (e * (p2.x - p1.x) + f * (p2.y - p1.y)); double g = (p3.x - p1.x) * (p3.x - p1.x) + (p3.y - p1.y) * (p3.y - p1.y) - d1 * d1; double h = (p3.x - p2.x) * (p3.x - p2.x) + (p3.y - p2.y) * (p3.y - p2.y) - d2 * d2; double i = (g + h) / d; double j = (g - h) / d; double x = p3.x - i * e - j * (p2.x - p1.x) / c; double y = p3.y - i * f - j * (p2.y - p1.y) / c; return new Point(x, y); } ``` 3. 测试代码如下,假设有三个已知点(0,0)、(3,0)、(0,4),它们与未知点的距离分别为5、4、3,求未知点的坐标。 ``` public static void main(String[] args) { Point p1 = new Point(0, 0); double d1 = 5; Point p2 = new Point(3, 0); double d2 = 4; Point p3 = new Point(0, 4); double d3 = 3; Point p4 = trilateration(p1, d1, p2, d2, p3, d3); System.out.println("未知点的坐标为(" + p4.x + ", " + p4.y + ")"); } ``` 输出结果为:未知点的坐标为(1.8, 2.4)。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值