Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
compgeoproject/main/DrawHalfEdge.pde
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
82 lines (77 sloc)
2.13 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DrawHalfEdge { | |
public void drawline(Point v1, Point v2) { | |
//System.out.println(v1 + " " + v2); | |
line(v1.getX(), v1.getY(), v2.getX(), v2.getY()); | |
} | |
public void drawpoint(Point v) { | |
ellipse(v.getX(), v.getY(),10,10); | |
} | |
public void drawGraph(ArrayList<Point> vlist) { | |
for(Point p: vlist) { | |
drawConnectedGraph(p); | |
} | |
zoom(vlist); | |
} | |
public void drawConnectedGraph(Point p) { | |
ArrayList<HalfEdge> edges = p.getLeaving(); | |
drawpoint(p); | |
//System.out.println(p); | |
if(edges != null) { | |
for(HalfEdge edge: edges) { | |
//System.out.println(edge); | |
drawConnection(edge); | |
} | |
} | |
} | |
public void drawConnection(HalfEdge edge) { | |
//System.out.println("drawing connection"); | |
Point v2 = edge.getOrigin(); | |
Point v1 = edge.gettwin().getOrigin(); | |
drawline(v1, v2); | |
} | |
public void zoom(ArrayList<Point> vlist) { | |
float[] bounds = getbounds(vlist); | |
float[] range = getRange(bounds); //{maxx,minx,maxy,miny}; | |
float scalefactor = scalingfactor(range); | |
translate(range[0]/2, range[1]/2); // center the figure | |
scale(scalefactor); | |
} | |
public float scalingfactor(float[] range) { | |
float rangex = range[0]; | |
float rangey = range[1]; | |
float diffx = width/rangex; | |
float diffy = height/rangey; | |
return Math.min(diffx,diffy); | |
} | |
public float[] getRange(float[] bounds) { | |
float rangex = bounds[0] - bounds[1]; | |
float rangey = bounds[2] - bounds[3]; | |
float[] range = {rangex, rangey}; | |
return range; | |
} | |
public float[] getbounds(ArrayList<Point> vlist) { | |
float maxx = Float.NEGATIVE_INFINITY; | |
float maxy = Float.NEGATIVE_INFINITY; | |
float minx = Float.POSITIVE_INFINITY; | |
float miny = Float.POSITIVE_INFINITY; | |
for(Point v: vlist) { | |
float x = v.getX(); | |
float y = v.getY(); | |
if(x < minx) { | |
minx = x; | |
} | |
if(x > maxx) { | |
maxx= x; | |
} | |
if(y < miny) { | |
miny = y; | |
} | |
if(y > maxy) { | |
maxy = y; | |
} | |
} | |
float[] result = {maxx,minx,maxy,miny}; | |
return result; | |
} | |
} | |
//find lowest and highest x and y, divide by difference. |