Skip to content

Instantly share code, notes, and snippets.

@mazbox
Created June 11, 2012 15:48
Show Gist options
  • Save mazbox/2910777 to your computer and use it in GitHub Desktop.
Save mazbox/2910777 to your computer and use it in GitHub Desktop.
Openframeworks Line Equation class
class LineEquation {
public:
float m;
float c;
void setFrom2Points(ofVec2f a, ofVec2f b) {
ofVec2f g = b - a;
float m = g.y / g.x;
// y = mx + c
// so c = y - mx
float c = a.y - m*a.x;
set(m, c);
}
void set(float m, float c) {
this->m = m;
this->c = c;
}
float getY(float x) {
return m*x + c;
}
float getX(float y) {
return (y-c)/m;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment