私はこれを数時間続けてきました。おそらく私は完全に間違っているかもしれませんが、私は正しい計算をしていると感じていますが、何の数字を入力しても同じ出力が得られます。私のコードはどこかにあり、真夜中までにコードを入れなければなりません。ポイントが三角形内にあるかどうかを確認する
これはとても楽しいことです。ポイントが三角コード内にあるかどうかを確認します。 (初心者用)
import java.util.Scanner;
public class PointsTriangle {
// checks if point entered is within the triangle
//given points of triangle are (0,0) (0,100) (200,0)
public static void main (String [] args) {
//obtain point (x,y) from user
System.out.print("Enter a point's x- and y-coordinates: ");
Scanner input = new Scanner(System.in);
double x = input.nextDouble();
double y = input.nextDouble();
//find area of triangle with given points
double ABC = ((0*(100-0 )+0*(0 -0)+200*(0-100))/2.0);
double PAB = ((x*(0 -100)+0*(100-y)+0 *(y- 0))/2.0);
double PBC = ((x*(100-0 )+0*(0 -y)+200*(y-100))/2.0);
double PAC = ((x*(0 -100)+0*(100-y)+200*(y- 0))/2.0);
boolean isInTriangle = PAB + PBC + PAC == ABC;
if (isInTriangle)
System.out.println("The point is in the triangle");
else
System.out.println("The point is not in the triangle");
}//end main
}//end PointsTriangle
を持っています... – Floris