Precisely position elements on wavy circle #813
-
wondering if there's a cleaner way to draw this diagram, especially how to best position the arrows, dot and crossed circle on exactly 3, 6, 9 and 12 of the wavy loop. #import "@preview/cetz:0.3.2": canvas, draw, decorations
#import draw: line, content, circle
#set page(width: auto, height: auto, margin: 8pt)
#let equation = $partial_t (diff V) / (diff chi) =$
#let rad = 0.8
#canvas({
// Define styles
let arrow-style = (
stroke: (paint: black, thickness: 0.5pt),
)
// Draw the loop using wave decoration
let loop = circle((1, 0), radius: rad, stroke: none)
decorations.wave(
loop,
amplitude: 0.1,
segments: 16,
close: true,
stroke: (paint: black, thickness: 0.5pt),
name: "loop",
mark: (end: "stealth"),
)
// Add vertices
circle("loop.23%", radius: 0.075, fill: black, name: "dot")
content(
"loop.74.5%",
text(size: 10pt)[$times.circle$],
name: "regulator",
fill: white,
frame: "circle",
stroke: none,
padding: -1.7pt,
)
// Draw input line
line((rel: (-1, 0), to: "dot"), "dot", name: "input", ..arrow-style)
content(
"input.start",
$ partial_t (diff V) / (diff chi) = $,
anchor: "east",
padding: (0, 5pt, 0),
)
// Add momentum label
content((rad, rad * 1.4), $q$, name: "momentum")
content((rad, rad * -1.4), $q$, name: "momentum")
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Yes, you can use #import "@preview/cetz:0.3.2": canvas, draw, decorations
#import draw: line, content, circle, intersections, group, hide
#set page(width: auto, height: auto, margin: 8pt)
#let equation = $partial_t (diff V) / (diff chi) =$
#let rad = 0.8
#canvas({
// Define styles
let arrow-style = (
stroke: (paint: black, thickness: 0.5pt),
)
// Draw the loop using wave decoration
decorations.wave(
circle((1, 0), radius: rad),
amplitude: .1,
segments: 16,
close: true,
stroke: (paint: black, thickness: 0.5pt),
name: "loop",
mark: (end: "stealth"),
)
// Find left and right position on the loop
intersections("loop-points", "loop",
hide(line((rel: (-2 * rad, 0), to: "loop.centroid"),
(rel: (+2 * rad, 0), to: "loop.centroid"))),
hide(line((rel: (0, +2 * rad), to: "loop.centroid"),
(rel: (0, -2 * rad), to: "loop.centroid"))))
// Add vertices
circle("loop-points.0", radius: 0.075, fill: black, name: "dot")
content(
"loop-points.1",
text(size: 10pt)[$times.circle$],
name: "regulator",
fill: white,
frame: "circle",
stroke: none,
padding: -1.7pt,
)
// Draw input line
line((rel: (-1, 0), to: "dot"), "dot", name: "input", ..arrow-style)
content(
"input.start",
$ partial_t (diff V) / (diff chi) = $,
anchor: "east",
padding: (0, 5pt, 0),
)
// Add momentum label
content((rad, rad * 1.4), $q$, name: "momentum")
content((rad, rad * -1.4), $q$, name: "momentum")
// Draw arrows
set-style(mark: (scale: 1.25, fill: black))
mark("loop-points.2", (rel: (1, 0)), symbol: "<", anchor: "center")
mark("loop-points.3", (rel: (1, 0)), symbol: ">", anchor: "center")
}) |
Beta Was this translation helpful? Give feedback.
-
at the risk of asking something that's already documented, i would appreciate any advice on how to fill the gray regions in this diagram #import "@preview/cetz:0.3.2": canvas, draw
#import draw: line, content, arc, rect, set-style, set-viewport
#set page(width: auto, height: auto, margin: 1pt)
// Constants
#let (xmin, xmax) = (-1, 1)
#let (ymin, ymax) = (-0.5, 2.4)
// Set global styles
#let arrow-style = (
mark: (end: "stealth", fill: black, scale: 0.2),
stroke: (thickness: 0.4pt),
)
#set text(size: 8pt)
#canvas({
set-style(stroke: (thickness: 0.4pt))
set-viewport((0, 0), (20, 20), bounds: (12, 12))
// Light gray vertical strip
rect(
(-0.5, 0),
(0.5, ymax),
fill: rgb(128, 128, 128).lighten(80%),
stroke: none,
)
// Draw axes
line((xmin, 0), (xmax, 0), ..arrow-style, name: "x-axis")
line((0, ymin), (0, ymax), ..arrow-style, name: "y-axis")
// Draw tick marks with labels
line((-0.5, -0.02), (-0.5, 0.02), name: "x-tick")
content((-0.5, -0.1), $-1 / 2$, anchor: "north")
line((0.5, -0.02), (0.5, 0.02), name: "x-tick")
content((0.5, -0.1), $1 / 2$, anchor: "north")
line((-0.02, 1), (0.02, 1), name: "i-tick", stroke: (thickness: 0.6pt))
content("i-tick", $i$, anchor: "north-west", padding: 1pt)
// Draw semicircle B and B' (dark red)
arc(
(0, 0),
radius: 1,
start: 0deg,
stop: 180deg,
stroke: (paint: red),
name: "B-arc",
anchor: "origin",
)
content("B-arc.60%", $B$, fill: red, anchor: "south", padding: (0, 0, 3pt))
content("B-arc.40%", $B'$, fill: red, anchor: "south", padding: (0, 0, 3pt))
// Draw vertical lines A and A' (dark blue)
line(
(-0.5, 0),
(-0.5, ymax),
stroke: (paint: blue),
mark: (end: "stealth", fill: blue, scale: 0.2),
name: "A-line",
)
content("A-line.80%", $A$, fill: blue, anchor: "east", padding: (0, 4pt, 0, 0))
line(
(0.5, 0),
(0.5, ymax),
stroke: (paint: blue),
mark: (end: "stealth", fill: blue, scale: 0.2),
name: "A-prime-line",
)
content("A-prime-line.80%", $A'$, fill: blue, anchor: "west", padding: (0, 0, 0, 4pt))
// Add F₀ labels
content("y-axis.80%", $F_0$, anchor: "west", padding: (0, 0, 0, 2pt))
content((rel: (-0.2, -0.2), to: "B-arc.50%"), $F_0'$)
// Draw the extended green arcs (C and C') first
arc(
(0, 0),
radius: 1,
start: 0deg,
stop: 90deg,
stroke: (paint: green),
name: "C-arc",
anchor: "start",
)
content("C-arc.40%", $C$, fill: green, anchor: "north-east", padding: 2pt)
arc(
(0, 0),
radius: 1,
start: 90deg,
stop: 180deg,
stroke: (paint: green),
name: "C-prime-arc",
anchor: "end",
)
content("C-prime-arc.60%", $C'$, fill: green, anchor: "north-west", padding: 2pt)
})
|
Beta Was this translation helpful? Give feedback.
It's this: