### Quick Start: Typst Euclidean Geometry Construction Source: https://github.com/nathan-ed/typst-package-ctz-euclide/blob/main/README.md Demonstrates a basic example of using the ctz-euclide package to draw a triangle, mark points, and label angles. It requires importing the package and uses specific functions for initialization, styling, point definition, drawing lines, points, labels, and angles. ```typst #import "@preview/ctz-euclide:0.1.0": * #ctz-canvas({ import cetz.draw: * ctz-init() ctz-style(point: (shape: "cross", size: 0.1, stroke: black + 1.5pt)) // Define points ctz-def-points(A: (0, 0), B: (4, 0), C: (2, 3)) // Draw triangle ctz-draw-line("A", "B", "C", "A", stroke: black) // Mark points and add labels ctz-draw-points("A", "B", "C") ctz-draw-labels("A", "B", "C", A: "below left", B: "below right", C: "above") // Mark an angle ctz-draw-angle("A", "B", "C", label: $alpha$, radius: 0.5) }) ``` -------------------------------- ### Comprehensive Typst Example: Triangle Centers and Euler Line Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt This comprehensive Typst example showcases the creation of various triangle centers (centroid, circumcenter, incenter, orthocenter) and visualizes the Euler line. It also includes drawing the circumcircle, incircle, and medians. The example demonstrates defining points, calculating centers using `ctz-def-*` functions, and rendering these elements with specific styles and labels using `ctz-draw` and `ctz-style`. ```typst #ctz-canvas(length: 0.95cm, { import cetz.draw: * ctz-init() ctz-style(point: (shape: "dot", size: 0.07, fill: black)) ctz-def-points(A: (0, 0), B: (7, 0.5), C: (2.5, 5)) ctz-draw(line: ("A", "B", "C", "A"), stroke: black + 1.5pt) // Define triangle centers ctz-def-centroid("G", "A", "B", "C") ctz-def-circumcenter("O", "A", "B", "C") ctz-def-incenter("I", "A", "B", "C") ctz-def-orthocenter("H", "A", "B", "C") // Euler line (H, G, O are collinear) ctz-draw(segment: ("H", "O"), stroke: (paint: red.darken(20%), dash: "dashed", thickness: 1.2pt)) // Circumcircle and incircle ctz-draw(circle-through: ("O", "A"), stroke: blue + 1pt) ctz-draw(incircle: ("A", "B", "C"), stroke: green.darken(20%) + 1pt) // Medians ctz-def-midpoint("Ma", "B", "C") ctz-def-midpoint("Mb", "A", "C") ctz-def-midpoint("Mc", "A", "B") ctz-draw(segment: ("A", "Ma"), stroke: gray + 0.7pt) ctz-draw(segment: ("B", "Mb"), stroke: gray + 0.7pt) ctz-draw(segment: ("C", "Mc"), stroke: gray + 0.7pt) ctz-draw(points: ("A", "B", "C", "G", "O", "I", "H"), labels: ( A: "below left", B: "below right", C: "above", G: (pos: "right", offset: (0.15, 0)), O: (pos: "right", offset: (0.15, 0)), I: (pos: "above left", offset: (-0.1, 0.1)), H: (pos: "left", offset: (-0.15, 0)) )) }) ``` -------------------------------- ### Configure Default Styles for Points and Labels in Typst with ctz-style Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt This Typst example demonstrates how to use the `ctz-style` function to set default visual properties for points and labels within a canvas. You can globally define attributes like shape, size, fill, and stroke for points. The example also shows how to override these styles mid-drawing for specific elements. Supported point shapes include 'dot', 'cross', 'circle', 'square', 'plus', 'diamond', and 'triangle'. ```typst #ctz-canvas(length: 0.8cm, { import cetz.draw: * ctz-init() // Set point style: shape, size, fill, stroke ctz-style(point: (shape: "dot", size: 0.1, fill: red)) ctz-def-points(A: (0, 0), B: (3, 0), C: (1.5, 2.5)) ctz-draw(line: ("A", "B", "C", "A"), stroke: black) ctz-draw(points: ("A", "B", "C")) // Change style mid-drawing ctz-style(point: (shape: "cross", size: 0.15, stroke: blue + 1.5pt)) ctz-def-centroid("G", "A", "B", "C") ctz-draw(points: ("G"), labels: (G: "right")) // Point shapes: "dot", "cross", "circle", "square", "plus", "diamond", "triangle" }) ``` -------------------------------- ### Initialize ctz-euclide and Draw Basic Triangle Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Imports the ctz-euclide package and initializes the point registry within a canvas. This example defines three points (A, B, C) and draws a triangle connecting them, also labeling the points. ```typst #import "@preview/ctz-euclide:0.1.0": * #ctz-canvas({ import cetz.draw: * ctz-init() // Initialize point registry - required at start // Your geometry code here ctz-def-points(A: (0, 0), B: (4, 0), C: (2, 3)) ctz-draw(line: ("A", "B", "C", "A"), stroke: black) ctz-draw(points: ("A", "B", "C"), labels: (A: "below left", B: "below right", C: "above")) }) ``` -------------------------------- ### Typst: Drawing Geometric Elements (Points, Labels, Angles) Source: https://github.com/nathan-ed/typst-package-ctz-euclide/blob/main/README.md Provides examples of drawing basic geometric elements: points, adding labels to points, and marking angles. These functions are used to visualize the constructed geometry. ```typst // Draw points ctz-draw-points("A", "B", "C") // Add labels ctz-draw-labels("A", "B", "C", A: "below left", B: "below right", C: "above") // Mark angles ctz-draw-angle("B", "A", "C", label: $alpha$, radius: 0.6) ``` -------------------------------- ### Construct Parallel Line Through a Point Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Constructs a line parallel to a given segment and passing through a specified point using `ctz-def-para`. The example uses `ctz-draw-line-global-clip` to render the parallel lines. ```typst #ctz-canvas(length: 0.75cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (5, 1), C: (1, 2.5)) ctz-def-para("P1", "P2", ("A", "B"), "C") // Parallel to AB through C ctz-set-clip(-0.5, -0.5, 5.5, 3.5) ctz-draw-line-global-clip("A", "B", add: (2, 2), stroke: black) ctz-draw-line-global-clip("P1", "P2", add: (2, 2), stroke: green) ctz-draw(points: ("A", "B", "C"), labels: (A: "below", B: "below", C: "above")) }) ``` -------------------------------- ### Find Nine-Point Circle Center using ctz-def-euler Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Calculates the center of the nine-point (Euler) circle of a triangle defined by points A, B, and C. The example also shows how to define midpoints and draw the triangle with the nine-point circle. Requires the 'cetz.draw' module. ```typst #ctz-canvas(length: 0.7cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (5, 0), C: (1.5, 3.5)) ctz-def-euler("N", "A", "B", "C") // Nine-point circle passes through midpoints of sides ctz-def-midpoint("Ma", "B", "C") ctz-def-midpoint("Mb", "A", "C") ctz-def-midpoint("Mc", "A", "B") ctz-draw(line: ("A", "B", "C", "A"), stroke: black) ctz-draw(circle-through: ("N", "Ma"), stroke: purple + 0.7pt) ctz-draw(points: ("A", "B", "C", "N", "Ma", "Mb", "Mc"), labels: (N: "below")) }) ``` -------------------------------- ### Define Regular Polygon Vertices Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Generates the vertices of a regular n-sided polygon using `ctz-def-regular-polygon`. It requires a center point and a starting vertex to define the polygon's size and orientation, then draws the polygon. ```typst #ctz-canvas(length: 0.7cm, { import cetz.draw: * ctz-init() ctz-def-points(O: (0, 0), A: (3, 0)) // O is center, A is starting vertex that fixes radius/angle ctz-def-regular-polygon("Hex", ("A", "B", "C", "D", "E", "F"), "O", "A") ctz-draw("Hex", stroke: blue) // Draw by name ctz-draw(points: ("A", "B", "C", "D", "E", "F", "O"), labels: (O: "below")) }) ``` -------------------------------- ### Construct Perpendicular Bisector - ctz-def-mediator Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Constructs the perpendicular bisector of a line segment. It requires the names for the start and end points of the bisector line and the two points defining the segment. ```typst #ctz-canvas(length: 0.75cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (1, 1), B: (5, 3)) ctz-def-mediator("M1", "M2", "A", "B") // Perpendicular bisector of AB ctz-def-midpoint("M", "A", "B") ctz-draw(segment: ("A", "B"), stroke: black) ctz-draw(segment: ("M1", "M2"), stroke: purple) ctz-draw-mark-right-angle("M1", "M", "A", size: 0.25) ctz-draw(points: ("A", "B", "M"), labels: (A: "left", B: "right", M: "below")) }) ``` -------------------------------- ### Construct Angle Bisector - ctz-def-bisect Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Constructs the bisector of an angle defined by three points. It takes the names for the start and end points of the bisector line and the three points defining the angle (vertex and two other points). ```typst #ctz-canvas(length: 0.8cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (4, 0), C: (1, 3)) ctz-def-bisect("D1", "D2", "C", "A", "B") // Bisector of angle CAB at vertex A ctz-set-clip(-0.5, -0.5, 4.5, 3.5) ctz-draw(line: ("A", "B", "C", "A"), stroke: black) ctz-draw-seg-global-clip("D1", "D2", stroke: red) ctz-draw-angle("C", "A", "B", radius: 0.5, stroke: gray) ctz-draw(points: ("A", "B", "C"), labels: (A: "below", B: "below", C: "above")) }) ``` -------------------------------- ### Enable Sketchy (Hand-Drawn) Mode in Typst Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt This snippet demonstrates how to enable a sketchy, hand-drawn style for geometric elements within a Typst canvas. It uses the `sketchy: true` parameter on drawing functions to apply this effect. The example shows drawing a triangle, its circumcircle, and incircle in a sketchy style. ```typst #ctz-canvas(length: 0.5cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (4, 0), C: (1.5, 2.5)) // Sketchy triangle with circumcircle and incircle ctz-draw(line: ("A", "B", "C", "A"), stroke: gray, sketchy: true) ctz-draw(circumcircle: ("A", "B", "C"), stroke: blue, sketchy: true) ctz-draw(incircle: ("A", "B", "C"), stroke: red, sketchy: true) // Parameters: roughness (0-2), seed (for reproducibility) // ctz-draw(segment: ("A", "B"), stroke: blue, sketchy: true, roughness: 1.5, seed: 42) ctz-draw(points: ("A", "B", "C"), labels: (A: "below left", B: "below right", C: "above")) }) ``` -------------------------------- ### Define Midpoint Between Two Points Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Calculates and defines the midpoint between two specified points using `ctz-def-midpoint`. The example then draws the segment and labels the original points along with their midpoint. ```typst #ctz-canvas(length: 0.8cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (5, 3)) ctz-def-midpoint("M", "A", "B") // M is midpoint of AB ctz-draw(segment: ("A", "B"), stroke: black) ctz-draw(points: ("A", "B", "M"), labels: (A: "left", B: "right", M: "above")) }) ``` -------------------------------- ### Rotate Point using ctz-def-rotation Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Rotates a point (or object) around a specified center point by a given angle in degrees. This example demonstrates rotating point A around center O by 60 and 120 degrees, creating points B and C. It also draws the relevant segments and circles. Requires 'cetz.draw'. ```typst #ctz-canvas(length: 0.75cm, { import cetz.draw: * ctz-init() ctz-def-points(O: (2, 2), A: (5, 2)) ctz-def-rotation("B", "A", "O", 60) // Rotate A by 60 degrees around O ctz-def-rotation("C", "A", "O", 120) // Rotate A by 120 degrees around O ctz-draw(circle-r: (ctz-pt("O"), 3), stroke: gray.lighten(50%)) ctz-draw(segment: ("O", "A"), stroke: blue) ctz-draw(segment: ("O", "B"), stroke: blue) ctz-draw(segment: ("O", "C"), stroke: blue) ctz-draw(line: ("A", "B", "C", "A"), stroke: black) ctz-draw(points: ("O", "A", "B", "C"), labels: (O: "below left", A: "right", B: "above right", C: "left")) }) ``` -------------------------------- ### Reflect Point Across Line using ctz-def-reflect Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Reflects a point P across a line defined by two points A and B, creating a new point Pp. This example shows reflecting point P across the line segment AB and drawing the original points, the line, and the reflected point with a connecting path. Requires 'cetz.draw'. ```typst #ctz-canvas(length: 0.75cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (4, 3), P: (3, 0)) ctz-def-reflect("Pp", "P", "A", "B") // Reflect P across line AB ctz-draw(segment: ("A", "B"), stroke: gray) ctz-draw(path: "P--Pp", stroke: blue + 0.5pt, mark: (end: ">"), points: false, labels: false) ctz-draw(points: ("A", "B", "P", "Pp"), labels: (P: "below", Pp: "above left")) }) ``` -------------------------------- ### Define Projectile Trajectory - ctz-def-projectile Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Defines a projectile trajectory, which is parabolic, using the ctz-def-projectile function. It takes the starting position, initial velocity components, and optionally gravity and floor level. The 'vectors' and 'vector-count' parameters can be used to visualize velocity vectors. ```typst #ctz-canvas(length: 0.5cm, { import cetz.draw: * ctz-init() ctz-def-projectile("proj", (0, 0), (4, 6), gravity: 9.81, y-floor: 0, vectors: true, vector-count: 5) ctz-draw("proj", stroke: blue) // Draw ground ctz-draw(segment: ((-1, 0), (6, 0)), stroke: gray) }) ``` -------------------------------- ### Compile Documentation and Gallery Images (Bash) Source: https://github.com/nathan-ed/typst-package-ctz-euclide/blob/main/README.md This script compiles the Typst documentation to PDF and rebuilds all gallery images. It first switches to local imports for documentation, compiles the manual, then iterates through all .typ files in the gallery directory to compile them into .png images. Finally, it switches back to preview imports for publishing. ```bash #!/bin/bash # 1) Switch docs to local imports and compile: ./scripts/use-local-docs.sh typst compile docs/manual.typ docs/manual.pdf # 2) Rebuild gallery images locally: for f in gallery/*.typ; do typst compile "$f" "${f%.typ}.png" done # 3) Switch docs/tests back to preview imports for publishing: ./scripts/use-preview-package.sh find gallery -name "*.typ" -type f -exec sed -i 's|@local/ctz-euclide:0.1.0|@preview/ctz-euclide:0.1.0|g' {} \; ``` -------------------------------- ### Typst: Drawing Paths with Connectors and Arrow Tips Source: https://github.com/nathan-ed/typst-package-ctz-euclide/blob/main/README.md Demonstrates drawing paths using TikZ-like syntax with various connectors (`--`, `->`, etc.) and supports per-segment arrow tips. It also shows how to customize point appearance and disable points. ```typst // TikZ-like per-segment tips ctz-draw-path("A--B->C|-|D", stroke: black) Supported connectors: --, ->, <-, <->, |-|. |->, <-|. By default, points (small dots) and labels (below) are drawn. Override with {...} in the path: "A{below}--B{below}->C{above}|-|D{below}". You can customize point appearance with `point-style` and `point-color`, or disable with `points: false`. ``` -------------------------------- ### Define Multiple Points and Draw Triangle Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Demonstrates defining multiple points at specific coordinates using `ctz-def-points` and then drawing a triangle connecting these points. It also shows how to label the defined points. ```typst #ctz-canvas(length: 0.8cm, { import cetz.draw: * ctz-init() // Define multiple points at once ctz-def-points(A: (0, 0), B: (4, 0), C: (2, 3)) // Draw triangle and label points ctz-draw(line: ("A", "B", "C", "A"), stroke: black) ctz-draw(points: ("A", "B", "C"), labels: ( A: "below left", B: "below right", C: "above" )) }) ``` -------------------------------- ### Typst: Geometric Transformations (Rotation, Reflection, Translation) Source: https://github.com/nathan-ed/typst-package-ctz-euclide/blob/main/README.md Illustrates how to perform basic geometric transformations: rotation around a point, reflection across a line, and translation by a vector. These functions are essential for manipulating geometric objects. ```typst // Rotation ctz-def-rotation("B", "A", "O", 60) // Rotate A around O by 60° // Reflection ctz-def-reflect("C", "A", "P", "Q") // Reflect A across line PQ // Translation ctz-def-translate("D", "A", (2, 3)) // Translate A by vector (2, 3) ``` -------------------------------- ### Typst: Define Geometric Points Source: https://github.com/nathan-ed/typst-package-ctz-euclide/blob/main/README.md Shows how to define geometric points using coordinates. This is a fundamental step for most constructions within the ctz-euclide package. ```typst // Define points ctz-def-points(A: (0, 0), B: (3, 0), C: (1.5, 2.5)) ``` -------------------------------- ### Typst: Measuring and Labeling Segments Source: https://github.com/nathan-ed/typst-package-ctz-euclide/blob/main/README.md Shows how to draw and label the measurement of a line segment. This is useful for annotating diagrams with lengths. ```typst ctz-draw-measure-segment("A", "B", label: $5$, offset: 0.3, side: "left") ``` -------------------------------- ### Typst: Geometric Intersections (Line-Line, Line-Circle, Circle-Circle) Source: https://github.com/nathan-ed/typst-package-ctz-euclide/blob/main/README.md Demonstrates how to find intersection points between different geometric entities: two lines, a line and a circle, and two circles. These are crucial for constructing complex geometric figures. ```typst // Line-line intersection ctz-def-ll("E", ("A", "B"), ("C", "D")) // Line-circle intersection ctz-def-lc(("F", "G"), ("A", "B"), ("O", "P")) // Circle-circle intersection ctz-def-cc(("H", "I"), ("O1", "P1"), ("O2", "P2")) ``` -------------------------------- ### Clip Geometric Drawings to a Defined Region in Typst Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt This Typst code snippet illustrates how to use clipping to confine geometric drawings within a specified rectangular region. The `ctz-set-clip` function defines the boundaries (xmin, ymin, xmax, ymax), and subsequent `ctz-draw-line-global-clip` calls ensure that lines are rendered only within these limits. An optional `ctz-show-clip` function can visualize the clipping boundary. ```typst #ctz-canvas(length: 0.75cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (4, 2), C: (1, 3)) ctz-def-perp("P1", "P2", ("A", "B"), "C") // Set clip region (xmin, ymin, xmax, ymax) ctz-set-clip(-0.5, -0.5, 5, 4) // Draw lines clipped to region ctz-draw-line-global-clip("A", "B", add: (2, 2), stroke: black) ctz-draw-line-global-clip("P1", "P2", add: (2, 2), stroke: blue) // Show clip boundary (optional) ctz-show-clip(stroke: gray + 0.5pt) ctz-draw(points: ("A", "B", "C"), labels: (A: "below", B: "right", C: "above")) }) ``` -------------------------------- ### Draw Path with Arrow Tips - ctz-draw-path Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt The ctz-draw-path function allows drawing polylines with customizable arrow tips at segment ends, using TikZ-like syntax. It supports various connector types like '--', '->', '<-', '<->', '|-|', '|->', and '<-|'. Optional label positions and per-point style overrides are also supported. ```typst #ctz-canvas(length: 0.8cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (3, 0), C: (6, 1.5), D: (8, 0)) // Connectors: --, ->, <-, <->, |-|, |->, <-| ctz-draw-path("A--B->C|-|D", stroke: black) // With custom label positions in the path string // ctz-draw-path("A{below}--B{below}->C{above}|-|D{below}", stroke: black) // With per-point style overrides // ctz-draw-path("A{below, style: circle}--B{below}->C{above, style: none}|-|D{below}", stroke: black) }) ``` -------------------------------- ### Construct Perpendicular Line Through a Point Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Constructs a line perpendicular to a given segment and passing through a specified point using `ctz-def-perp`. It also demonstrates finding the foot of the perpendicular using `ctz-def-project` and drawing a right-angle mark. ```typst #ctz-canvas(length: 0.75cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (5, 1), C: (2, 3)) ctz-def-perp("P1", "P2", ("A", "B"), "C") // Perpendicular to AB through C ctz-def-project("H", "C", "A", "B") // Foot of perpendicular ctz-draw(segment: ("A", "B"), stroke: black) ctz-draw(segment: ("P1", "P2"), stroke: blue) ctz-draw-mark-right-angle("A", "H", "C", size: 0.3) ctz-draw(points: ("A", "B", "C"), labels: (A: "left", B: "right", C: "above")) }) ``` -------------------------------- ### Project Point onto Line - ctz-def-project Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Projects a point onto a line using orthogonal projection. This is commonly used in geometry to find the foot of a perpendicular from a point to a line. It requires the name for the projected point, the point to project, and two points defining the line. ```typst #ctz-canvas(length: 0.75cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (5, 1), P: (2, 3)) ctz-def-project("H", "P", "A", "B") // Project P onto line AB ctz-draw(segment: ("A", "B"), stroke: black) ctz-draw(segment: ("P", "H"), stroke: blue + 0.5pt) ctz-draw-mark-right-angle("A", "H", "P", size: 0.25) ctz-draw(points: ("A", "B", "P", "H"), labels: (P: "above", H: "below")) }) ``` -------------------------------- ### Create Thales Triangle using ctz-def-thales-triangle Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Constructs a right triangle inscribed in a circle according to Thales' theorem. This function defines points A, B, and C, with the right angle at C, and places them on a circle centered at O with a given radius. The 'base-angle' and 'orientation' parameters offer customization. Requires 'cetz.draw'. ```typst #ctz-canvas(length: 0.75cm, { import cetz.draw: * ctz-init() ctz-def-points(O: (0, 0)) // Creates triangle with right angle at C, inscribed in circle of radius 2.5 ctz-def-thales-triangle("A", "B", "C", "O", 2.5, base-angle: 30, orientation: "left") ctz-draw(circle-r: (ctz-pt("O"), 2.5), stroke: gray + 0.5pt) ctz-draw-path("A--B--C--A", stroke: black + 1pt) ctz-draw-mark-right-angle("A", "C", "B", color: red) ctz-draw(points: ("A", "B", "C", "O"), labels: (A: "right", B: "left", C: "above", O: "below")) }) ``` -------------------------------- ### Find Orthocenter of a Triangle using ctz-def-orthocenter Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Calculates the orthocenter (intersection of altitudes) of a triangle defined by points A, B, and C. It also demonstrates constructing the altitudes and drawing the triangle and its orthocenter. Dependencies include the 'cetz.draw' module. ```typst #ctz-canvas(length: 0.75cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (5, 0), C: (2, 3.5)) ctz-def-orthocenter("H", "A", "B", "C") // Construct altitudes ctz-def-perp("Ha1", "Ha2", ("B", "C"), "A") ctz-def-perp("Hb1", "Hb2", ("A", "C"), "B") ctz-def-perp("Hc1", "Hc2", ("A", "B"), "C") ctz-set-clip(-0.5, -0.5, 5.5, 4) ctz-draw(line: ("A", "B", "C", "A"), stroke: black) ctz-draw-line-global-clip("A", "Ha1", add: (2, 2), stroke: red + 0.5pt) ctz-draw-line-global-clip("B", "Hb1", add: (2, 2), stroke: red + 0.5pt) ctz-draw-line-global-clip("C", "Hc1", add: (2, 2), stroke: red + 0.5pt) ctz-draw(points: ("A", "B", "C", "H"), labels: (A: "left", B: "right", C: "above right", H: "below right")) }) ``` -------------------------------- ### Invert Geometric Objects - ctz-def-inversion Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Performs circle inversion on points, lines, or circles. This transformation maps objects to other objects (e.g., a line to a circle, a circle to a circle) with respect to a given center and radius. It's a fundamental concept in inversive geometry. ```typst #ctz-canvas(length: 0.7cm, { import cetz.draw: * ctz-init() ctz-set-clip(-5, -4.5, 5, 4) ctz-def-points(O: (0, 0), A: (-4, -1), B: (4, -1), C: (1.8, 1)) ctz-def-line("L", "A", "B") ctz-def-circle("C1", "C", radius: 1.1) // Invert line and circle through circle centered at O with radius 3 ctz-def-inversion("Li", "L", "O", 3) // Line becomes circle ctz-def-inversion("C1i", "C1", "O", 3) // Circle becomes circle ctz-draw(circle-r: (ctz-pt("O"), 3), stroke: black + 1pt) ctz-draw("L", stroke: gray + 0.7pt) ctz-draw("C1", stroke: gray + 0.7pt) ctz-draw("Li", stroke: blue + 1pt) // Inverted line (now a circle) ctz-draw("C1i", stroke: red + 1pt) // Inverted circle ctz-draw(points: ("O"), labels: (O: "below left")) }) ``` -------------------------------- ### Construct Medial Triangle using ctz-def-medial-triangle Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Constructs the medial triangle by connecting the midpoints of the sides of a given triangle ABC. The function defines the midpoints Ma, Mb, and Mc and draws both the original and medial triangles. Requires the 'cetz.draw' module. ```typst #ctz-canvas(length: 0.7cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (5, 0), C: (2, 3.5)) ctz-def-medial-triangle("Ma", "Mb", "Mc", "A", "B", "C") ctz-draw(line: ("A", "B", "C", "A"), stroke: black) ctz-draw(line: ("Ma", "Mb", "Mc", "Ma"), stroke: blue + 0.7pt) ctz-draw(points: ("A", "B", "C", "Ma", "Mb", "Mc"), labels: (A: "below left", B: "below right", C: "above")) }) ``` -------------------------------- ### Define Point Using Linear Combination Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Defines a point based on a linear combination of two other points (P = A + k(B - A)) using `ctz-def-linear`. This allows for creating points along a line segment or its extension. ```typst #ctz-canvas(length: 0.8cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (5, 2)) ctz-def-linear("P", "A", "B", 0.3) // P is 30% from A to B ctz-def-linear("Q", "A", "B", 1.5) // Q extends beyond B ctz-draw(segment: ("A", "B"), stroke: black) ctz-draw(segment: ("B", "Q"), stroke: gray + 0.5pt) ctz-draw(points: ("A", "B", "P", "Q"), labels: (A: "left", B: "above", P: "below", Q: "right")) }) ``` -------------------------------- ### Find Line-Circle Intersection - ctz-def-lc Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Finds the intersection points of a line with a circle. It requires the names for the intersection points (can be one or two) and the names of the line and the circle. ```typst #ctz-canvas(length: 0.7cm, { import cetz.draw: * ctz-init() ctz-def-points(O: (0, 0), R: (3, 0), A: (-2, 2), B: (4, 1)) ctz-def-line("L1", "A", "B") ctz-def-circle("C1", "O", through: "R") ctz-def-lc(("I1", "I2"), "L1", "C1") // Two intersection points ctz-draw("C1", stroke: blue) ctz-label-circle("C1", $C_1$, pos: "above", dist: 0.2) ctz-set-clip(-4, -4, 5, 4) ctz-draw-line-global-clip("A", "B", add: (2, 2), stroke: red) ctz-draw(points: ("O", "I1", "I2"), labels: (O: "below", I1: "above left", I2: "above right")) }) ``` -------------------------------- ### Define Ellipse and Foci - ctz-def-ellipse Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Defines an ellipse by its center, x-radius, y-radius, and rotation angle. It also shows how to retrieve the foci of the ellipse using `ctz-def-ellipse-foci`. This is useful for drawing and analyzing ellipses. ```typst #ctz-canvas(length: 0.7cm, { import cetz.draw: * ctz-init() ctz-def-ellipse("E", (0, 0), 3, 2, angle: 20deg) ctz-draw("E", stroke: blue) // Get the foci as named points ctz-def-ellipse-foci("F1", "F2", (0, 0), 3, 2, angle: 20deg) ctz-draw(points: ("F1", "F2"), labels: (F1: "below", F2: "below")) }) ``` -------------------------------- ### Unified Drawing Function - ctz-draw Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt The ctz-draw function in Typst is a versatile drawing utility that can render named geometric objects or unnamed constructs directly. It supports drawing points, paths, circles, circumcircles, incircles, and more, with options for styling and labeling. ```typst #ctz-canvas(length: 0.6cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (3, 0), C: (1.5, 2)) // Draw named circle ctz-def-circle("myCircle", (1.5, 1), radius: 2.5) ctz-draw("myCircle", stroke: gray + 0.5pt) // Draw unnamed constructs directly ctz-draw(path: "A--B--C--A", stroke: black) // Path/polyline ctz-draw(circumcircle: ("A", "B", "C"), stroke: blue) // Circumcircle ctz-draw(incircle: ("A", "B", "C"), stroke: red) // Incircle ctz-draw(points: ("A", "B", "C"), labels: true) // Points with default labels // More draw options: // ctz-draw(circle-r: ((0, 0), 1.5), stroke: green) // ctz-draw(circle-through: ("O", "A"), stroke: blue) // ctz-draw(ellipse: ((0, 0), 3, 2, 20deg), stroke: black) // ctz-draw(segment: ("A", "B"), stroke: maroon) // ctz-draw(arc: (center: "O", start: "A", end: "B"), stroke: orange) }) ``` -------------------------------- ### Scale Point with Homothety - ctz-def-homothety Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Scales a point from a center by a given factor. This function is useful for geometric transformations and creating scaled versions of shapes. It takes the name of the new point, the original point, the center of homothety, and the scaling factor as arguments. ```typst #ctz-canvas(length: 0.7cm, { import cetz.draw: * ctz-init() ctz-def-points(O: (0, 0), A: (2, 1), B: (3, 2), C: (1, 2.5)) ctz-def-homothety("Ap", "A", "O", 2) // Scale A by factor 2 from O ctz-def-homothety("Bp", "B", "O", 2) ctz-def-homothety("Cp", "C", "O", 2) ctz-draw(line: ("A", "B", "C", "A"), stroke: black) ctz-draw(line: ("Ap", "Bp", "Cp", "Ap"), stroke: blue) ctz-draw(segment: ("O", "Ap"), stroke: gray + 0.3pt) ctz-draw(segment: ("O", "Bp"), stroke: gray + 0.3pt) ctz-draw(segment: ("O", "Cp"), stroke: gray + 0.3pt) ctz-draw(points: ("O", "A", "B", "C", "Ap", "Bp", "Cp"), labels: (O: "below left")) }) ``` -------------------------------- ### Find Line-Line Intersection - ctz-def-ll Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Finds the intersection point of two lines. It takes the name for the intersection point and the names of the two lines as input. ```typst #ctz-canvas(length: 0.8cm, { import cetz.draw: * ctz-init() ctz-def-points(A: (0, 0), B: (4, 3), C: (4, 0), D: (0, 2.5)) ctz-def-line("L1", "A", "B") ctz-def-line("L2", "C", "D") ctz-def-ll("I", "L1", "L2") // Intersection point ctz-draw("L1", stroke: blue) ctz-draw("L2", stroke: red) ctz-draw(points: ("A", "B", "C", "D", "I"), labels: (I: "above")) }) ``` -------------------------------- ### Define Parabola using Focus and Directrix - ctz-def-parabola Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Defines a parabola in Typst using the ctz-def-parabola function. It requires the focus point and two points defining the directrix line. The 'extent' parameter controls the drawing range. This function is part of the ctz-euclide package and relies on ctz-canvas for rendering. ```typst #ctz-canvas(length: 0.7cm, { import cetz.draw: * ctz-init() ctz-def-points(F: (0, 0), D1: (-2, -3), D2: (-2, 3)) ctz-def-parabola("P", "F", ("D1", "D2"), extent: 4) ctz-draw("P", stroke: blue) // Draw directrix and focus ctz-draw(segment: ("D1", "D2"), stroke: gray) ctz-draw(points: ("F",), labels: (F: "right")) }) ``` -------------------------------- ### Find Circle-Circle Intersection - ctz-def-cc Source: https://context7.com/nathan-ed/typst-package-ctz-euclide/llms.txt Finds the intersection points of two circles. It takes the names for the intersection points (can be one or two) and the names of the two circles. ```typst #ctz-canvas(length: 0.65cm, { import cetz.draw: * ctz-init() ctz-def-points(O1: (0, 0), O2: (3, 0), R1: (2.5, 0), R2: (5.5, 0)) ctz-def-circle("C1", "O1", through: "R1") ctz-def-circle("C2", "O2", through: "R2") ctz-def-cc(("I1", "I2"), "C1", "C2") // Two intersection points ctz-draw("C1", stroke: blue) ctz-draw("C2", stroke: red) ctz-label-circle("C1", $C_1$, pos: "above left", dist: 0.2) ctz-label-circle("C2", $C_2$, pos: "above right", dist: 0.2) ctz-draw(points: ("O1", "O2", "I1", "I2"), labels: (I1: "above", I2: "below")) }) ```