Angle and position from two nodes #868
Answered
by
johannes-wolf
l0uisgrange
asked this question in
Q&A
-
Hi CeTZ team 👋, I'm currently building a library using CeTZ to draw electronic circuits, and I'm planning to contribute back to CeTZ once the library is published to Typst Universe 🚀. I currently have something like this: #let component(node, node2, ..things) = {
group(name: uid, {
let angle = get-angle(rotate, node, node2)
cetz.draw.on-layer(1, {
(draw.anchors)(..things)
cetz.draw.scope({
cetz.draw.set-origin("center")
cetz.draw.scale(scale)
cetz.draw.rotate(angle)
(draw.component)(..things)
})
})
// ...
})
} With my function #let get-angle(rotate, node, node2) = {
if (node2 != none) {
return calc.atan2(node2.at(0) - node.at(0), node2.at(1) - node.at(1))
} else {
return rotate
}
}
Thanks in advance for your help! 😊 |
Beta Was this translation helpful? Give feedback.
Answered by
johannes-wolf
May 6, 2025
Replies: 1 comment
-
👋 Hi :)
I hope that helps. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
l0uisgrange
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👋 Hi :)
let (ctx, vec) = coordinate.resolve(ctx, node)
to resolve any cetz coordinate to a vector. Here is an example: https://github.com/cetz-package/cetz/blob/master/src/lib/angle.typ#L66I hope that helps.