HomeCALCULUSMinimum Distance Between a...

Minimum Distance Between a Point and a Line

HP Prime: Minimum Distance Between a Point and a Line

Introduction

We
have a line in the form of y = m * x + b, where m is the slope of the
line and b is the y-intercept of the line, and a separate point (px,
py). The task is to find the minimum distance, or the shortest
distance, between the point and the line. The separate point is not
required to be on the line. The line and point are in
two-dimensional space.

If
the point (px, py) is not on the line, then theoretically, there are
an infinite amount of distances between the point and the line.
However, to get the shortest distance, draw a path that is “directly
straight” to the line. This is achieved by choosing a line that
connects the (px, py) that is a line that is orthogonal
(perpendicular) to the line y = m * x + b.

Minimum Distance Between a Point and a Line

The
line drawn is of the form y = -1/m * x + b1. The slope of the
orthogonal line is -1/m. Assuming that m ≠ 0, the y-intercept of
the orthogonal line is b1 = y1 + x1 / m.

The
next step is to find where the two lines intersect, which is done by
solving the following system for x and y:

y =
m * x + b

y =
-m / n + b1

Label
the intersection point (x1, y1). The minimum distance will be
calculated as follows:

dist
= √( (x1 – px)^2 + (y1 – py)^2 ) = abs( (x1 – px) + (y1 –
py)*i)

If m
= 0, the line is in the form of y = b. The orthogonal line is x =
px, and the distance is simply abs( (y1 – py)*i ).

HP
Prime Code: PTLNDIST

EXPORT
PTLNDIST()

BEGIN

//
2024-07-21 EWS

//
radian

HAngle:=0;

LOCAL
px,py,m,b;

INPUT({m,b,px,py},

“Point-Line
Distance (px, py), y=mx+b”,

{“m:”,”b:”,”px:”,”py:”},

{“m:
slope”,” b: y-intercept”,

“point
x”,”point y”});

LOCAL
y0;

y0:=m*px+b;

LOCAL
b1,mt,x1,y1,dist,str;

IF
m≠0 THEN

b1:=py+px/m;

mt:=[[−m,1],[1/m,1]]^-1*[[b],[b1]];

x1:=mt[1,1];

y1:=mt[2,1];

dist:=ABS((x1-px)+(y1-py)*√(-1));

ELSE

x1:=px;

y1:=b;

dist:=ABS((y1-py)*√(-1));

END;

//
print results

PRINT();

PRINT(“Results:”);

PRINT(“Intersect
point:”);

PRINT(“x:
“+STRING(x1));

PRINT(“y:
“+STRING(y1));

PRINT(“”);

IF
m≠0 THEN

str:=”Y=”+STRING(-1/m)+”*X+”+STRING(b1);

ELSE

str:=”X=”+STRING(x1);

END;

PRINT(“Orthogonal
Line:”);

PRINT(str);

PRINT(“”);

PRINT(“Minimum
Distance:”);

PRINT(dist);

RETURN
{x1,y1,str,dist};

END;

Note:

√(-1)
represents the imaginary number ⅈ ( [ Shift ], [ 2 ] ).

Inputs:

*
The slope of the y-intercept of the line y = m * x + b (no
vertical lines, but m can be zero)

*
The point (px, py)

Outputs:

*
The line that runs through point (px, yx) that is orthogonal to y = m
* x + b. The slope and y-intercept of the orthogonal line, which the
line will be stated in a string

*
The intersection point of the two lines.

*
The distance between (px, yx) and the intersection point. (dist)

Examples

Example
1:

Inputs:
Line: y = 5 x – 2, Point: (-1, -5)

m =
5

b =
-2

px =
-1

py =
-5

Results:

Intersect
point:

x =
-0.615384615386

y =
-5.07692307692

Orthogonal
Line:

Y =
-0.2 * X – 5.2

Minimum
distance:

0.392232270274

Example
2:

Inputs:
Line: y = 6, Point: (3, -9)

m =
0

b =
6

px =
3

py =
-9

Results:

Intersect
point:

x =
0.764705882353

y =
4.05882352941

Orthogonal
Line:

X =
3

Minimum
distance:

15

Example
3:

Inputs:
Line: y = 4 x + 1, Point: (5, 3)

m =
4

b =
1

px =
5

py =
3

Results:

Intersect
point:

x =
0.764705882353

y =
4.05882352941

Orthogonal
Line:

Y =
-0.25 * X + 4.25

Minimum
distance:

4.36564125066

Source


Tremblay, Christopher.
Mathematics for Game
Developers
. Thomson
Course Technology. Boston, MA. 2004. ISBN 1-59200-038-X.

Eddie

All
original content copyright, © 2011-2024. Edward Shore.
Unauthorized use and/or unauthorized distribution for commercial
purposes without express and written permission from the author is
strictly prohibited. This blog entry may be distributed for
noncommercial purposes, provided that full credit is given to the
author.

Most Popular

More from Author

Google Forms for Formative Assessment in Math Class

Cheers to a new school year that will be unlike any...

2nd Grade Subtraction Worksheet | Subtraction of 2-Digit Numbers

In 2nd grade subtraction worksheet we will solve the problems on subtraction...

S01 overview – Intellectual Mathematics

Galileo is the most overrated figure in the history of science....

Digital SAT Math Problems and Solutions (Part

Problem 1 :Store A sells raspberries for $5.50 per pint and...

- A word from our sponsors -

Read Now

Google Forms for Formative Assessment in Math Class

Cheers to a new school year that will be unlike any school year before!I know that all of us are looking at new and different plans...hybrid/synchronous/asynchronous/ fully in person/fully remote...the list goes on.   I have spent a considerable amount of time trying to figure out how I...

2nd Grade Subtraction Worksheet | Subtraction of 2-Digit Numbers

In 2nd grade subtraction worksheet we will solve the problems on subtraction of 2-digit numbers (without Regrouping), subtraction of numbers with regrouping, subtracting 1-digit number from 2-digit number with regrouping, subtracting 2-digit number with regrouping, checking subtraction with addition, subtraction is reverse of addition, addition and subtraction together, estimating the difference and...

S01 overview – Intellectual Mathematics

Galileo is the most overrated figure in the history of science. That is the thesis of Season 1 of my podcast, which consists of the following 18 episodes. Galileo bad, Archimedes good Galileo’s bumbling attempts at determining the area of the cycloid suggests a radical new interpretation of...

Digital SAT Math Problems and Solutions (Part

Problem 1 :Store A sells raspberries for $5.50 per pint and blackberries for $3.00 per pint. Store B sells raspberries for $6.50 per pint and blackberries for $8.00 per pint. A certain purchase of raspberries and blackberries would cost $37.00 at store A or $66.00 at store B. How many...

How To Find The Factors Of 20: A Simple Way

The factors of 20 are the numbers 1, 2, 4, 5, 10, 20, -1, -2, -4, -5, -10, and -20. As you can see, the total number of factors 20 has is 12. Make the following observations!The numbers 1, 2, 4, 5, 10, 20 are called positive factors of...

Addition & Subtraction Together |Combination of addition & subtraction

We will solve the different types of problems involving addition and subtraction together. To show the problem involving both addition and subtraction, we first group all the numbers with ‘+’ and ‘-‘ signs. We find the sum of the numbers with ‘+’ sign and similarly the sum of all the...

Two Back to School Ideas for Digital Classrooms

 Yep, it's a school year like no other.  If you're like me, you have some very specific back to school routines...you buy the new school supplies, you get your kids a new backpack, you prepare your bulletin boards.  There are even back to school activities that I...

Digital SAT Math Problems and Solutions (Part

Problem 1 :Each face of a fair 14-sided die is labeled with a number from 1 through 14, with a different number appearing on each face. If the die is rolled one time, what is the probability of rolling a 2? Solution : https://www.youtube.com/watch?v=PC0RAjG6Zb8 Problem 2 :A printer produces posters...

Percent of Increase Word Problems

Hello and welcome! We're focusing today on a fascinating mathematical topic: percent of increase word problems. We've got some exciting scenarios to consider and we'll walk through these calculations together. It'll be as simple as counting 1, 2, 3. Let's start! Before we start, let's be clear on...

Societal role of geometry in early civilisations – Intellectual Mathematics

Podcast: DownloadIn ancient Mesopotamia and Egypt, mathematics meant law and order. Specialised mathematical technocrats were deployed to settle conflicts regarding taxes, trade contracts, and inheritance. Mathematics enabled states to develop civil branches of government instead of relying on force and violence. Mathematics enabled complex economies in which...

Sub Plans for High School Math Class – Webquests are Perfect!

Distance learning ... hybrid learning ... asynchronous learning ...   we're all learning different terms right now!  Here is a type of activity would be great in any of these settings...Webquests!I have used these types of activities in my classroom for a number of years.  I enjoy using...

Digital SAT Math Problems and Solutions (Part

Problem 1 :A neighborhood consists of a 2-hectare park and a 35-hectare residential area. The total number of trees in the neighborhood is 3,934. The equation 2x + 35y = 3,934 represents this situation. Which of the following is the best interpretation of x in this context? A) ...