Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Quickhull algorithm  RSS feed

 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, i need some help with my semester project. Τhere is the report :
I should use the quickhull algorithm in order to find the shortest path from one point to another.
You can imagine an island with a treasure and bombs.
We can only follow the path around the bombs and not among them.
I have written this code so far:


Now i want to read from a file the coordinates of the start point, the treasure
and the bombs. In the output i should show something like that: The shortest distance is 122.1687
The shortest path is: (8.0,23.0)-->(56.0,23.0)-->(130.0,28.8).

Has anyone done something like that ? I am a beginner and i really need some help !

 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a note on your post: you almost got the code tags right, but the code goes between the two tags. I fixed it for you.
 
Stephan van Hulst
Saloon Keeper
Posts: 7807
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christina,

So what are you stuck on? Do you know how to read and write from and to files?
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know if my code is correct, also i am trying to find a function that saves the path which i follow in order to reach the treasure and that will be used in the end for the output of the program.
 
Campbell Ritchie
Marshal
Posts: 55707
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't know. Please tell us what the algorithm is, and explain how the code implements that algorithm.
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok guys i found the piece of code that i was looking for ! Now i have a problem with the file from which i should read the coordinates. I don't know how to find the file's size. I have written this:
File file = new File("input1.txt");
Scanner sc = new Scanner(file);
for (int i = 0; i < N; i++) // N is an int that i have inisialized before because i don't how to write the file's size

{

int x = sc.nextInt();

int y = sc.nextInt();

Point e = new Point(x, y);

points.add(i, e); // insert points in a ArrayList<Point> points

}

Remember that the input is this:
8 23 // Beginning
130 28 // End
156 // Number of diamonds
23 108
50 99
108 107
52 54
115 107...
 
Carey Brown
Bartender
Posts: 2993
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A file's size is stored in a long and is the number of bytes in the file. This size is managed in the operating system, you can't modify it except by writing more bytes to the file. In your case knowing the file's size doesn't help because you have a varying number of characters on each line. So, by storing the number of diamonds in the third row of the file you negate any need to know the file's size in bytes (which wouldn't have helped anyway). So your N variable should be populated from the number in the third row.
 
Christina Tzogka
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thank you !
 
Junilu Lacar
Sheriff
Posts: 11144
160
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christina, when you get a chance, please read the UseCodeTags (←click on that link) wiki article so you know how to use code tags properly. There's also a "Preview" button right beside the "Submit" button that you can use to review what your message will look like before you submit it for posting.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!