Advertisement
Guest User

Untitled

a guest
Mar 7th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.vividsolutions.jts.geom.Coordinate;
  2. import com.vividsolutions.jts.geom.CoordinateArrays;
  3. import com.vividsolutions.jts.geom.GeometryFactory;
  4. import com.vividsolutions.jts.math.Vector2D;
  5. import com.vividsolutions.jts.geom.*;
  6.  
  7. // Start point
  8. double x1 = 0
  9. double y1 = 0
  10.  
  11. // Angle
  12. double angle = Math.PI / 3;
  13.  
  14. // Max distance
  15. double distance =  100
  16.  
  17. Coordinate ptStart = new Coordinate(x1, y1);
  18. Vector2D vStart = new Vector2D(ptStart);
  19. GeometryFactory gf = new GeometryFactory();
  20. Vector2D v = Vector2D.create(1, 0);
  21. v.rotate(angle);
  22. // Normalize the vector (length=1), we keep only the direction
  23. v.normalize();
  24. double targetStepLength = 10; //target step length m
  25. int stepCount = math.round(distance / targetStepLength) ;
  26. double stepLength = distance / stepCount ;
  27. // This is the translation vector
  28. v = v.multiply(stepLength);
  29.  
  30. for(int i=0; i < stepCount; i ++) {
  31.  LineSegment stepLine= new LineSegment(vStart.add(v.multiply(i)).toCoordinate(), vStart.add(v.multiply(i + 1)).toCoordinate());
  32.  LineString geom =   stepLine.toGeometry(gf);
  33.  println(geom.toString())
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement