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:
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
Scenario B: You have one point and a direction
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.