#------------------------------------------------------------------ # 3D world using orthographic projection # Material on pages 414-415 of the Companion # Copyright (C) 2019 Dr. William T. Verts # Uses the graphics library developed in Lab #3 #------------------------------------------------------------------ import math from Graphics import * Origin2D = [0,0] Scale2D = 1.0 def SetOrigin (X,Y): global Origin2D Origin2D = [X,Y] return def SetScale2D (N): global Scale2D Scale2D = N return Cosine = math.cos(math.radians(30)) Sine = math.sin(math.radians(30)) def Project3D (P3D): # P3D is a list [X,Y,Z] global Origin2D,Scale2D X = Origin2D[0] + (P3D[0] + P3D[2] * Cosine) * Scale2D Y = Origin2D[1] - (P3D[1] + P3D[2] * Sine) * Scale2D return [X,Y] def addLine3D (Canvas, X1,Y1,Z1,X2,Y2,Z2,Color=black): P1 = Project3D([X1,Y1,Z1]) # P1 is [X,Y] P2 = Project3D([X2,Y2,Z2]) # P2 is [X,Y] addLine(Canvas, P1[0],P1[1],P2[0],P2[1],Color) return def addHouse (Canvas, X, Y, Z, Color=black): def Line (X1,Y1,Z1,X2,Y2,Z2): addLine3D(Canvas, X+X1,Y+Y1,Z+Z1, X+X2,Y+Y2,Z+Z2, Color) return Line(0,0,0, 6,0,0) # Front of House Line(6,0,0, 6,3,0) Line(6,3,0, 3,5,0) Line(3,5,0, 0,3,0) Line(0,3,0, 0,0,0) Line(0,0,6, 6,0,6) # Back of House Line(6,0,6, 6,3,6) Line(6,3,6, 3,5,6) Line(3,5,6, 0,3,6) Line(0,3,6, 0,0,6) Line(0,0,0, 0,0,6) # Connecting Front to Back Line(6,0,0, 6,0,6) Line(6,3,0, 6,3,6) Line(3,5,0, 3,5,6) Line(0,3,0, 0,3,6) return