第三章第二十九題(幾何:兩個圓)(Geometry: two circles)
第三章第二十九題(幾何:兩個圓)(Geometry: two circles)
-
**3.29(幾何:兩個圓)編寫程式,提示使用者輸入兩個圓的中心座標和各自的半徑值,然後判斷第二個圓是在第一個圓內,還是和第一個圓重疊。
下面是執行示例:
Enter circle1’s center x-,y-coordinates,and radius: 0.5 5.1 13
Enter circle2’s center x-,y-coordinates,and radius: 1 1.7 4.5
circle2 is inside circle1
Enter circle1’s center x-,y-coordinates,and radius: 3.4 5.7 5.5
Enter circle2’s center x-,y-coordinates,and radius: 6.7 3.5 3
circle2 overlaps circle1
Enter circle1’s center x-,y-coordinates,and radius: 3.4 5.5 1
Enter circle2’s center x-,y-coordinates,and radius: 5.5 7.2 1
circle2 does not overlap circle1**3.29(Geometry: two circles) Write a program that prompts the user to enter the center coordinates and radii of two circles and determines whether the second circle is inside the first or overlaps with the first.
Here are the sample runs:
Enter circle1’s center x-,y-coordinates,and radius: 0.5 5.1 13
Enter circle2’s center x-,y-coordinates,and radius: 1 1.7 4.5
circle2 is inside circle1
Enter circle1’s center x-,y-coordinates,and radius: 3.4 5.7 5.5
Enter circle2’s center x-,y-coordinates,and radius: 6.7 3.5 3
circle2 overlaps circle1
Enter circle1’s center x-,y-coordinates,and radius: 3.4 5.5 1
Enter circle2’s center x-,y-coordinates,and radius: 5.5 7.2 1
circle2 does not overlap circle1 -
參考程式碼:
package chapter03;
import java.util.Scanner;
public class Code_29 {
public static void main(String[] args) {
double xCoordinateCircle1,yCoordinateCircle1,radiusCircle1;
double xCoordinateCircle2,yCoordinateCircle2,radiusCircle2;
double distanceFromP1ToP2;
System.out.print("Enter circle1's center x-,y-coordinates,and radius: ");
Scanner input = new Scanner(System.in);
xCoordinateCircle1 = input.nextDouble();
yCoordinateCircle1 = input.nextDouble();
radiusCircle1 = input.nextDouble();
System.out.print("Enter circle2's center x-,y-coordinates,and radius: ");
xCoordinateCircle2 = input.nextDouble();
yCoordinateCircle2 = input.nextDouble();
radiusCircle2 = input.nextDouble();
distanceFromP1ToP2 = Math.pow((Math.pow(xCoordinateCircle1-xCoordinateCircle2, 2)
+Math.pow(yCoordinateCircle1-yCoordinateCircle2, 2)), 0.5);
if(radiusCircle1 + radiusCircle2 >= distanceFromP1ToP2)
{
if(radiusCircle1 - radiusCircle2 >= distanceFromP1ToP2)
System.out.println("circle2 is inside circle1");
else
System.out.println("circle2 overlaps circle1");
}
else
System.out.println("circle2 does not overlap circle1");
input.close();
}
}
- 結果顯示:
Enter circle1's center x-,y-coordinates,and radius: 0.5 5.1 13
Enter circle2's center x-,y-coordinates,and radius: 1 1.7 4.5
circle2 is inside circle1
Process finished with exit code 0
相關文章
- 第三章第二十五題(幾何:交點)(Geometry: intersecting point)
- 第九章第十二題(幾何:交點)(Geometry: Intersections)
- three.js基礎之幾何體Curve、GeometryJS
- WPF繪圖(一):幾何(Geometry)與形狀(Shape)繪圖
- 不可不知的WPF幾何圖形(Geometry)
- 第九章第九題(幾何:正多邊形)(Geometry: regular polygons)Go
- WPF 反射載入Geometry幾何圖形資料圖示反射
- JSXGraph幾何繪圖證明解答【五點共圓】問題JS繪圖
- 三維幾何生成:多段線、圓弧
- 異構幾何問題
- 寫一個Geometry Shader
- 旋轉向量合成,兩個圓圈
- C. Black Circles
- LeetCode 之 JavaScript 解答第一題 —— 兩數之和(Two Sum)LeetCodeJavaScript
- LeetCode 第二題兩數相加LeetCode
- Python中OpenCV劃線、畫圓、橢圓、新增文字等幾何圖形繪製操作PythonOpenCV
- LeetCode: Two sum(兩數之和)LeetCode
- [計算幾何]圓與三角形是否相交
- 數學趣題:平面幾何(一)
- 數學趣題:平面幾何(二)
- sweetalert 快速顯示兩個提示, 第二個顯示不出的問題
- 【leetcode 簡單】第二十題 合併兩個有序陣列LeetCode陣列
- 1.兩數之和 Two Sum
- 俄羅斯總理的幾何題
- AC-DMIS 5.3 平面 、 圓 、 圓(已知,先偏置一個軸,後偏置兩個軸)
- python leetcode 之兩數之和(two sum)PythonLeetCode
- 001,Two Sum(求兩數的和)
- 平面幾何
- Multiple View Geometry(多檢視幾何)學習筆記(9)—無窮遠平面&絕對二次曲線View筆記
- King連發兩款“糖果”IP新遊戲,成功前景幾何?遊戲
- LeetCode2: Add two numbers(兩數相加)LeetCode
- 計算幾何(一):凸包問題(Convex Hull)
- 計算幾何
- sql server 計算兩個時間 相差的 幾天幾時幾分幾秒SQLServer
- Fifth. LeetCode 2:Add Two Numbers 兩數之和LeetCode
- 用css畫出兩個大圓相交,可以在各自圓及相交部分輸入文字CSS
- CAD兩點畫圓操作
- 計算幾何 —— 二維幾何基礎 —— 距離度量方法