-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Rotations about the Z-axis #274
Labels
Comments
Huh we really messed that up! Rotations should be positive going anticlockwise (which follows your intuition right?) so its the same as tikz. Also its okay that cetz's rotate is opposite to typst's as cetz uses up as positive but typst uses down. |
Yes, that follows my intuition! Okay, I'm glad I wasn't going crazy. 😄 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is something I want to bring up about my original implementation of
arc-through
from #206. This was originally going to just be a comment on #273, but after typing so much I figured it was worth posting as a full issue.This part was meant to be only temporary; it's supposed to figure out the angle between$x$ -axis when $(x, y)$ instead of $(y, x)$ , like most other $(y, x)$ instead of Typst's $(x, y)$ , which is why I wrote that little custom block with that comment (it also subtracts
a
and thecenter
is taken as the origin. What this should be is just a call tovector.angle2(center, a)
; but when I tried that, I found that my angles were always backwards. That was when I discovered that Typst'satan2
isatan2
implementations.vector.angle2
, which usescalc.atan2
, passes its arguments asa - b
instead ofb - a
, then adds 90 degrees, which I presume was done to account for the incorrect argument order).Had I gotten around to making a full PR, I had intended to fix this as part of it. So, when I saw #273, I figured I would go ahead and do that little change as a separate one and then request to merge into this branch. But... I've managed to confuse myself.
To cut to the chase: in which direction should rotations around the$z$ -axis be done?
Is this 60°, or is this −60°? My intuition when working in two dimensions is that it's 60°, like how the unit circle works. That is, I expected a right-hand coordinate system, where counterclockwise is positive. So, 60° is what I'd expect
atan2(x: 1/2, y: sqrt(3)/2)
to spit out:There is no clear picture, as far as I can discern, for what CetZ uses, though:
(diagram generated with Typst v0.8 and CetZ 2ed733a)
(code is kind of messy, but here it is)
vector.angle2
, counterclockwise is negative (left-handed; red).angle
parameter, counterclockwise is positive (right-handed; blue).rotate
transformation function, clockwise is positive (left-handed; purple).arc
sstart
,stop
, anddelta
parameters, counterclockwise is positive (right-handed; olive).The
arc
one being different fromvector.angle2
is the problem I initially ran into, and what prompted that customstart
block in my originalarc-through
function from #206. Therotate
one could make sense either way: technically, the coordinate space was rotated by 120°, my line was drawn, and then it was rotated back. But that means that a call torotate(120deg)
rotated my shapes by -120°, which feels counterintuitive.Like I alluded to, I started working on a PR to fix this: johannes-wolf:2ed733a...matthew-e-brown:feb07cc. I "fixed"
vector.angle2
to work in-line with the trigonometric functions, and subsequently "fixed" the few spots that usedvector.angle2
. But then when making my MWE and writing my PR, I noticed thatrotate
—which didn't depend onangle2
—also happened to be left-handed. I could "fix" therotate
function to also be right-handed, but because the transformation matrices feel like the "standard" way to do rotations, that felt a little drastic. I suddenly became unsure: what is the intended direction of rotation for CetZ?I have been staring at matrices and curves and arcs, twisting my left and right hands around in the air for so long now that I could very well just be getting my angles in a knot. I wouldn't be too surprised if it turns out this is all completely intended behaviour and I've missed something silly. I hope not! 😆 I'll open a draft PR with my (potential) fixes for now. Once I know which way things are supposed to spin, I can correct the last few discrepancies and mark it as ready. Or, I can close it if I got things the wrong way.
One last thing I want to note is that Typst's native
rotate
function is left-handed; so clockwise is positive. Not that CetZ has to use the same system, but it certainly didn't help me come to any conclusions.Sorry 🍁 this issue's so long. 😅
The text was updated successfully, but these errors were encountered: