Java 找到平行四边形的所有可能坐标
平行四边形指的是具有两对平行边的四边形,其中对边长度相等,对角线长度相等。
在本文中,我们将找到一个平行四边形的所有可能坐标。
基本上,我们将从给定的三个坐标中找到所有可能的坐标,以形成一个非零面积的平行四边形。这里给定的三个坐标不是固定点,可以改变。
因此,如果给定了三个坐标,我们可以说只有三个坐标可以构建一个平行四边形。
展示一些实例
实例1
假设三个点为 – {a1 = 3,a2 = 2},{b1 = 1,b2 = 0},{c1 = 4,c2 = 2} 找到平行四边形的所有可能坐标后,结果如下 – (x,y)坐标为 – 0,0 6,4 2,0
实例2
假设三个点为 – {a1 = 7,a2 = 2},{b1 = 3,b2 = 0},{c1 = 0,c2 = 1} 找到平行四边形的所有可能坐标后,结果如下 – (x,y)坐标为 – 10,1 4,3 -4,-1
步骤
步骤1 - 声明平行四边形的三个坐标。
步骤2 - 使用公式找到其他可能的坐标。
步骤3 - 打印结果。
多种方法
我们提供了不同的解决方法。
- 通过使用静态输入值
- 通过用户定义的方法
让我们逐个查看程序及其输出。
方法1:通过使用静态输入值
在这种方法中,我们将取三个点为静态输入,并应用公式来打印结果。
示例
public class Main{
// main method
public static void main(String[] args){
//Declare the three coordinates of parallelogram
int a1 = 3, a2 = 2;
int b1 = 1, b2 = 0;
int c1 = 4, c2 = 2;
//find the other possible coordinates and printing it
System.out.println("The (x,y) coordinates are: ");
System.out.println(a1 + b1 - c1 + ", " + (a2 + b2 - c2));
System.out.println(a1 + c1 - b1 + ", " + (a2 + c2 - b2));
System.out.println(c1 + b1 - a1 + ", " + (c2 + b2 - a2));
}
}
输出
The (x,y) coordinates are:
0, 0
6, 4
2, 0
方法2:使用用户自定义方法
在这种方法中,首先我们将初始化一个用户自定义方法,然后将三个点作为输入,并应用公式打印结果。
示例
public class Main {
// main method
public static void main(String[] s){
//Declare the three coordinates of parallelogram
int a1 = 7, a2 = 2;
int b1 = 3, b2 = 0;
int c1 = 0, c2 = 1;
//calling user defined function
func(a1, a2, b1, b2, c1, c2);
}
//user defined function
static void func(int a1, int a2, int b1, int b2, int c1, int c2){
//find the other possible coordinates and printing it
System.out.println("The (x,y) coordinates are: ");
System.out.println(a1 + b1 - c1 + ", " + (a2 + b2 - c2));
System.out.println(a1 + c1 - b1 + ", " + (a2 + c2 - b2));
System.out.println(c1 + b1 - a1 + ", " + (c2 + b2 - a2));
}
}
输出
The (x,y) coordinates are:
10, 1
4, 3
-4, -1
在这篇文章中,我们探讨了如何通过使用不同的方法在Java中找到平行四边形的所有可能坐标。