Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add files via upload
Creates random arrangement of lines in a bounding box only, no halfedges used.
- Loading branch information
Showing
1 changed file
with
172 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
class HalfEdge { | ||
|
||
Node origin; | ||
Node next; | ||
Node prev; | ||
HalfEdge twin; | ||
Face face; | ||
|
||
public HalfEdge(Node o, Node n, Node p, HalfEdge t, Face f){ | ||
origin = o; | ||
next = n; | ||
prev = p; | ||
twin = t; | ||
face = f; | ||
} | ||
|
||
|
||
} | ||
|
||
class Node{ | ||
int x_coord; | ||
int y_coord; | ||
HalfEdge arbitrary_outgoing; | ||
|
||
public Node(int x, int y, HalfEdge a_o){ | ||
x_coord = x; | ||
y_coord = y; | ||
arbitrary_outgoing = a_o; | ||
} | ||
|
||
} | ||
|
||
class Face{ | ||
HalfEdge inc_edge; | ||
|
||
public Face(HalfEdge he){ | ||
inc_edge = he; | ||
} | ||
} | ||
|
||
int num_lines = int(random(4, 8)); | ||
|
||
int[][] list_of_lines = new int[num_lines][4]; | ||
|
||
|
||
|
||
|
||
void setup(){ | ||
size(800, 800); | ||
frameRate(60); | ||
background(0, 0, 0); | ||
for(int i = 0; i < num_lines; i++){ | ||
stroke(255, 255, 255); | ||
int side1 = int(random(1,5)); | ||
int side2 = side1; | ||
|
||
while ( side2 == side1){ | ||
side2 = int(random(1,5)); | ||
} | ||
|
||
int x1 = int(random(0, width + 1)); | ||
int y1 = int(random(0, height + 1)); | ||
int x2 = int(random(0, width + 1)); | ||
int y2 = int(random(0, height + 1)); | ||
|
||
if (side1 == 1) | ||
y1 = 0; | ||
|
||
if (side1 == 2) | ||
x1 = width; | ||
|
||
if (side1 == 3) | ||
y1 = height; | ||
|
||
if (side1 == 4) | ||
x1 = 0; | ||
|
||
/////////////////// | ||
|
||
if (side2 == 1) | ||
y2 = 0; | ||
|
||
if (side2 == 2) | ||
x2 = width; | ||
|
||
if (side2 == 3) | ||
y2 = height; | ||
|
||
if (side2 == 4) | ||
x2 = 0; | ||
|
||
|
||
if( i == 0 ){ | ||
|
||
line(x1, y1, x2, y2); | ||
list_of_lines[i][0] = x1; | ||
list_of_lines[i][1] = y1; | ||
list_of_lines[i][2] = x2; | ||
list_of_lines[i][3] = y2; | ||
|
||
} | ||
|
||
|
||
else{ | ||
|
||
int hasIntersect = 0; | ||
|
||
for (int k = 0; k < i; k++){ | ||
|
||
if (checkLineIntersect(x1, y1, x2, y2, list_of_lines[k][0], list_of_lines[k][1], list_of_lines[k][2], list_of_lines[k][3]) == true){ | ||
|
||
hasIntersect = 1; | ||
break; | ||
} | ||
|
||
} | ||
|
||
if (hasIntersect == 1){ | ||
|
||
line(x1, y1, x2, y2); | ||
list_of_lines[i][0] = x1; | ||
list_of_lines[i][1] = y1; | ||
list_of_lines[i][2] = x2; | ||
list_of_lines[i][3] = y2; | ||
|
||
}else{ | ||
|
||
i--; | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
} | ||
|
||
boolean checkLineIntersect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){ | ||
|
||
int orientation1 = ccw( x1, y1, x2, y2, x3, y3); | ||
int orientation2 = ccw( x1, y1, x2, y2, x4, y4); | ||
int orientation3 = ccw( x3, y3, x4, y4, x1, y1); | ||
int orientation4 = ccw( x3, y3, x4, y4, x2, y2); | ||
|
||
if((orientation1 != orientation2) && (orientation3 != orientation4)){ | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
|
||
int ccw(int point1_x, int point1_y, int point2_x, int point2_y, int point3_x, int point3_y){ | ||
|
||
float returnVal = (float)(point2_y - point1_y)/(point2_x - point1_x) - (float)(point3_y - point2_y)/(point3_x - point2_x); //<>// | ||
|
||
if (returnVal > 0) | ||
return 1; | ||
|
||
else if (returnVal == 0) | ||
return 0; | ||
|
||
else if (returnVal < 0) | ||
return -1; | ||
|
||
else | ||
return 2; //error code | ||
} | ||
|
||
|
||
|
||
void draw(){ | ||
|
||
} |