第三章第二十九題(幾何:兩個圓)(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)
- WPF繪圖(一):幾何(Geometry)與形狀(Shape)繪圖
- 第九章第九題(幾何:正多邊形)(Geometry: regular polygons)Go
- WPF 反射載入Geometry幾何圖形資料圖示反射
- JSXGraph幾何繪圖證明解答【五點共圓】問題JS繪圖
- 三維幾何生成:多段線、圓弧
- 找圓演算法((HoughCircles)總結與優化演算法優化
- 異構幾何問題
- 關於霍夫找圓演算法cvHoughCircles的引數演算法
- [計算幾何]圓與三角形是否相交
- Python中OpenCV劃線、畫圓、橢圓、新增文字等幾何圖形繪製操作PythonOpenCV
- 幾道經典的幾何作圖趣題
- 幾個把平面幾何問題的輔助線做到空間去的數學趣題
- 數學趣題:平面幾何(一)
- 數學趣題:平面幾何(二)
- 俄羅斯總理的幾何題
- [LeetCode] Add Two Numbers 兩個數字相加LeetCode
- hdu5365 簡單幾何問題
- 平面幾何
- LeetCode 第二題兩數相加LeetCode
- LeetCode 之 JavaScript 解答第一題 —— 兩數之和(Two Sum)LeetCodeJavaScript
- Multiple View Geometry(多檢視幾何)學習筆記(9)—無窮遠平面&絕對二次曲線View筆記
- LeetCode: Two sum(兩數之和)LeetCode
- [LeetCode] Two Sum 兩數之和LeetCode
- King連發兩款“糖果”IP新遊戲,成功前景幾何?遊戲
- 【leetcode 簡單】第二十題 合併兩個有序陣列LeetCode陣列
- 計算幾何
- Divide Two Integers不使用乘除法來計算兩個數相除IDE
- 達芬奇密碼 第二十九章密碼
- sql server 計算兩個時間 相差的 幾天幾時幾分幾秒SQLServer
- C. Black Circles
- 計算幾何 —— 二維幾何基礎 —— 距離度量方法
- 計算幾何:模板
- CF18A 幾何
- 美國人的幾何