Jump to content
  • Advertisement
Sign in to follow this  

What would you think of a 2D math library?

This topic is 2994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!