# creating lines in Java

• 10-28-2013, 05:50 PM
minaise
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:

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        }```
Any help much appreciated!!!
• 10-28-2013, 06:00 PM
Tolls
Re: creating lines in Java
When posting code please wrap it in [code] tags [/code].

And also show what the problem is (and if it's in that awful light blue then you need to remove the colour tags, as that's unreadable).