Reputation: 37
I am trying to understand the following function from theparticle Supposedly, the function determines the equation of a line which is represented as an array of the coordinates for two points that lie on the line: [x1, y1, x2, y2]. The function that returns the equation is:
float [ ] getLineEquation( int [ ] line) {
float [ ] equation = new float [3];
int dx = line[2] - line[0];
int dy = line[3] - line[1];
equation[0] = -dy;
equation[1] = dx;
equation[2] = dy*line[0] - dx*line[1];
return equation;
}
I don’t understand how the 3-element array that is returned by this function corresponds to the equation of a line. I appreciate any help that will let me understand what this function is doing.
Upvotes: 3
Views: 62
Reputation: 483
A line in 2D space can be described by y = ax + b or cx + dy + e = 0. If you take the second form of the same equation than you can represent it as [c, d, e] which is your array of three elements. I hope I understood well your question.
Upvotes: 2