第八章第三十一题(几何:交点)(Geometry: Intersections)
-
*8.31(几何:交点)编写一个方法,返回两条直线的交点。两条直线的交点可以使用编程练习题3.25中显示的公式求得。假设(x1,y1),(x2,y2)位于直线1上,而(x3,y3)和(x4,y4)位于直线2上。方法头:
public static double[] getIntersectionPoint(double[][] points)
这些点保存在 一个4x2的二维数组points中,其中(points[0][0],points[0][1])代表(x1,y1)。方法返回交点,或者如果两条线平行的话就返回null。编写一个程序,提示用户输入四个点,并且显示交点。运行示例参见编程练习题3.25.
*8.31(Geometry: Intersections)Write a method to return the intersection of two lines. The intersection of the two lines can be obtained by using the formula shown in programming exercise 3.25. Suppose (x1, Y1), (X2, Y2) are on line 1 and (X3, Y3) and (x4, Y4) are on line 2. Method header:
public static double[] getIntersectionPoint(double[][] points)
These points are stored in a 4x2 two-dimensional array points, where (points [0] [0], points [0] [1]) represents (x1, Y1). Method returns the intersection point, or null if two lines are parallel. Write a program to prompt the user to enter four points and display the intersection point. See programming exercise 3.25 for example -
参考代码:
package chapter08; import java.util.Scanner; public class Code_31 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入4个点"); double[][