搜尋
首頁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中的類加載程序子系統如何促進平台獨立性?JVM中的類加載程序子系統如何促進平台獨立性?Apr 23, 2025 am 12:14 AM

類加載器通過統一的類文件格式、動態加載、雙親委派模型和平台無關的字節碼,確保Java程序在不同平台上的一致性和兼容性,實現平台獨立性。

Java編譯器會產生特定於平台的代碼嗎?解釋。Java編譯器會產生特定於平台的代碼嗎?解釋。Apr 23, 2025 am 12:09 AM

Java編譯器生成的代碼是平台無關的,但最終執行的代碼是平台特定的。 1.Java源代碼編譯成平台無關的字節碼。 2.JVM將字節碼轉換為特定平台的機器碼,確保跨平台運行但性能可能不同。

JVM如何處理不同操作系統的多線程?JVM如何處理不同操作系統的多線程?Apr 23, 2025 am 12:07 AM

多線程在現代編程中重要,因為它能提高程序的響應性和資源利用率,並處理複雜的並發任務。 JVM通過線程映射、調度機制和同步鎖機制,在不同操作系統上確保多線程的一致性和高效性。

在Java的背景下,'平台獨立性”意味著什麼?在Java的背景下,'平台獨立性”意味著什麼?Apr 23, 2025 am 12:05 AM

Java的平台獨立性是指編寫的代碼可以在任何安裝了JVM的平台上運行,無需修改。 1)Java源代碼編譯成字節碼,2)字節碼由JVM解釋執行,3)JVM提供內存管理和垃圾回收功能,確保程序在不同操作系統上運行。

Java應用程序仍然可以遇到平台特定的錯誤或問題嗎?Java應用程序仍然可以遇到平台特定的錯誤或問題嗎?Apr 23, 2025 am 12:03 AM

Javaapplicationscanindeedencounterplatform-specificissuesdespitetheJVM'sabstraction.Reasonsinclude:1)Nativecodeandlibraries,2)Operatingsystemdifferences,3)JVMimplementationvariations,and4)Hardwaredependencies.Tomitigatethese,developersshould:1)Conduc

雲計算如何影響Java平台獨立性的重要性?雲計算如何影響Java平台獨立性的重要性?Apr 22, 2025 pm 07:05 PM

云计算显著提升了Java的平台独立性。1)Java代码编译为字节码,由JVM在不同操作系统上执行,确保跨平台运行。2)使用Docker和Kubernetes部署Java应用,提高可移植性和可扩展性。

Java的平台獨立性在廣泛採用中扮演著什麼角色?Java的平台獨立性在廣泛採用中扮演著什麼角色?Apr 22, 2025 pm 06:53 PM

Java'splatformindependenceallowsdeveloperstowritecodeonceandrunitonanydeviceorOSwithaJVM.Thisisachievedthroughcompilingtobytecode,whichtheJVMinterpretsorcompilesatruntime.ThisfeaturehassignificantlyboostedJava'sadoptionduetocross-platformdeployment,s

容器化技術(例如Docker)如何影響Java平台獨立性的重要性?容器化技術(例如Docker)如何影響Java平台獨立性的重要性?Apr 22, 2025 pm 06:49 PM

容器化技術如Docker增強而非替代Java的平台獨立性。 1)確保跨環境的一致性,2)管理依賴性,包括特定JVM版本,3)簡化部署過程,使Java應用更具適應性和易管理性。

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

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版