diff --git a/2019/sketch_190405a/sketch_190405a.png b/2019/sketch_190405a/sketch_190405a.png new file mode 100644 index 00000000..e018513a Binary files /dev/null and b/2019/sketch_190405a/sketch_190405a.png differ diff --git a/2019/sketch_190405a/sketch_190405a.pyde b/2019/sketch_190405a/sketch_190405a.pyde new file mode 100644 index 00000000..27d2cef8 --- /dev/null +++ b/2019/sketch_190405a/sketch_190405a.pyde @@ -0,0 +1,98 @@ +""" +Terrain Box +""" + +add_library('peasycam') +from third_point import third_point + +L, H = 100, 100 +A, B, C, D = H + 50, H + 0, H + 10, H + 20 + +def setup(): + global cam + size(700, 500, P3D) + cam = PeasyCam(this, 660) + fill(255, 100) + +def draw(): + background(200) + # ortho() + strokeWeight(2) + stroke(0) + translate(0, 0, -100) + faces_3D() + cam.beginHUD() + translate(100, 50) + top_2D() + translate(0, 400) + faces_2D() + cam.endHUD() + + +def faces_3D(): + # floor + beginShape() + vertex(0, 0, 0) + vertex(L, 0, 0) + vertex(L, L, 0) + vertex(0, L, 0) + endShape(CLOSE) + + beginShape() + vertex(0, 0, B) + vertex(L, 0, C) + vertex(L, 0, 0) + vertex(0, 0, 0) + endShape(CLOSE) + + beginShape() + vertex(0, 0, B) + vertex(0, L, A) + vertex(0, L, 0) + vertex(0, 0, 0) + endShape(CLOSE) + + stroke(200, 200, 0) + line(0, 0, B, L, L, D) + stroke(0) + line(L, 0, C, L, L, D) + line(0, L, A, L, L, D) + stroke(0, 0, 200) + line(L, L, 0, L, L, D) + +def faces_2D(): + beginShape() + vertex(0, -B) + vertex(L, -C) + vertex(L, 0) + vertex(0, 0) + endShape(CLOSE) + b = PVector(0, -B) + c = PVector(L, -C) + bc = PVector.dist(b, c) #(0, 0, -B, L, 0, -C) + + bd = dist(0, 0, B, L, L, D) + cd = dist(L, 0, C, L, L, D) + d = third_point(b, c, bd, cd) + stroke(200, 200, 0) + line(b.x, b.y, d.x, d.y) + stroke(0) + line(c.x, c.y, d.x, d.y) + + ab = dist(0, A, L, B) + ad = dist(0, A, L, D) + a = third_point(b, d, ab, ad) + stroke(0) + line(b.x, b.y, a.x, a.y) + line(d.x, d.y, a.x, a.y) + +def top_2D(): + stroke(0) + rect(0, 0, L, L) + stroke(200, 200, 0) + line(0, 0, B, L, L, D) + stroke(0) + line(L, 0, C, L, L, D) + line(0, L, A, L, L, D) + stroke(0) + line(L, L, 0, L, L, D) diff --git a/2019/sketch_190405a/third_point.py b/2019/sketch_190405a/third_point.py new file mode 100644 index 00000000..ed8e409e --- /dev/null +++ b/2019/sketch_190405a/third_point.py @@ -0,0 +1,51 @@ +""" +Code From +https://stackoverflow.com/questions/4001948/drawing-a-triangle-in-a-coordinate-plane-given-its-three-sides +""" + +class CirclesSeparate(BaseException): + pass + +class CircleContained(BaseException): + pass + +def third_point(PVector_a, PVector_b, ac_length, bc_length): + """ + Find PVector_c given: + PVector_a + PVector_b + ac_length + bc_length + + PVector_d == PVector at which the right-angle to c is formed. + """ + ab_length = PVector_a.dist(PVector_b) + if ab_length > (ac_length + bc_length): + raise CirclesSeparate("Given sides do not intersect!") + elif ab_length < abs(ac_length - bc_length): + raise CircleContained("The circles around the points do not intersect") + + # get the length to the vertex of the right triangle formed, + # by the intersection formed by circles a and b + ad_length = (ab_length**2 + ac_length**2 - bc_length**2)/(2.0 * ab_length) + + # get the height of the line at a right angle from a_length + h = sqrt(abs(ac_length**2 - ad_length**2)) + + # Calculate the mid PVector (PVector_d), needed to calculate PVector_c(1|2) + d_x = PVector_a.x + ad_length * (PVector_b.x - PVector_a.x)/ab_length + d_y = PVector_a.y + ad_length * (PVector_b.y - PVector_a.y)/ab_length + PVector_d = PVector(d_x, d_y) + + # get PVector_c location + # --> get x + c_x1 = PVector_d.x + h * (PVector_b.y - PVector_a.y)/ab_length + c_x2 = PVector_d.x - h * (PVector_b.y - PVector_a.y)/ab_length + + # --> get y + c_y1 = PVector_d.y - h * (PVector_b.x - PVector_a.x)/ab_length + c_y2 = PVector_d.y + h * (PVector_b.x - PVector_a.x)/ab_length + + PVector_c1 = PVector(c_x1, c_y1) + PVector_c2 = PVector(c_x2, c_y2) + return PVector_c1 #, PVector_c2