Horizontal and Vertical Distance

Introduction

Welcome to Distance on the Coordinate Plane, the third course in our Pythagorean Theorem learning path! In the previous two courses, you built a solid understanding of right triangles and learned how to solve for unknown sides. Now it's time to put those skills to work in one of the most practical settings in math: the coordinate plane.

This first lesson focuses on horizontal and vertical distance, the simplest kinds of distance between two points. Mastering these will set the stage for everything else in this course, including diagonal distances and the famous distance formula. Let's dig in.

Thinking in Terms of a Grid

Imagine standing at a street intersection in a city laid out on a perfect grid. If a friend tells you they are seven blocks east and zero blocks north, you immediately know the distance: seven blocks. You didn't need any fancy formula; you just compared positions along one direction.

The coordinate plane works the same way. Every point has an xx-coordinate (horizontal position) and a yy-coordinate (vertical position). When two points share one of those coordinates, the distance between them lies entirely along a single axis, and finding it is as simple as comparing the coordinate that differs.

Horizontal Distance

Two points have a purely horizontal separation when their yy-coordinates are the same. For example, consider the points (2,5)(2, 5) and (9,5)(9, 5). Both sit at y=5y = 5, so the segment connecting them is a flat, horizontal line.

To find the distance, subtract the xx-coordinates:

9−2=79 - 2 = 7

The horizontal distance is 7 units. Notice that you only needed the xx-values because the yy-values matched.

Coordinate plane showing horizontal distance of 7 units between (2, 5) and (9, 5)

Vertical Distance

The same idea applies vertically. Two points have a purely vertical separation when their xx-coordinates are the same. Take (3,1)(3, 1) and (3,8)(3, 8). Both share x=3x = 3, so the segment connecting them is a straight, vertical line.

Coordinate plane showing vertical distance of 7 units between (3, 1) and (3, 8)

To find the distance, subtract the yy-coordinates:

8−1=78 - 1 = 7

The vertical distance is 7 units. Once again, only the coordinate that changes matters.

Crossing an Axis: Why Sign Doesn't Change Distance

Things get more interesting when points sit on opposite sides of an axis. Consider (3,4)(3, 4) and (3,−7)(3, -7). If you subtract without thinking about sign, you might write:

−7−4=−11-7 - 4 = -11

A negative result! But distance is always a positive quantity. You handle this by taking the absolute value of the difference:

∣−7−4∣=∣−11∣=11|{-7 - 4}| = |{-11}| = 11

The vertical distance is 11 units. Intuitively, the point at y=4y = 4 is 4 units above the xx-axis and the point at y=−7y = -7 is 7 units below it, so the total gap is 4+7=114 + 7 = 11. The absolute value of the subtraction gives you exactly that total.

Coordinate plane showing vertical distance of 11 units between (3, 4) and (3, -7)

The General Pattern

You can now state a clean rule for axis-aligned distances between any two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2):

  • Horizontal distance (same yy): ∣x2−x1∣|x_2 - x_1|
  • Vertical distance (same xx): ∣y2−y1∣|y_2 - y_1|

The absolute value ensures the result is positive no matter which point you subtract from which, and no matter which quadrants the points occupy. Here are a few quick examples:

Point APoint BSubtractionDistance
(2,5)(2, 5)(9,5)(9, 5)∣9−2∣=7\lvert 9 - 2 \rvert = 77 units (horizontal)
(−1,2)(-1, 2)(4,2)(4, 2)∣4−(−1)∣=5\lvert 4 - (-1) \rvert = 55 units (horizontal)
(3,4)(3, 4)(3,−7)(3, -7)∣−7−4∣=11\lvert -7 - 4 \rvert = 1111 units (vertical)

Notice the second row: subtracting a negative coordinate, 4−(−1)4 - (-1), turns into addition, 4+1=54 + 1 = 5. This is exactly the "crossing the axis" effect at work.

Subtraction Order Does Not Matter

One last detail worth highlighting: the order of subtraction is completely up to you when absolute value is involved. Whether you compute ∣9−2∣|9 - 2| or ∣2−9∣|2 - 9|, the answer is the same: 77. So feel free to subtract in whichever order feels natural. The absolute value will always keep the result positive.

This flexibility is especially handy when points have negative coordinates. For instance, with (−1,2)(-1, 2) and (4,2)(4, 2), you could compute ∣4−(−1)∣=5|4 - (-1)| = 5 or ∣−1−4∣=∣−5∣=5|{-1} - 4| = |{-5}| = 5. Either way, you arrive at the correct horizontal distance of 5 units.

Conclusion and Next Steps

In this lesson, you learned that horizontal and vertical distances on the coordinate plane come down to a single subtraction and an absolute value. When two points share a yy-coordinate, compare their xx-values; when they share an xx-coordinate, compare their yy-values. The absolute value guarantees a positive distance even when points span across an axis into negative territory.

As you may recall from earlier courses, the Pythagorean theorem connects two perpendicular sides to a hypotenuse — and the horizontal and vertical distances you just practiced are exactly those perpendicular sides. In the next lesson, you will use them to build right triangles between any two points on the plane, but first, it's time to put today's skills into action with some hands-on practice exercises!

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal