How to find the distance and angle between two points on a plane

Overview

Summarize how to find the angle and distance between two points in XY coordinates. Language is Java

How to find the distance

//Coordinates of 2 points
double x = 0;
double y = 0;
double x2 = 1;
double y2 = 1;

//Find the distance from the coordinates of two points
double distance = Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));

How to find the angle

//Coordinates of 2 points
double x = 0;
double y = 0;
double x2 = 1;
double y2 = 1;

//Find the radian from the coordinates of two points
doble radian = Math.atan2(y2 - y, x2 - x);

//Find the degree from the radians
double degree = radian * 180 / Math.PI;

Recommended Posts

How to find the distance and angle between two points on a plane
How to find the average angle
Find the angle between two vectors
Difference between Java and JavaScript (how to find the average)
How to find the tens and ones
Calculate the latitude / longitude distance between two points
How to find the total score and average score
How to run React and Rails on the same server
How to install and configure the monitoring tool "Graphite" on Ubuntu
[Rails] How to put a crown mark on the ranking function
How to place and share SwiftLint config files on the server
A memorandum on how to use Eclipse
How to redo a deployment on Heroku
[Android] How to turn the Notification panel on and off using StatusBarManager
A note on the differences between interfaces and abstract classes in Java
How to change the timezone on Ubuntu
How to find out the Java version of a compiled class file
[Rails] How to create a table, add a column, and change the column type
Differences between Java, C # and JavaScript (how to determine the degree of obesity)
How to share on the host side (windows) and guest side (CentOS 7) with VirtualBox
How to find the cause of the Ruby error
How to deploy a container on AWS Lambda
How to use Segmented Control and points to note
How to build a Pytorch environment on Ubuntu
[Java] Memo on how to write the source
Ruby How to convert between uppercase and lowercase
Code to find out how many people are lined up on the Tokyo 2020 official ticket sales site and tweet
How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
How to find the total value, average value, etc. of a two-dimensional array (multidimensional array)-java
A memo about the types of Java O/R mappers and how to select them
How to create a header or footer once and use it on another page
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
[ruby] How to assign a value to a hash by referring to the value and key of another hash
Let's sort out the differences between Java substring and C # Substring, and how to port them.
How to run the SpringBoot app as a service
What is the difference between a class and a struct? ?? ??
[Ruby on Rails] How to change the column name
How to make JavaScript work on a specific page
How to hover and click on Selenium DOM elements
[Java] How to execute tasks on a regular basis
How to convert A to a and a to A using AND and OR in Java
Install MySQL 5.6 on CentOS6 [How to specify the version]
[Ruby] How to get the tens place and the ones place
How to make a mod for Slay the Spire
(Ruby on Rails6) How to create models and tables
[Ruby On Rails] How to search and save the data of the parent table from the child table
[Error resolution] How to resolve the error "Could not find a JavaScript runtime." After upgrading Catalina!
[Ruby] How to get the value by specifying the key. Differences between hashes, symbols and fetch
How to reduce the load on the program even a little when combining characters with JAVA
How to take a screenshot with the Android Studio emulator
How to use OpenCV 4 on Android and view camera live view
SDWebImage: How to clear the cache for a particular UIImageView
How to prevent conflicts between JBoss modules and application libraries
How to deploy a simple Java Servlet app on Heroku
How to get inside a container running on AWS Fargate
How to create a form to select a date from the calendar
How to create a placeholder part to use in the IN clause
How to Install Elixir and Phoenix Framework on Ubuntu 20.04 LTS
I want to call a method and count the number
[Rails] Differences between redirect_to and render methods and how to output render methods
How to disable Set-Cookie from API on the front side