[Solved] Is it somehow possible to check if points `x` and `y` is in a line when only the y-intercept and the slope is given? [closed]


Yes, it is possible, however, this has nothing to do with programming and is more of a mathematical question. (I would recommend going here https://math.stackexchange.com/)

Solving this using basic Algebra, given the slope and y-intercept we can check if a point is on a line by substituting the x and y values. For example, if we had a given slope of -3 and a y-intercept of 2, we would get the following equation of y = -3x + 2, if we wanted to check if the point (2, 3) was on the line we would substitute the x and y value. So it would be 3 = -3(2) + 2, and if you were to do the math you would get 3 = -4, which isn’t true. If it ended up as 3 = 3, then the point would indeed be on the line.

As I saw Java in one of the tags for the question, I will also give this solution in code:

public class Main
{
    public static void main(String[] args)
    {
        System.out.printIn(CheckPoint(-3, 2, 2, 3));
    }

    private static bool CheckPoint(float slope, float yInt, int x, int y)
    {
        //Standard form for line is y = ax + b
        if(y == (slope * x) + yInt)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

1

solved Is it somehow possible to check if points `x` and `y` is in a line when only the y-intercept and the slope is given? [closed]