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

歡迎訪問 生活随笔!

生活随笔

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

java

Java黑皮书课后题第3章:*3.32(几何:点的位置)给定一个从点p0(x0,y0)到p1(x1,y1)的有向线段,可以用以下公式判定定点p2(x2, y2)是在线段的左侧、右侧,或者在该线段上

發布時間:2024/7/23 java 28 豆豆

*3.32(幾何:點的位置)給定一個從點p0(x0,y0)到p1(x1,y1)的有向線段,可以用以下公式判定定點p2(x2, y2)是在線段的左側、右側,或者在該線段上

  • 題目
    • 題目概述
    • 運行示例
  • 代碼

題目

題目概述

*3.32(幾何:點的位置)給定一個從點p0(x0,y0)到p1(x1,y1)的有向線段,可以用以下公式判定定點p2(x2, y2)是在線段的左側、右側,或者在該線段上
公式:(x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0)
以上結果>0則p2在線段左側,=0則在線段上,<0則在線段右側
編寫程序,提示用戶輸入三個點p0 p1 p2,顯示p2在線段p0p1的左側右側還是線段上

運行示例

Enter three points for p0, p1, and p2: 4.4 2 6.5 9.5 -5 4
p2 is on the left side of the line

Enter three points for p0, p1, and p2: 1 1 5 5 2 2
p2 is on the same line

Enter three points for p0, p1, and p2: 3.4 2 6.5 9.5 5 2.5
p2 is on the right side of the line

代碼

import java.util.Scanner;public class Test3_32 {public static void main(String[] args) {// 獲取三個點的x、y坐標值Scanner input = new Scanner(System.in);System.out.println("Enter three points for p0, p1, and p2: ");double x0 = input.nextDouble(), y0 = input.nextDouble();double x1 = input.nextDouble(), y1 = input.nextDouble();double x2 = input.nextDouble(), y2 = input.nextDouble();// 公式判斷double result = (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0);// 輸出結果if(result > 0)System.out.println("p2 is on the left side of the line");else if(result == 0)System.out.println("p2 is on the same line");elseSystem.out.println("p2 is on the right side of the line");} }

總結

以上是生活随笔為你收集整理的Java黑皮书课后题第3章:*3.32(几何:点的位置)给定一个从点p0(x0,y0)到p1(x1,y1)的有向线段,可以用以下公式判定定点p2(x2, y2)是在线段的左侧、右侧,或者在该线段上的全部內容,希望文章能夠幫你解決所遇到的問題。

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