typedef struct {
double a; // coefficient for x
double b; // coefficient for y
double c; // constant term
} line;
points_to_line(point p1, point p2, line *l)
{
if (p1[X] == p2[X]) {
l->a = 1;
l->b = 0;
l->c = -p1[X];
} else {
l->b = 1;
l->a = -(p1[Y]-p2[Y])/(p1[X]-p2[X]);
l->c = -(l->a * p1[X]) - (l->b * p1[Y]);
}
I’m reading Programming Challenges book by (Steven S. Skiena and Miguel Revilla), maybe someone should have been read this book.
p1[X] is point p1’s X value, and [Y] is Y value.
This function makes a linear equation line. (line *l)
First If sentense makes x + C (p1[X]) = 0 to l.
What I don’t know is:
-
In C language, how can I represent
p1[X]?? -
Is
p1a one dimentional array? then,XandYis constant macro?? -
Or, using C++, Is this a overloaded operator[] ?? then, point type has overloaded operator[]???
-
Or is there point type in C?? I searched google “point type C” and, I found nothing.
Assuming it is C code, as
p1is accessed with[]operator, my guess ispointtype is likely to be atypedefto an array.I think it is
doublebecause(p1[Y]-p2[Y])/(p1[X]-p2[X])expression is written withoutdoublecasts.