*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