Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.vividsolutions.jts.geom.Coordinate;
- import com.vividsolutions.jts.geom.CoordinateArrays;
- import com.vividsolutions.jts.geom.GeometryFactory;
- import com.vividsolutions.jts.math.Vector2D;
- import com.vividsolutions.jts.geom.*;
- // Start point
- double x1 = 0
- double y1 = 0
- // Angle
- double angle = Math.PI / 3;
- // Max distance
- double distance = 100
- Coordinate ptStart = new Coordinate(x1, y1);
- Vector2D vStart = new Vector2D(ptStart);
- GeometryFactory gf = new GeometryFactory();
- Vector2D v = Vector2D.create(1, 0);
- v.rotate(angle);
- // Normalize the vector (length=1), we keep only the direction
- v.normalize();
- double targetStepLength = 10; //target step length m
- int stepCount = math.round(distance / targetStepLength) ;
- double stepLength = distance / stepCount ;
- // This is the translation vector
- v = v.multiply(stepLength);
- for(int i=0; i < stepCount; i ++) {
- LineSegment stepLine= new LineSegment(vStart.add(v.multiply(i)).toCoordinate(), vStart.add(v.multiply(i + 1)).toCoordinate());
- LineString geom = stepLine.toGeometry(gf);
- println(geom.toString())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement