第三章第三十二题(几何:点的位置)(Geometry: point position)
-
*3.32(几何:点的位置)给定一个从点 p0(x0,y0) 到 p1(x1,y1)的有向线段,可以使用下面的条件来确定点p2(x2,y2)是在线段的左侧、右侧,或者在该线段上。
编写一个程序,提示用户输入三个点 p0、p1和p2,显示p2是在从p0到p1的线段的左侧、右侧,还是在线段上。
下面是运行示例: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 one the right side of the line
*3.32(Geometry: point position) Given a directed line from point p0(x0, y0) to p1(x1, y1), you can use the following condition to decide whether a point p2(x2, y2) is on the left of the line, on the right, or on the same line
Write a program that prompts the user to enter the three points for p0, p1, and p2 and displays whether p2 is on the left of the line from p0 to p1, to the right, or on the same line.Here are some sample runs:
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 one the right side of the line
-
参考代码: