我正在尝试将下面的方程转换为编程代码。目的是找到两条线的相交点并打印。
(y1 - y2)x - (x1 - x2)y = (y1 - y2)x1 - (x1 - x2)y1
(y3 - y4)x - (x3 - x4)y = (y3 - y4)x3 - (x3 - x4)y3
我被告知要使用克莱姆法则,但克莱姆法则有6个不同的变量。我将从4个不同的点开始,作为8个变量(x1、y1、x2、y2、x3、y3、x4、y4)。
我正在使用Java。任何帮助都将不胜感激。此网站上所有问题都涉及长而复杂的代码的不同类型的线性方程,我没有发现任何与我相关的内容。
这就是我拥有的,虽然不多,但如何从上述方程过渡到可编程内容确实困扰着我。
import java.util.Scanner;
public class E325 {
public static void main(String[] args) {
/*
* The purpose of this program is to find the intersect
* of two lines given by the user by four points
*
* Get the four points. x1,y1 x2,y2 x3,y3 x4,y4
*/
Scanner input = new Scanner(System.in);
System.out.print("Enter x1 y1, x2 y2, x3 y3, x4 y4: ");
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double x3 = input.nextDouble();
double y3 = input.nextDouble();
double x4 = input.nextDouble();
double y4 = input.nextDouble();
}
}