Created
June 11, 2012 15:48
-
-
Save mazbox/2910777 to your computer and use it in GitHub Desktop.
Openframeworks Line Equation class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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