Search code examples
pythonmathdiagramprojection

How can I Draw rectangle in programmatically


How can I draw rectangle(Oblique projection view) in programmatically(python) by giving height, width and depth.


Solution

  • Take a look at Python's turtle module, here is the v3.3 documentation. On top of height, width and depth, you will need to think about an angle for the projection - I think this is typically 30/45 degrees.

    To get you started... adapting code by Y. Daniel Liang.

    import turtle
    
    w = 100
    h = 50
    d = 20
    angle = 30
    
    def drawRectangle(width, height): 
        turtle.right(90)
        turtle.forward(height)
        turtle.right(90)
        turtle.forward(width)
        turtle.right(90)
        turtle.forward(height)
        turtle.right(90)
        turtle.forward(width)
    
    turtle.penup() 
    turtle.goto(0, 0)
    turtle.pendown()
    drawRectangle(w, h)
    turtle.left(angle)
    turtle.forward(d)
    turtle.right(angle)
    drawRectangle(w, h)