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

Draw right angles #414

Closed
avonmoll opened this issue Dec 20, 2023 · 1 comment
Closed

Draw right angles #414

avonmoll opened this issue Dec 20, 2023 · 1 comment
Labels

Comments

@avonmoll
Copy link

avonmoll commented Dec 20, 2023

I was looking for an easy way to draw right angles and couldn't find a built-in solution in CeTZ, so I wrote the following:

let angle-point-to-point(a, b) = {
    return calc.atan2(b.at(0) - a.at(0), b.at(1) - a.at(1))
  }
  
  let right-angle(origin, a, b, radius: 5pt, ..style) = {
    get-ctx(ctx => {
      let a = cetz.coordinate.resolve(ctx, a)
      let b = cetz.coordinate.resolve(ctx, b)
      let angle-a = angle-point-to-point(origin, a)
      let angle-b = angle-point-to-point(origin, b)
      line((origin, radius, a), (rel: (angle-b, radius)), ..style)
      line((origin, radius, b), (rel: (angle-a, radius)), ..style)
    })
  }

And used it like this: right-angle(O, A, B, radius: 10pt, stroke: green) to produce:
image

It seems to work OK but I was wondering if drawing right angles can or will be built into CeTZ.

@johannes-wolf
Copy link
Member

It should be built into the angle function, I think 👍.

johannes-wolf added a commit that referenced this issue Dec 20, 2023
Adds a `right-angle` function to the angle library that behaves tikz
like.
Fixes #414.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants