That is... not a question.
You are being given lines in
Standard Form, Ax + By = C.
I would suggest reading an article such as this:
http://courses.wccnet.edu/~palay/precalc/22mt01.htm
It seems to explain the basics pretty well.
Your first two methods are determining whether or not a line is vertical or horizontal, respectively.
To tackle this, you first need to know what a vertical line looks like in standard form.
An example of a vertical line is
x = 4. Notice that it doesn't depend on
y at all.
An example of a horizontal line is
y = 3. Notice that it doesn't depend on
x at all.
From this, we can deduce that if a line doesn't depend on
y, then
B must be equal to 0:
1x + 0y = 4 --> 1x = 4
If a line doesn't depend on
x, then
A must be equal to 0:
0x + 1y = 3 --> 1y = 3
From this, we can conclude that
if a line is vertical, B = 0, and if a line is horizontal, A = 0.
Do you know how to write this statement in code? I'll start it off for you.
1 2 3 4 5 6 7
|
bool Line::vertical()
{
if ( /* B is equal to 0 */)
return true;
else
return false;
}
|
For completeness, you would also check for the degenerate form where both A and B are equal to 0, which is not a valid line. But I wouldn't worry about that for now.
__________________
To get the slope of a line in standard form, Ax + By = C,
you need to tranform it into slope-intercept form,
y = mx + b (note: lowercase b is not the same as B).
m is then the slope, and
b is the y-intercept.
Ax + By = C
By = C - Ax
y = (C/B) - (A/B) x
y = -(A/B)x + (C/B)
The slope is
-A/B.