# 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);

// 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 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627752
• Total Posts
2978922

• 10
• 10
• 22
• 14
• 14