Skip to content

Customize the perspective #746

Answered by johannes-wolf
idoric asked this question in Q&A
Nov 10, 2024 · 1 comments · 7 replies
Discussion options

You must be logged in to vote

Ah ok, you may want something like this:

#import "@preview/cetz:0.3.1"
#cetz.canvas({
  import cetz.draw: *

  grid((-1,-1), (12,4))

  let cube(pos) = scope({
    stroke(red + 2pt)
    set-origin(pos)

    on-xz({
      rect((0,0), (2,2))
      rect((0,0,-2), (2,2,-2))
    })
    
    rect((0,0), (2,2))
    rect((0,0,2), (2,2,2))
  })

  let persp(a, c: calc.sqrt(2)/2) = {
    set-transform(
      ((1, 0, calc.cos(a) * c,0),
       (0,-1,-calc.sin(a) * c,0),
       (0, 0, 0,  0),
       (0, 0, 0,  1)))
  }

  persp(45deg)
  cube((0,0))

  persp(45deg, c: .5)
  cube((4,0))
  
  persp(30deg)
  cube((8,0))
})

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@idoric
Comment options

@johannes-wolf
Comment options

@idoric
Comment options

@johannes-wolf
Comment options

Answer selected by idoric
@johannes-wolf
Comment options

@idoric
Comment options

@johannes-wolf
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants