搜索
首页Javajava教程在Java中找到平行四边形的所有可能坐标

在Java中找到平行四边形的所有可能坐标

Aug 26, 2023 pm 07:41 PM
java坐标平行四边形

平行四边形是指具有两对平行边的四边形,其中对边长度相等,对角线度量相等。

In this article we are going to find all possible coordinates of a Parallelogram.

Basically, we will find all the possible coordinates from the given three coordinates to make a parallelogram of a non-zero area. Here the three given coordinates are not fixed points and can change.

因此,如果给出三个坐标,我们可以断言只有这三个坐标可以构建一个平行四边形。

在Java中找到平行四边形的所有可能坐标

As per diagram given above, the opposite sides of a parallelogram are equal in length i.e., AD = BC and AB = CD, we can calculate the coordinates of the missing point (D) as

AD = BC

(Dx - Ax, Dy - Ay) = (Cx - Bx, Cy - By)

Dx = Ax + Cx - Bx

Dy = Ay + Cy - By

让我们开始吧!

展示给你一些实例

Instance-1

假设这三个点是 −

{a1 = 3, a2 = 2}, {b1 = 1, b2 = 0}, {c1 = 4, c2 = 2}

After finding all possible coordinates of a Parallelogram, result will be −

The (x, y) coordinates are −

0, 0

6, 4

2, 0

Instance-2

假设这三个点是 −

{a1 = 7, a2 = 2}, {b1 = 3, b2 = 0}, {c1 =0, c2 = 1}

After finding all possible coordinates of a Parallelogram, result will be −

The (x,y) coordinates are −

10, 1

4, 3

-4, -1

Algorithm

Step 1 − Declare the three coordinates of parallelogram.

Step 2 − Find the other possible coordinates using the formula.

Step 3 − Print the result.

Multiple Approaches

我们以不同的方法提供了解决方案。

  • 通过使用静态输入值

  • 通过用户定义的方法

让我们逐个查看程序及其输出。

方法一:通过使用静态输入值

在这种方法中,我们将把这三个点作为静态输入,并应用公式来打印结果。

Example

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));
   }
}

Output

The (x,y) coordinates are: 
0, 0
6, 4
2, 0

Approach-2: By Using User Defined Method

In this approach, first we will initialise a user defined method and we will take the three points as input and apply the formula to print the result.

Example

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));
   }
}

Output

The (x,y) coordinates are: 
10, 1
4, 3
-4, -1

在这篇文章中,我们探讨了如何通过使用不同的方法在Java中找到平行四边形的所有可能坐标。

以上是在Java中找到平行四边形的所有可能坐标的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:tutorialspoint。如有侵权,请联系admin@php.cn删除
说明JVM如何充当Java代码和基础操作系统之间的中介。说明JVM如何充当Java代码和基础操作系统之间的中介。Apr 29, 2025 am 12:23 AM

JVM的工作原理是将Java代码转换为机器码并管理资源。1)类加载:加载.class文件到内存。2)运行时数据区:管理内存区域。3)执行引擎:解释或编译执行字节码。4)本地方法接口:通过JNI与操作系统交互。

解释Java虚拟机(JVM)在Java平台独立性中的作用。解释Java虚拟机(JVM)在Java平台独立性中的作用。Apr 29, 2025 am 12:21 AM

JVM使Java实现跨平台运行。1)JVM加载、验证和执行字节码。2)JVM的工作包括类加载、字节码验证、解释执行和内存管理。3)JVM支持高级功能如动态类加载和反射。

您将采取哪些步骤来确保Java应用程序在不同的操作系统上正确运行?您将采取哪些步骤来确保Java应用程序在不同的操作系统上正确运行?Apr 29, 2025 am 12:11 AM

Java应用可通过以下步骤在不同操作系统上运行:1)使用File或Paths类处理文件路径;2)通过System.getenv()设置和获取环境变量;3)利用Maven或Gradle管理依赖并测试。Java的跨平台能力依赖于JVM的抽象层,但仍需手动处理某些操作系统特定的功能。

Java是否需要特定于平台的配置或调整区域?Java是否需要特定于平台的配置或调整区域?Apr 29, 2025 am 12:11 AM

Java在不同平台上需要进行特定配置和调优。1)调整JVM参数,如-Xms和-Xmx设置堆大小。2)选择合适的垃圾回收策略,如ParallelGC或G1GC。3)配置Native库以适应不同平台,这些措施能让Java应用在各种环境中发挥最佳性能。

哪些工具或库可以帮助您解决Java开发中特定于平台的挑战?哪些工具或库可以帮助您解决Java开发中特定于平台的挑战?Apr 29, 2025 am 12:01 AM

Osgi,Apachecommonslang,JNA和JvMoptionsareeForhandlingForhandlingPlatform-specificchallengesinjava.1)osgimanagesdeppedendendencenciesandisolatescomponents.2)apachecommonslangprovidesitorityfunctions.3)

JVM如何在不同平台上管理垃圾收集?JVM如何在不同平台上管理垃圾收集?Apr 28, 2025 am 12:23 AM

JVMmanagesgarbagecollectionacrossplatformseffectivelybyusingagenerationalapproachandadaptingtoOSandhardwaredifferences.ItemploysvariouscollectorslikeSerial,Parallel,CMS,andG1,eachsuitedfordifferentscenarios.Performancecanbetunedwithflagslike-XX:NewRa

为什么Java代码可以在不同的操作系统上运行,而无需修改?为什么Java代码可以在不同的操作系统上运行,而无需修改?Apr 28, 2025 am 12:14 AM

Java代码可以在不同操作系统上无需修改即可运行,这是因为Java的“一次编写,到处运行”哲学,由Java虚拟机(JVM)实现。JVM作为编译后的Java字节码与操作系统之间的中介,将字节码翻译成特定机器指令,确保程序在任何安装了JVM的平台上都能独立运行。

描述编译和执行Java程序的过程,突出平台独立性。描述编译和执行Java程序的过程,突出平台独立性。Apr 28, 2025 am 12:08 AM

Java程序的编译和执行通过字节码和JVM实现平台独立性。1)编写Java源码并编译成字节码。2)使用JVM在任何平台上执行字节码,确保代码的跨平台运行。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),