1

Slope Calculator

If the 2 Points are Known

If 1 Point and the Slope are Known
OR

Math

Core Functions of the Slope Calculator

The provided code is designed to be a dual-purpose utility that handles two primary geometric scenarios.

1. The Two-Point Determination

The first core function utilizes the fundamental slope formula:

$$ m = \frac{y_2 - y_1}{x_2 - x_1} $$

The code takes four inputs ($x_1, y_1$ and $x_2, y_2$), calculates the difference between the vertical coordinates, divides it by the difference between the horizontal coordinates, and outputs the resulting gradient ($m$).

2. The Point-Slope and Trigonometric Function

It allows users to find the "missing" coordinates of a second point when they only have one starting location. It can calculate this based on:

  • The Slope ($m$): Using a known rate of change.
  • The Angle ($\theta$): Utilizing trigonometry ($\tan(\theta) = \text{slope}$) to find the direction.
  • Distance ($d$): Using the distance formula or Pythagorean theorem to plot exactly where the next point should land along that line.

3. Visual Rendering (The Canvas)

Unlike basic calculators, this code includes a element with the ID lineChart. This indicates that the core functionality isn't just numerical; it is visual. The calculator is designed to take the calculated coordinates and draw the resulting line on a grid, providing immediate visual feedback to the user.


How to Use This Slope Calculator

This tool is designed to be intuitive. Depending on the information you have at hand, follow these steps:

Scenario A: You have two sets of coordinates

  • Step 1: Locate the section titled "If the 2 Points are Known."
  • Step 2: Enter the coordinates of your first point into the $X_1$ and $Y_1$ boxes.
  • Step 3: Enter the coordinates of your second point into $X_2$ and $Y_2$.
  • Step 4: Click "Calculate." The slope will appear below the button, and the line will be drawn on the graph.

Scenario B: You have one point and a direction

  • Step 1: Locate the section titled "If 1 Point and the Slope are Known."
  • Step 2: Enter your starting point ($X_1, Y_1$) and the Distance ($d$) you want to travel along the line.
  • Step 3: Enter either the Slope ($m$) OR the Angle of Incline ($\theta$). You do not need both.
  • Step 4: Click "Calculate." The tool will determine the coordinates of the second point and render the line.

Resetting the Tool

If you make a mistake or want to start a new calculation, simply click the "Clear" button. This will wipe the input fields and trigger the clearChart() function to erase the drawing from the canvas, giving you a fresh start.

Published
2026-05-10 11:22:30
Author
Taylor Bennett