Skip to content

MSH-trojan/Java_17_Two_lines_Perpendicular

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Write a Java code that asks the user to enter the integer (x, y) coordinates of two points that form a straight line, reads these coordinates, and calculate the slope (a) and the slope-intercept (b) that form the equation of the straight line as follows: y = ax + b a = (y2 - y1)/(x2 - x1) b = y2 - a*x2 Then ask the user to enter the integer (xA, yA) coordinate of a point A, read this data, and calculate the distance from this point A to the above straight line: Then you need to get the equation of the line that passes through A and is perpendicular to the original one as follows: The slope of the perpendicular line (aP) is the negative inverse of the slope of the original line: aP = -1/a The slope-intercept (bP) of the perpendicular line is calculated by replacing the coordinates of point A into the equation: 𝑏𝑃=π‘¦π΄βˆ’π‘Žπ‘ƒπ‘₯𝐴 Once you get the equation of the perpendicular line, you need to calculate the coordinates (xI, yI) of the intersection point between the original line and the perpendicular one as follows. π‘₯𝐼=π‘π‘ƒβˆ’π‘π‘Žβˆ’π‘Žπ‘ƒ 𝑦𝐼=π‘Žπ‘₯𝐼+𝑏 Lastly, get the distance as follows: π‘‘π‘–π‘ π‘‘π‘Žπ‘›π‘π‘’=√(π‘₯π΄βˆ’π‘₯𝐼)^2+(π‘¦π΄βˆ’π‘¦πΌ)^2

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages