Jngen provides two point classes: Point with long long coordinates and Pointf with long double coordinates. Standard operations like addition, subtraction, dot and cross products are supported. Similarly, classes Polygon and Polygonf are provided. A special class GeometryRandom is used for generating objects, all interaction goes via its global instance rndg.
Point is basically a structure with two fields: x and y. Polygon is basically an Array of Points.
Like most Jngen objects, Point and Polygon can be printed to streams and modified with output modifiers.
If you are looking for an SVG drawing tool, please refer to this page.
- Returns: random point with coordinates between 0 and C, inclusive.
- Returns: random point with coordinates between min and max, inclusive.
- Returns: random point with x-coordinate between x1 and x2 and y-coordinate between y1 and y2, inclusive.
- Returns: random convex polygon with n vertices and coordinates lying in specified range.
- No three consecutive vertices lie on the same line, no two points coincide.
- Polygon is generated like following: convex hull of 10n random points on an ellipse is taken, then n points are randomly selected from it.
- Throws if the are less than n points on the above convex hull.
TArray<Point> pointsInGeneralPosition(int n, long long x1, long long y1, long long x2, long long y2)
- Returns: n random points such that no two coincide and no three lie on the same line.
- Complexity: O(n2 log n).
Here is the list of operators supported for Point and Pointf. All of them are declared const, excluding those which explicitly modify their arguments.
- p1 + p2, p1 += p2: coordinate-wise addition;
- p1 - p2, p1 -= p2: coordinate-wise subtraction;
- p * x, p *= x: coordinate-wise multiplication with scalar value;
- p1 * p2: dot product (p1.x * p2.x + p1.y * p2.y);
- p1 % p2: cross product (p1.x * p2.y - p1.y * p2.x);
- p1 == p2, p1 != p2: coordinate-wise equality comparison;
- p1 < p2: lexicographical coordinate-wise ordering.
For Pointf comparisons of floating point values are done with eps presision. The default value is 10-9. It can be overridden with setEps function.
Polygon inherits TArray<Point> so has it supports standard Array methods like .sort(), .choice() and so on. However, it provides a couple of additional methods.
- Shift the polygon by given vector, i.e. add vector to each vertex of a polygon.
- Reflect the polygon across the x = -y line, i.e. replace point (x, y) with (-x, -y).