Skip to content
Search

Linear equation

lastmod 2023-02-02created 2014-09-0318 edits

A linear equation (also called a first-degree equation) is an equation whose highest-degree term has degree 1.

Category

Drawing on the coordinate plane

The most general form of the equation of a line is as follows.

Ax + By + C = 0

Given the gradient m and the y-intercept b, the equation of the line is determined as follows.

y = mx + b

Given two distinct points (x1,y1),(x2,y2), the equation of the line is determined as follows.

(x2 − x1)(y − y1) = (y2 − y1)(x − x1)

If x1 ≠ x2, it can be written as follows.

y - y1 = (y2 − y1) / (x2 − x1) * (x − x1)

It can be obtained as an expression using the slope and y-intercept as follows.

y = mx + b
단, m = (y2 − y1) / (x2 − x1), b = (y2 − y1) / (x2 − x1) * (− x1) + y1

INFORMATION

For reference, the slope is tanθ

General Form

The general form of a linear equation is as follows.

Ax + By + C = 0

in one step by simply using the formula:

(y1 - y2)x + (x2 - x1)y + (x1y2 - x2y1) = 0

Python code

class GeneralForm:
    """
    Ax + By + C = 0
    """

    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c

    @classmethod
    def from_points(cls, x1, y1, x2, y2):
        """
        (y1 - y2)x + (x2 - x1)y + (x1y2 - x2y1) = 0
        """
        a = y1 - y2
        b = x2 - x1
        c = (x1 * y2) - (x2 * y1)
        return cls(a, b, c)

    def calc_x(self, y):
        return -1 * ((self.b * y) + self.c) / self.a

    def calc_y(self, x):
        return -1 * ((self.a * x) + self.c) / self.b

    @property
    def slope(self):
        return -1 * (self.a / self.b)

See also

Favorite site

Intersection point of two lines

References


  1. Wikipedia_linear_equation.pdf ↩

  2. Wikipedia_linear_equation_ko.pdf ↩

  3. Line_to_point.zip ↩

  4. Linear_equation.pdf ↩

author Zer0 sitemap