Results 1 to 2 of 2
Thread: creating lines in Java
 10282013, 04:50 PM #1Member
 Join Date
 Oct 2013
 Posts
 1
 Rep Power
 0
creating lines in Java
Hello
I`m completely new to Java and in big trouble with the following exercise.
Using JTS Topology Suite and Eclipse, I`m supposed to run a certain program to create 3 lines (LineString; a, b, c) with the coordinates (x,y) and as a result to find out which lines intersect the first line a.
This is what have:
Java Code:import com.vividsolutions.jts.geom.*; public class NewProj { public static void main(String[] args){ if (args.length % 2 == 1) { else { int i=0; // Create a new empty array of coordinates. I don`t know how I could create three separate lines, each line a, b and c has 3 pairs of x,y coordinates. I think here I am creating just one big line with all the coordinates. Coordinate[] coordinates = new Coordinate[] { new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y), }; while (i < args.length) { double x = Double.parseDouble(args[i]); double y = Double.parseDouble(args[i+1]); Coordinate newCoord = new Coordinate(x,y); coordinates[i/2] = newCoord; // System.out.println(newCoord.toString()); i=i+2; } // while // Create a new Geometry from the array of coordinates. If understand correctly this is the command that is actually taking x,y coordinates from above and joining it for a line, right? Since I`m supposed to have 3 lines, should I amend it or copy 3x somehow? LineString line = new GeometryFactory().createLineString(coordinates); Point startPoint = line.getStartPoint(); Point endPoint = line.getEndPoint(); // What do I have to write here to find out which lines intersect line a? System.out.println("Answer" + ..................()); } // else } //main }
Last edited by minaise; 10282013 at 07:57 PM.
 10282013, 05:00 PM #2Moderator
 Join Date
 Apr 2009
 Posts
 13,541
 Rep Power
 27
Similar Threads

What happens if we comment lines in java policy file?
By av1978 in forum Java AppletsReplies: 1Last Post: 09162012, 09:11 PM 
scanning lines from notepad, by creating a loop "while(input_line=NULL) {"
By noobplus in forum New To JavaReplies: 3Last Post: 03172012, 03:19 AM 
How do I make lines and graphs in java?
By TallOne in forum New To JavaReplies: 5Last Post: 01172012, 02:36 AM 
I need to truncate a file with 10 or more lines, to 10, removing the first lines
By sledjama in forum New To JavaReplies: 3Last Post: 10252011, 06:29 PM 
eliminating new lines in java
By javajames in forum New To JavaReplies: 5Last Post: 05132011, 10:55 PM
Bookmarks