I am doing a Jarvis' march (wrapping) program, in which I need to return a set of the points on the convex hull. I am getting the correct points, for example [L0, L1, L2] but it needs to be ["L1", "L2", "L3"].
When adding the results to the set, I have used "\"" + temp.point + "\"" and also '"' + temp.point + '"', but they both end up swapping my final results.
public static Set<String> getBoundary (String sectorFile){
Set<String> points = new HashSet<>();
public static Set<String> getBoundary(String sectorFile){
Set<String> points=new HashSet<>();
Set<Point> vals=new HashSet<>();
Vector<Point> hull=new Vector<Point>();
try(Scanner s=new Scanner(new File(sectorFile))){
s.useDelimiter("[\\\\|\\n\\r]+");
while(s.hasNext()){
String point=s.next();
double x=s.nextDouble();
double y=s.nextDouble();
Point xy=new Point(point,x,y);
xy.setPoint(point);
xy.setX(x);
xy.setY(y);
vals.add(xy);
}
Point[]values=new Point[vals.size()];
vals.toArray(values);
int l=0;
for(int i=1;i<vals.size();i++)
if(values[i].x<values[l].x)
l=i;
// Start from leftmost point, keep moving
// counterclockwise until reach the start point
int p=l,q;
do
{
// Add current point to result
hull.add(values[p]);
q=(p+1)%vals.size();
for(int i=0;i<vals.size();i++)
{
if(orientation(values[p],values[i],values[q])==2)
q=i;
}
p=q;
}while(p!=l); // While we don't come to first
// point
for(Point temp:hull)
points.add(temp.point);
}catch(FileNotFoundException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
return points;
}
private static class Point
{
String point;
double x, y;
Point(String point, double x, double y){
this.point = point;
this.x=x;
this.y=y;
}
private void setPoint(String i) {
this.point = i;
}
private void setX (double x) {
this.x = x;
}
private void setY (double y) {
this.y = y;
}
}
Expected
["L0", "L1", "L2"]
Actual
["L2", "L1", "L0"]