题目:
( 几何:点的位置)给定一个从点 p0( x0, y0) 到 pl( xl, pl) 的有向线段,可以使用
下面的条件来确定点 p2( x2, y2) 是在线段的左侧、右侧,或者在该直线上(见下图) :
编写一个程序,提示用户输入三个点 p0、 p1 和 p2, 显示 p2 是否在从 p0 到 p1 的线段左
侧、右侧,或者在该直线上。下面是运行示例
class Tang_01_21
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
double x0=input.nextDouble();
double y0=input.nextDouble();
double x1=input.nextDouble();
double y1=input.nextDouble();
double x2=input.nextDouble();
double y2=input.nextDouble();
double result=(x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);
if(result>0)
System.out.println("("+x2+","+y2+")"+"is on the left side of the line from"+"("+x0+","+y0+") to"+"("+x1+","+y1+")");
if(result<0)
System.out.println("("+x2+","+y2+")"+"is on the right side of the line from"+"("+x0+","+y0+") to"+"("+x1+","+y1+")");
if(result==0)
System.out.println("("+x2+","+y2+")"+"is on the line from"+"("+x0+","+y0+") to"+"("+x1+","+y1+")");
}
}