Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default 3D coordinate system is left-handed? #501

Closed
KronosTheLate opened this issue Feb 13, 2024 · 5 comments · Fixed by #502
Closed

Default 3D coordinate system is left-handed? #501

KronosTheLate opened this issue Feb 13, 2024 · 5 comments · Fixed by #502

Comments

@KronosTheLate
Copy link

Relevant issue: #274

The following screenshot shows how a simple 3D coordinate system I made appears to be left-handed:
image

Code:
#import "@preview/cetz:0.2.0"  // Drawing diagrams directly in Document
#[
  #cetz.canvas(length: 2cm, {
  import cetz.draw: *
  rotate(y: 30deg)

  let grid_sidelength = 3
  grid(
    (-grid_sidelength/2, -grid_sidelength/2, -grid_sidelength/2), 
    (grid_sidelength/2, grid_sidelength/2, -grid_sidelength/2), 
    step: 0.5, stroke: gray + 0.2pt
  )

  line((-grid_sidelength/2, 0, 0), (grid_sidelength/2, 0, 0), name: "xaxis", mark: (end: "stealth"))
  content((name: "xaxis", anchor: 98%), [#v(1.5em)$ x $])
  line((0, -grid_sidelength/2, 0), (0, grid_sidelength/2, 0), name: "yaxis", mark: (end: "stealth"))
  content((name: "yaxis", anchor: 98%), [#h(-0.9em)$y$])
  line((0, 0, -grid_sidelength/2), (0, 0, grid_sidelength/2), name: "zaxis", mark: (end: "stealth"))
  content((name: "zaxis", anchor: 98%), [#h(-1em)$z$], anchor: "south-east")

  let ccol = red.darken(30%)
  line((0, 0, 0), (1, 0, 0), name: "ihat", mark:(end: "stealth", fill: ccol), stroke: ccol)
  content((name: "ihat", anchor: 65%, ), text(ccol)[#v(1.5em)$hat(i)$])

  let ccol = green.darken(30%)
  line((0, 0, 0), (0, 1, 0), name: "jhat", mark:(end: "stealth", fill: ccol), stroke: ccol)
  content((name: "jhat", anchor: 65%), text(ccol)[#h(-0.75em)$hat(j)$])

  let ccol = blue.darken(30%)
  line((0, 0, 0), (0, 0, 1), name: "khat", mark:(end: "stealth", fill: ccol), stroke: ccol)
  content((name: "khat", anchor: 65%), text(ccol)[#v(-1em)$hat(k)$])
})]
This seems like an odd choice to me. I tried changing `z-up` and `xy-up` in `set-style`, but I could not see any difference. Am I doing it wrong, or is the default coordinate system left-handed?

P.S: Awesome package. Easy to use, reaults look great.

@johannes-wolf
Copy link
Member

johannes-wolf commented Feb 13, 2024

3D support is very limited right now. To set up your coordinate system, call set-transform(<matrix>) to overwrite the transformation matrix. We should definitely add some functions to set up 3D coordinate systems more easily.

The system is left-handed because TikZ' also is, tbh.
A scale(z: -1) should flip the coordinates.

Some elements, like marks, have z-up and xy-up style-keys to set up their orientation, but this does not change the coordinate system.

@KronosTheLate
Copy link
Author

Thanks, scale(z: -1) works as expected.

I am super impressed by the limited 3D support, awesome work ^_^

As this is a young package, it is not too late to improve upon it's ancestors. Would it not make a lot of sense to make the default coordinate system right-handed, and basically all coordinate systems anyone works with are? If not, the burden of inverting the z-axis will be inherited by every user wanting to visualize a normal coordinate system, forever. Unless there is a clear benefit (other than consistency with TikZ), I would vote hard in the direction of changing the default.

@johannes-wolf johannes-wolf linked a pull request Feb 13, 2024 that will close this issue
@johannes-wolf
Copy link
Member

@KronosTheLate what do you think about #504

@KronosTheLate
Copy link
Author

KronosTheLate commented Feb 14, 2024

It looks good to me! There are some details I feel unable to evaluate (due to lack of knowledge and experience), but that PR certainly closes this issue. I will hop on over to continue the discussion there.

@KronosTheLate
Copy link
Author

Thanks for fixing this <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants