亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用坐標檢查點是否位于三角形內部?

如何使用坐標檢查點是否位于三角形內部?

白板的微信 2023-07-19 15:39:30
假設將一個直角三角形放置在一個平面上,如下所示。直角點放置在(0, 0)處,另外兩個點放置在(200, 0)和(0, 100)處。編寫一個程序,提示用戶輸入帶有 x 和 y 坐標的點,并確定該點是否在三角形內部。? ? `String xInput, yInput;? ? double x, y;? ? xInput = JOptionPane.showInputDialog("Enter the x-coordinate of the point");? ? yInput = JOptionPane.showInputDialog("Enter the y-coordinate of the point");? ? x = Double.parseDouble(xInput);? ? y = Double.parseDouble(yInput);? ? if (x <= 200 && x >= 0 && y <= 100 && y >= 0) {? ? ? ? if (y = roundup(x/2))? ? ? ? ? ? System.out.print("The point is in the the triangle");? ? ? ? else? ? ? ? ? ? System.out.print("The point isn't in the triangle");? ? }else? ? ? ? System.out.print("The point isn't in the triangle");`The output is an error in the second if saying that a double can't be a boolean
查看完整描述

2 回答

?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

基本上你有一個線性公式 y = 100 - x/2 其中 x 在 0 到 200 之間,所以我們可以為此創建簡單的方法


static double calculateY(double x) {

    return 100.0 - x / 2.0;

}

然后將 x 與邊界進行比較,將 y 與公式進行比較


 if (x < 0 || x > 200 || y < 0) {

     System.out.print("The point isn't in the triangle");

 } else if ( y <= calculateY(x)) {

     System.out.print("The point is in the the triangle");

 } else

     System.out.print("The point isn't in the triangle");

 }


查看完整回答
反對 回復 2023-07-19
?
慕慕森

TA貢獻1856條經驗 獲得超17個贊

考慮一個頂點位于 (0, 0)、(1, 0) 和 (0, 1) 的三角形。編寫一個程序,詢問用戶 x 和 y 坐標,然后輸出該點是在三角形內部、在三角形邊界上還是在三角形外部。



查看完整回答
反對 回復 2023-07-19
  • 2 回答
  • 0 關注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號