Sign in to follow this  
sheep19

What would you think of a 2D math library?

Recommended Posts

I had the idea of developing my own 2D math library (points, lines, segments, circles, triangles [+all shapes that can be made of lines ->this can be done manually]). I have almost completed the Line class: The line is of type: Ax+By+C=0 It has the following member functions:
// constructors -- A line can be formed by setting a, b, c manually or by proving two points it passes from
Line(const float _a = 0, const float _b = 1, const float _c = 0);
Line(const Point2D &p1, const Point2D &p2);

float Gradient() const;

// returns x when y is given, e.g if the line is 10x+2y+30=0 and y = 4,
//x = (-2*4-30)/10 = ...
float x(const float y) const;
// as above
float y(const float x) const;

float DistanceFromPoint(const float px, const float py) const;
float DistanceFromPoint(const Point2D &p) const;

// LINE_POSITION is an enumeration.returns:
// 1)paraller
// 2)identical
// 3)intersect		
LINE_POSITION LinePosition(const Line &ln) const;
// converts LINE_POSITION to an std::string
static std::string LinePositionToString(const LINE_POSITION lnPos);

		// returns the interesection point of 2 lines
Point2D Interesection(const Line &ln) const;
		
Point2D InteresectionToX() const; // interesection point with x axis
Point2D InteresectionToY() const;

float CornerBetweenLines(const Line &ln) const;

// e.g "30x+50y+10=0"
std::string Equation() const;
What do you think of the class? Would you find it useful in your projects? ~Minas

Share this post


Link to post
Share on other sites
IMO, if you need the library, write it. If you don't, don't. If you think what you've written can be helpful to others, there are many ways to share your ideas, one of which being producing a library.

EDIT: Were you aware of CML? It sounds like you're going for a different audience, but it's always good to know your competition.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this