Java 如何使用坐标检查点是否位于三角形内?

Java 如何使用坐标检查点是否位于三角形内?,java,geometry,Java,Geometry,假设一个直角三角形放置在一个平面中,如下所示: 如下所示。直角点放置在(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 = JOption

假设一个直角三角形放置在一个平面中,如下所示: 如下所示。直角点放置在(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
`String xInput,yInput;
双x,y;
xInput=JOptionPane.showInputDialog(“输入点的x坐标”);
yInput=JOptionPane.showInputDialog(“输入点的y坐标”);
x=Double.parseDouble(xInput);
y=Double.parseDouble(yInput);
如果(x=0&&y=0){
如果(y=汇总(x/2))
系统输出打印(“点在三角形中”);
其他的
System.out.print(“点不在三角形中”);
}否则
System.out.print(“点不在三角形中”)`
如果说double不能是布尔值,则第二个输出是错误的

基本上你有一个线性公式,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");
 }
if(x<0 | | x>200 | | y<0){
System.out.print(“点不在三角形中”);

}else if(y)
roundup
做什么?如果(y==roundup(x/2))你想要一个相等测试
if(y==roundup)
实际上,甚至
都使用ceil方法。据我所知,roundup不存在。另外,您是否打算在第二个if语句中使用=或==呢?主要是=应该是==但现在他们告诉我,roundup是个问题,那么我还可以使用哪些其他方法|