日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java如何定义三个圆_java – 以编程方式查找三个圆的交叉点

發布時間:2023/12/18 java 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java如何定义三个圆_java – 以编程方式查找三个圆的交叉点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

你可以從

C code獲得幫助.把它移植到JAVA不應該是具有挑戰性的.說明是

here.搜索/滾動到:兩個圓的交點

使用此方法,找到任意兩個圓的交點..讓我們說(x,y).現在,只有當中心與點x,y之間的距離等于r時,第三個圓將在點x,y處相交.

情況1)如果距離(中心,點)== r,則x,y是交點.

情況2)如果距離(中心,點)!= r,則不存在這樣的點.

代碼(從[這里!所有學分轉移到原作者):

private boolean calculateThreeCircleIntersection(double x0, double y0, double r0,

double x1, double y1, double r1,

double x2, double y2, double r2)

{

double a, dx, dy, d, h, rx, ry;

double point2_x, point2_y;

/* dx and dy are the vertical and horizontal distances between

* the circle centers.

*/

dx = x1 - x0;

dy = y1 - y0;

/* Determine the straight-line distance between the centers. */

d = Math.sqrt((dy*dy) + (dx*dx));

/* Check for solvability. */

if (d > (r0 + r1))

{

/* no solution. circles do not intersect. */

return false;

}

if (d < Math.abs(r0 - r1))

{

/* no solution. one circle is contained in the other */

return false;

}

/* 'point 2' is the point where the line through the circle

* intersection points crosses the line between the circle

* centers.

*/

/* Determine the distance from point 0 to point 2. */

a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;

/* Determine the coordinates of point 2. */

point2_x = x0 + (dx * a/d);

point2_y = y0 + (dy * a/d);

/* Determine the distance from point 2 to either of the

* intersection points.

*/

h = Math.sqrt((r0*r0) - (a*a));

/* Now determine the offsets of the intersection points from

* point 2.

*/

rx = -dy * (h/d);

ry = dx * (h/d);

/* Determine the absolute intersection points. */

double intersectionPoint1_x = point2_x + rx;

double intersectionPoint2_x = point2_x - rx;

double intersectionPoint1_y = point2_y + ry;

double intersectionPoint2_y = point2_y - ry;

Log.d("INTERSECTION Circle1 AND Circle2:", "(" + intersectionPoint1_x + "," + intersectionPoint1_y + ")" + " AND (" + intersectionPoint2_x + "," + intersectionPoint2_y + ")");

/* Lets determine if circle 3 intersects at either of the above intersection points. */

dx = intersectionPoint1_x - x2;

dy = intersectionPoint1_y - y2;

double d1 = Math.sqrt((dy*dy) + (dx*dx));

dx = intersectionPoint2_x - x2;

dy = intersectionPoint2_y - y2;

double d2 = Math.sqrt((dy*dy) + (dx*dx));

if(Math.abs(d1 - r2) < EPSILON) {

Log.d("INTERSECTION Circle1 AND Circle2 AND Circle3:", "(" + intersectionPoint1_x + "," + intersectionPoint1_y + ")");

}

else if(Math.abs(d2 - r2) < EPSILON) {

Log.d("INTERSECTION Circle1 AND Circle2 AND Circle3:", "(" + intersectionPoint2_x + "," + intersectionPoint2_y + ")"); //here was an error

}

else {

Log.d("INTERSECTION Circle1 AND Circle2 AND Circle3:", "NONE");

}

return true;

}

調用此方法如下:

calculateThreeCircleIntersection(-2.0, 0.0, 2.0, // circle 1 (center_x, center_y, radius)

1.0, 0.0, 1.0, // circle 2 (center_x, center_y, radius)

0.0, 4.0, 4.0);// circle 3 (center_x, center_y, radius)

此外,將EPSILON定義為適合您的應用程序要求的小值

private static final double EPSILON = 0.000001;

注意:也許有人應該測試并驗證結果是否正確.我找不到任何簡單的方法.我嘗試過的基本案例的工作

總結

以上是生活随笔為你收集整理的Java如何定义三个圆_java – 以编程方式查找三个圆的交叉点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。