Date: May 20 2020
Summary: An explanation on how to find a line that fits to two points
Keywords: ##zettel #algebra #line #point #slope #formula #archive
Not Available
Let , , where and are two points of interest and is either or . The algorithm for determining the line that contains points and utilizes the Point-Slope Formula:
Can be rewritten such that
To define the slope of the line in question. To generalize this to a generic solution, one reevaluates for the point slope formula using and as general terms:
To produce the final generic equation, reorganizing yields:
using Plots
gr()
# Utilizing an implicit return from the generic function
y(x, x_1, y_1, x_2, y_2) = x .* (y_2 - y_1) ./ (x_2 - x_1) .- x_1 .* (y_2 - y_1) ./ (x_2 - x_1) .+ y_1
input = -5:5
output = y(input, 2, -1, 0, 3)
plot(input,
output,
framestyle=:zerolines,
label="Fitted Line",
title="Line Fitting Two Points",
xlim=(-5, 5),
ylim=(-5, 5)
)
scatter!((2, -1), label="Point 1", marker=5)
scatter!((0, 3), label="Point 2", marker=5)
Zelko, Jacob. Finding a Line Which Contains Two Points. https://jacobzelko.com/05202020224416-line-two-points. May 20 2020.