How can I remove the initial z shearing transformation in Cetz?

Cetz applies an initial transformation matrix with shearing components

    / Current transformation matrix, a rhs coordinate system
    // where z is sheared by a half x and y.
    //   +x = right, +y = up, +z = 1/2 (left + down)
    transform:
      ((1, 0,-.5, 0),
       (0,-1,+.5, 0),
       (0, 0, .0, 0),
       (0, 0, .0, 1)),

I want to avoid the initial z shearing transformation in Cetz since it creates some distortions in 3D generated images.
What are the commands I need to remove this shearing? or do I need to set a new transformation matrix?
Also, is there a way to define an default initial transformation?

Is this what you are looking for?

#canvas({
  import draw: *
  set-style(mark:(end:">"))
  
  set-transform(none)

  line((),(x:1))
  line((0,0),(y:1))
  line((0,0),(z:1))
})

image

Almost. I need the y axis pointing upwards.
Probably the only way to achieve this is providing the transformation matrix explicitly.

I think this one does what you want:

#canvas({
  import draw: *
  set-style(mark:(end:">"))
  
  scale(z: 0)

  line((),(x:1), stroke: red)
  line((0,0),(y:1), stroke: green)
  line((0,0),(z:1), stroke: blue)
})

image

Scaling z by 0 will effectively ignore the coordinate, so that all points with the same (x, y) appear at the same position on the canvas.

Not really. In that case, I will lose the z dimension after a rotation. Thanks, though.

You can either use:

#import "@preview/cetz:0.3.2"

#cetz.canvas({
  import cetz.draw: *

  set-transform(none)
  scale(y: -1)

  line((0,1), (0,0), (1,0), mark: (start: ">", end: ">"))
})

Or:

#import "@preview/cetz:0.3.2"

#cetz.canvas({
  import cetz.draw: *

  set-transform(
    ((1,0,0,0),
     (0,-1,0,0),
     (0,0,1,0),
     (0,0,0,1)))

  line((0,1), (0,0), (1,0), mark: (start: ">", end: ">"))
})

To remove the shearing.

3 Likes