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

canvas: Change to rh coordinate system #502

Merged
merged 4 commits into from
May 21, 2024
Merged

Conversation

johannes-wolf
Copy link
Member

@johannes-wolf johannes-wolf commented Feb 13, 2024

This is a breaking change for code that uses 3D coordinates!

Right hand sided coordinate systems are more common. Cetz currently uses lhs because TikZ does so by default. But TikZ also makes it more easy to change the system by having x, y and z arguments to the tikzpicture/canvas.

Question: Should we add x, y, and z arguments to canvas to make setting up a custom
coordinate system simpler?

An alternative would be providing helper functions to set up axes:

set-axes(x, y, z) // Signature
set-axes(1, -1, -.5) // Set length relative values (default xyz system)
set-axes(2cm, .5cm)  // Set absolute lengths (default xyz system)
set-axes((0,1), (1,0), (.5,.5)) // Set custom axis vectors

Such function would override the current transformation matrix.
The proposed x, y and z arguments would be able to do the same (accept number or vector).


The proposed arguments or functions are not part of this PR but a proposal for a follow-up PR.

@fenjalien
Copy link
Member

I don't have any particular opinion about this as I haven't and don't have the need to use 3D. However, I would like to get feedback from users about this before merging as I assume it could be a large breaking change (although easily fixed just annoying). A thread on the discord server would work :)

@KronosTheLate
Copy link

Before, z was sheared by 0.5. Now, it is instead scaled by 0.5. I am not sure what the effect of that difference is. Other than that, the sign is swapped, and this looks good to me!

@johannes-wolf
Copy link
Member Author

Before, z was sheared by 0.5. Now, it is instead scaled by 0.5. I am not sure what the effect of that difference is. Other than that, the sign is swapped, and this looks good to me!

That is actually a typo.

@johannes-wolf
Copy link
Member Author

3D users I know of that already use a rhs system by manually transforming coordinates:

johannes-wolf added a commit that referenced this pull request Feb 21, 2024
Change the default transformation matrix to have z coordinates of zero
after transformation.
This is actually a fix, as the final 2D projection should not have a
z-value other than zero.

With this change, anchors in 3D space become 2D and thus elements like
rect, Bézier or Catmull, … will correctly work when using them with
anchors to 3D elements. Intersection between 3D elements will also work
(in 2D space).


See: #502 and #493.
@johannes-wolf
Copy link
Member Author

Ping.

@knuesel
Copy link

knuesel commented May 18, 2024

For what it's worth I did a lot of 3D plots in TikZ and first thing to do is always using the keys x, y, z to define a right-handed coordinate system with z looking up. (I'm still trying to figure out how to do that in CeTZ :-) ). Having right-handed by default would make a lot of sense for me.

By the way is the default really left-handed in TikZ? I have no memory of that and trying this:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0,0) -- (1,0,0) node {x};
\draw (0,0,0) -- (0,1,0) node {y};
\draw (0,0,0) -- (0,0,1) node {z};
\end{tikzpicture}
\end{document}

gives the following which looks right-handed:

image

@johannes-wolf
Copy link
Member Author

You would do that using scale(x: , y:, z: )

@KronosTheLate
Copy link

I was honestly very surprised to see the default being a left handed coordinate system. Throughout my 5 years engineering education I have not once used a left handed one, nor seen anyone else do it.

Are there any fields in which it is not just implied that coordinate systems are right handed unless otherwise specified?

@fenjalien
Copy link
Member

Okay I've seen a few comments on discord as well, I'm happy for it to be merged once its been updated

@johannes-wolf johannes-wolf merged commit 259dfc8 into master May 21, 2024
1 check passed
@johannes-wolf johannes-wolf deleted the right-handed-cs branch May 21, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default 3D coordinate system is left-handed?
4 participants