Skip to content

Regular polygons #1019

@Enivex

Description

@Enivex

Description

At the moment, visualize has polygon, but the only regular polygon that is easy to create is a square.

https://typst.app/docs/reference/visualize/polygon/
https://typst.app/docs/reference/visualize/square/

It would be helpful to have a function (or some easier way to get them from the existing one) to obtain regular n-gons.

Use Case

I'd wager that a good chunk of those looking to draw polygons are actually looking to draw regular polygons (equilateral triangles, regular hexagons etc). Currently this requires some math, and is therefore inconvenient. Here's a proof of concept illustrating this.

#let regular-polygon(n) = {
  let vertices(n) = for k in range(n) {
    (((1+calc.cos(2*calc.pi/n*k))*1cm,(1+calc.sin(2*calc.pi/n*k))*1cm),)
  }
  polygon(fill: blue.lighten(80%),
  stroke: blue,..vertices(n))
}
#for k in range(3,30) {box()[#regular-polygon(k)]}

image

(Obviously a proper implementation would need to be more customizable than this.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or requestvisualizeRelated to drawing and visualizations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions