Results 1 to 5 of 5
 02182011, 11:30 AM #1Member
 Join Date
 Feb 2011
 Posts
 9
 Rep Power
 0
Java Topology suit (JTS)  calculating point
Hi all
First of; sorry if I'm starting this thread in the wrong section.
I've created a line with 7 points.
Then I shall use these coordinates to make another line, but where each linesegment can't be longer than 5 units. If a linesegment is longer than 5, a new point should be added at the point.
I'm having trouble to calculate where these points should be located (well, not by hand, but when writing a code that does it).
These points should then be added together with the original coordinates in a new coordinate array to create the new line.
Would really appreciate comments and tips on how to solve this.
Java Code:import com.vividsolutions.jts.geom.*; public class NewProj { public static void main(String[] args){ // Create the original linestring Coordinate[] coordinatesToLine = new Coordinate[] { new Coordinate(12, 2), new Coordinate(12, 13), new Coordinate(12, 19), new Coordinate(19, 19), new Coordinate(20, 20), new Coordinate(25, 25), new Coordinate(27, 18) }; LineString FirstLine = new GeometryFactory().createLineString(coordinatesToLine); Point pointOne, pointTwo; double dist; int newLineLength = FirstLine.getNumPoints();//that number will be changed later double newCoorX, newCoorY; Coordinate newCoor;// 'newCoor = new Coordinate(newCoorX, newCoorY);' should be used in the second loop int points2Add; // Loop that parses the line and reads the number of points available. // it will output an integer values that gives the length of the // new line by calculating the distance between each two points. for (int counter=1; counter <= FirstLine.getNumPoints()1;counter++){ pointOne = FirstLine.getPointN(counter1); pointTwo = FirstLine.getPointN(counter); dist = pointOne.distance(pointTwo); if ( dist > 5 ){ newLineLength = newLineLength + (int)(dist / 5);//here new number of points are added } } // Here is the section where the program should calculate the new points... // I think this can be done by a loop similar to the one above. then I shall put the coordinates // in the 'newCoordinates'array. // I know that this section probably will need to be rewritten completely. It's just a try... for (int counter=1; counter <= newLineLength;counter++){ pointOne = FirstLine.getPointN(counter1); pointTwo = FirstLine.getPointN(counter); Coordinate[] newCoordinates = new Coordinate[newLineLength]; pointOne.getX();pointOne.getY(); pointTwo.getX();pointTwo.getY(); Geometry SecondLine = new GeometryFactory().createLineString(newCoordinates); if ( pointOne.getX()  pointTwo.getX() > 5 ){ newCoorX = pointOne.getX() +5; } if ( pointOne.getY()  pointTwo.getY() > 5 ){ newCoorY = pointOne.getY() +5; } System.out.println("Coordinates of SecondLine: " + SecondLine.toString()); } } }
 02182011, 03:33 PM #2can't be longer than 5 units
The intersection of a line with a circle comes to mind (where the radius is 5 units, and the line has an angle from the origin to some destination point beyond the circle).
 02212011, 07:56 AM #3Member
 Join Date
 Feb 2011
 Posts
 9
 Rep Power
 0
As in, the distance between two points?
The intersection of a line with a circle comes to mind (where the radius is 5 units, and the line has an angle from the origin to some destination point beyond the circle).
Thank's for your reply.
 02222011, 01:52 PM #4Any tips on how to implement this  in code?
 02222011, 02:54 PM #5Member
 Join Date
 Feb 2011
 Posts
 9
 Rep Power
 0
Similar Threads

calculating taxes in java
By KAM0002 in forum New To JavaReplies: 16Last Post: 12082010, 11:41 AM 
how i can do this in java main and class point
By ssssami in forum New To JavaReplies: 6Last Post: 09242010, 01:55 AM 
java floating point comparison
By sardare in forum Advanced JavaReplies: 6Last Post: 03032009, 04:11 PM 
[SOLVED] Calculating Std. Deviation using Java
By random0munky in forum New To JavaReplies: 1Last Post: 12122008, 09:24 AM
Bookmarks