Libraries/GeometryVectored2D
From Ratwiki
Contents |
Overview - J2ME 2D vector geometry package
GeometryVectored2D is a 2D vector geometry package implemented in java (J2ME). It is useful for 2D collision detection and for operations using vectors.
Vector2D
All of the classes in the package depend on the Vector2D. This class represents a vector in 2D space with supporting utility methods like normalize(), truncate(double length), magnitude(), add(Vector2D v) etc.
Vector2D vector1 = new Vector2D(1,2); Vector2D vector2 = new Vector2D(1,2);
vector1.add(vector2);
Line2D
The Line2D class represents a line in two dimensions.
Line2D line1 = new Line2D( new Vector2D(0, 0), new Vector2D(10, 10) ); Line2D line2 = new Line2D( new Vector2D(0, 10), new Vector2D(10, 0) );
if ( line1.intersects(line2) ) { System.out.println("lines intersect"); }
Shapes - Polygon2D, Triangle2D and Circle2D
Polygon2D, Triangle2D, Circle2D are 2D representations of simple shapes, though Circle2D is only partially implemented at this time.
All of these classes have contains(Vector2D point) and intersects(Line2D line) methods as well as some other methods for checking intersection of shapes against each other.
Polygon2D polygon = new Polygon2D();
polygon.addVertex( new Vector2D(0, 0) ); polygon.addVertex( new Vector2D(0, 10) ); polygon.addVertex( new Vector2D(10, 10) ); polygon.addVertex( new Vector2D(10, 0) );
polygon.rotate( Math.PI / 2 );
if ( polygon.contains( new Vector2D(5,5) ) ) { System.out.println("point contained withing polygon"); }
More information
See the vector geometry javadoc for more information on how to use the package.
Download
| File | Description | Link |
|---|---|---|
| Jar file | Binary package required containing library. | GeometryVectored2D-1.0.0.jar |
| Source code | Source package containing the J2ME source code, build scripts and javadoc | GeometryVectored2D-1.0.0-src.zip |
| Javadoc | Javadoc for source code | GeometryVectored2D-1.0.0-javadoc.zip |