|
1 | 1 | #import "@preview/cetz:0.3.4": canvas, draw
|
2 |
| -#import draw: rect, line, circle, content, hobby, scale |
| 2 | +#import draw: rect, line, circle, content, hobby, scale, set-origin |
3 | 3 |
|
4 | 4 | #set page(width: auto, height: auto, margin: 8pt)
|
5 | 5 |
|
6 | 6 | #canvas({
|
7 | 7 | let arrow-style = (mark: (end: "stealth", fill: black, scale: .75))
|
8 | 8 | let plot-height = 4
|
9 | 9 | let plot-width = 10
|
10 |
| - let y-offset = 4.65 // Reduced from 6 to bring plots closer together |
| 10 | + let y-offset = 4.5 |
11 | 11 |
|
12 | 12 | // Helper to draw axes
|
13 | 13 | let draw-axes(origin, width, height) = {
|
14 | 14 | line(
|
15 |
| - (origin.at(0) - 0.5, origin.at(1)), |
| 15 | + (origin.at(0) - 0.3, origin.at(1)), |
16 | 16 | (origin.at(0) + width, origin.at(1)),
|
17 | 17 | ..arrow-style,
|
18 | 18 | name: "x-axis",
|
19 | 19 | )
|
20 | 20 | line(
|
21 |
| - (origin.at(0), origin.at(1) - 0.5), |
| 21 | + (origin.at(0), origin.at(1) - 0.3), |
22 | 22 | (origin.at(0), origin.at(1) + height),
|
23 | 23 | ..arrow-style,
|
24 | 24 | name: "y-axis",
|
|
31 | 31 |
|
32 | 32 | // Draw double-well potential curve using hobby spline
|
33 | 33 | hobby(
|
34 |
| - (top-origin.at(0) + .5, top-origin.at(1) + 3.5), // start high |
| 34 | + (top-origin.at(0) + .5, top-origin.at(1) + 4), // start high |
35 | 35 | (top-origin.at(0) + 1.7, top-origin.at(1) + 0.4), // left minimum
|
36 | 36 | (top-origin.at(0) + 1.8, top-origin.at(1) + 0.3), // left minimum
|
37 | 37 | (top-origin.at(0) + 5, top-origin.at(1) + 1.5), // up to middle peak
|
38 | 38 | (top-origin.at(0) + 8.2, top-origin.at(1) + 0.3), // right minimum
|
39 | 39 | (top-origin.at(0) + 8.3, top-origin.at(1) + 0.4), // right minimum
|
40 |
| - (top-origin.at(0) + 9.5, top-origin.at(1) + 3.5), // up high again |
| 40 | + (top-origin.at(0) + 9.5, top-origin.at(1) + 4), // up high again |
41 | 41 | omega: 0,
|
42 | 42 | name: "potential-curve",
|
| 43 | + stroke: 1.5pt, |
43 | 44 | )
|
44 | 45 |
|
45 | 46 | // Add "Free Energy" label
|
|
107 | 108 | )
|
108 | 109 |
|
109 | 110 | // Helper function to draw BaTiO3 unit cell
|
110 |
| - // TODO the face-centered oxygen atom positions need fixing and the lines overlap the atoms |
| 111 | + let atom(pos, radius: 0.20, fill: luma(50), ..args) = { |
| 112 | + circle( |
| 113 | + pos, |
| 114 | + radius: radius, |
| 115 | + stroke: none, |
| 116 | + fill: fill, |
| 117 | + ..args |
| 118 | + ) |
| 119 | + circle( |
| 120 | + (), |
| 121 | + radius: radius, |
| 122 | + stroke: none, |
| 123 | + fill: gradient.radial( |
| 124 | + fill.lighten(75%), fill, fill.darken(15%), |
| 125 | + focal-center: (30%, 25%), |
| 126 | + focal-radius: 5%, |
| 127 | + center: (35%, 30%), |
| 128 | + ), |
| 129 | + ) |
| 130 | + } |
111 | 131 | let draw-unit-cell(center-x, center-y, ti-y, cell-name) = {
|
112 | 132 | let (x, y) = (center-x, center-y)
|
113 |
| - let z-offset = 0.3 // Consistent offset for back face |
| 133 | + let z-offset = -1.0 // Consistent offset for back face |
114 | 134 | let cube-style = (stroke: 0.7pt)
|
115 | 135 |
|
| 136 | + |
116 | 137 | // Draw unit cell cube with consistent offsets
|
117 | 138 | rect(
|
118 |
| - (x - 1, y - 1), |
119 |
| - (x + 1, y + 1), |
| 139 | + (x - 1, y - 1, 0), |
| 140 | + (x + 1, y + 1, 0), |
120 | 141 | ..cube-style,
|
121 | 142 | name: cell-name + "-front",
|
122 | 143 | ) // Front face
|
123 | 144 | line(
|
124 |
| - (x - 1, y - 1), |
125 |
| - (x - 1 + z-offset, y - 1 + z-offset), |
| 145 | + (x - 1, y - 1, 0), |
| 146 | + (x - 1, y - 1, z-offset), |
126 | 147 | ..cube-style,
|
127 | 148 | name: cell-name + "-left",
|
128 | 149 | ) // Left edge
|
129 | 150 | line(
|
130 |
| - (x + 1, y - 1), |
131 |
| - (x + 1 + z-offset, y - 1 + z-offset), |
| 151 | + (x + 1, y - 1, 0), |
| 152 | + (x + 1, y - 1, z-offset), |
132 | 153 | ..cube-style,
|
133 | 154 | name: cell-name + "-right",
|
134 | 155 | ) // Right edge
|
135 | 156 | line(
|
136 |
| - (x - 1 + z-offset, y - 1 + z-offset), |
137 |
| - (x + 1 + z-offset, y - 1 + z-offset), |
| 157 | + (x - 1, y - 1, z-offset), |
| 158 | + (x + 1, y - 1, z-offset), |
138 | 159 | ..cube-style,
|
139 | 160 | name: cell-name + "-back",
|
140 | 161 | ) // Back edge
|
141 | 162 | line(
|
142 |
| - (x - 1 + z-offset, y + 1 + z-offset), |
143 |
| - (x + 1 + z-offset, y + 1 + z-offset), |
| 163 | + (x - 1, y + 1, z-offset), |
| 164 | + (x + 1, y + 1, z-offset), |
144 | 165 | ..cube-style,
|
145 | 166 | name: cell-name + "-top-back",
|
146 | 167 | ) // Top back edge
|
147 | 168 | line(
|
148 |
| - (x - 1 + z-offset, y - 1 + z-offset), |
149 |
| - (x - 1 + z-offset, y + 1 + z-offset), |
| 169 | + (x - 1, y - 1, z-offset), |
| 170 | + (x - 1, y + 1, z-offset), |
150 | 171 | ..cube-style,
|
151 | 172 | name: cell-name + "-left-back",
|
152 | 173 | ) // Left back edge
|
153 | 174 | line(
|
154 |
| - (x + 1 + z-offset, y - 1 + z-offset), |
155 |
| - (x + 1 + z-offset, y + 1 + z-offset), |
| 175 | + (x + 1, y - 1, z-offset), |
| 176 | + (x + 1, y + 1, z-offset), |
156 | 177 | ..cube-style,
|
157 | 178 | name: cell-name + "-right-back",
|
158 | 179 | ) // Right back edge
|
159 |
| - |
160 |
| - // Draw Ba atoms (all 8 corners) |
161 |
| - let ba-style = (stroke: none, fill: rgb("#00ffff")) |
162 |
| - for (pos, suffix) in ( |
163 |
| - // Front face corners |
164 |
| - ((x - 1, y - 1), "front-bl"), |
165 |
| - ((x + 1, y - 1), "front-br"), |
166 |
| - ((x - 1, y + 1), "front-tl"), |
167 |
| - ((x + 1, y + 1), "front-tr"), |
168 |
| - // Back face corners |
169 |
| - ((x - 1 + z-offset, y - 1 + z-offset), "back-bl"), |
170 |
| - ((x + 1 + z-offset, y - 1 + z-offset), "back-br"), |
171 |
| - ((x - 1 + z-offset, y + 1 + z-offset), "back-tl"), |
172 |
| - ((x + 1 + z-offset, y + 1 + z-offset), "back-tr"), |
173 |
| - ) { |
174 |
| - circle( |
175 |
| - pos, |
176 |
| - radius: 0.15, |
177 |
| - ..ba-style, |
178 |
| - name: cell-name + "-ba-" + suffix, |
179 |
| - ) |
180 |
| - } |
181 |
| - |
182 |
| - // Draw O atoms (all 6 face centers) |
183 |
| - let o-style = (stroke: none, fill: red) |
184 |
| - for (pos, suffix) in ( |
185 |
| - // Front and back face centers |
186 |
| - ((x, y), "front"), // Front face center |
187 |
| - ((x + z-offset, y + z-offset), "back"), // Back face center |
188 |
| - // Face centers with consistent offsets |
189 |
| - ((x, y + 1), "top"), // Top face center |
190 |
| - ((x, y - 1), "bottom"), // Bottom face center |
191 |
| - ((x - 1, y), "left"), // Left face center |
192 |
| - ((x + 1, y), "right"), // Right face center |
193 |
| - ) { |
194 |
| - circle( |
195 |
| - pos, |
196 |
| - radius: 0.12, |
197 |
| - ..o-style, |
198 |
| - name: cell-name + "-o-" + suffix, |
199 |
| - ) |
200 |
| - } |
201 |
| - |
202 |
| - // Draw Ti atom (center, displaced) |
203 |
| - let ti-style = (stroke: none, fill: gray) |
204 |
| - circle( |
205 |
| - (x + z-offset / 2, y + ti-y), |
206 |
| - radius: 0.1, |
207 |
| - ..ti-style, |
208 |
| - name: cell-name + "-ti", |
| 180 | + line( |
| 181 | + (x + 1, y - -1), |
| 182 | + (x + 1, y - -1, z-offset), |
| 183 | + ..cube-style, |
| 184 | + name: cell-name + "top-right", |
| 185 | + ) // top right edge |
| 186 | + line( |
| 187 | + (x + -1, y - -1), |
| 188 | + (x + -1, y - -1, z-offset), |
| 189 | + ..cube-style, |
| 190 | + name: cell-name + "top-left", |
| 191 | + ) // top right edge |
| 192 | + |
| 193 | + // Define helper functions for each atom style |
| 194 | + let Ba-atom(pos, name) = atom(pos, fill: rgb("#00ffff"), name: cell-name + "-ba-" + name) |
| 195 | + let O-atom(pos, name) = atom( pos, fill: red, name: cell-name + "-o-" + name) |
| 196 | + let Ti-atom(pos) = atom( pos, fill: gray, name: cell-name + "-ti") |
| 197 | + let Ti-O-bond(end-pos, name) = line( |
| 198 | + ((x, y + ti-y, z-offset/2), 15%, end-pos), |
| 199 | + ((x, y + ti-y, z-offset/2), 85%, end-pos), |
| 200 | + stroke: 1pt, |
| 201 | + name: cell-name + "-bond-" + name, |
209 | 202 | )
|
210 | 203 |
|
211 |
| - // Draw Ti-O bonds |
212 |
| - let bond-style = (stroke: (thickness: 0.5pt)) |
213 |
| - for (end-pos, suffix) in ( |
214 |
| - ((x, y), "front"), // Front face center |
215 |
| - ((x + z-offset, y + z-offset), "back"), // Back face center |
216 |
| - ((x, y + 1), "top"), // Top face center |
217 |
| - ((x, y - 1), "bottom"), // Bottom face center |
218 |
| - ((x - 1, y), "left"), // Left face center |
219 |
| - ((x + 1, y), "right"), // Right face center |
220 |
| - ) { |
221 |
| - line( |
222 |
| - (x + z-offset / 2, y + ti-y), // Ti position |
223 |
| - end-pos, |
224 |
| - ..bond-style, |
225 |
| - name: cell-name + "-bond-" + suffix, |
226 |
| - ) |
| 204 | + // --- Back Plane (z = z-offset) --- |
| 205 | + Ba-atom((x - 1, y - 1, z-offset), "back-bl") |
| 206 | + Ba-atom((x + 1, y - 1, z-offset), "back-br") |
| 207 | + Ba-atom((x - 1, y + 1, z-offset), "back-tl") |
| 208 | + Ba-atom((x + 1, y + 1, z-offset), "back-tr") |
| 209 | + O-atom((x, y, z-offset), "back") |
| 210 | + Ti-O-bond((x, y, z-offset), "back") |
| 211 | + |
| 212 | + // --- Middle Plane (z = z-offset/2) --- |
| 213 | + if ti-y >= 0 { |
| 214 | + Ti-O-bond((x, y + 1, z-offset/2), "top") |
| 215 | + } |
| 216 | + if ti-y <= 0 { |
| 217 | + Ti-O-bond((x, y - 1, z-offset/2), "bottom") |
227 | 218 | }
|
| 219 | + Ti-O-bond((x - 1, y, z-offset/2), "left") |
| 220 | + Ti-O-bond((x + 1, y, z-offset/2), "right") |
| 221 | + O-atom((x, y + 1, z-offset/2), "top") |
| 222 | + O-atom((x, y - 1, z-offset/2), "bottom") |
| 223 | + O-atom((x - 1, y, z-offset/2), "left") |
| 224 | + O-atom((x + 1, y, z-offset/2), "right") |
| 225 | + Ti-atom((x, y + ti-y, z-offset/2)) |
| 226 | + |
| 227 | + // --- Front Plane (z = 0) --- |
| 228 | + Ti-O-bond((x, y, 0), "front") |
| 229 | + Ba-atom((x - 1, y - 1, 0), "front-bl") |
| 230 | + Ba-atom((x + 1, y - 1, 0), "front-br") |
| 231 | + Ba-atom((x - 1, y + 1, 0), "front-tl") |
| 232 | + Ba-atom((x + 1, y + 1, 0), "front-tr") |
| 233 | + O-atom((x, y, 0), "front") |
228 | 234 | }
|
229 | 235 |
|
230 | 236 | // Draw three unit cells with different Ti displacements
|
231 |
| - scale(0.75) |
232 |
| - draw-unit-cell(-4, y-offset + 5, -0.2, "cell1") |
233 |
| - draw-unit-cell(0, y-offset + 5, 0, "cell2") |
234 |
| - draw-unit-cell(4, y-offset + 5, 0.2, "cell3") |
| 237 | + scale(0.64) |
| 238 | + set-origin("potential-curve.mid") |
| 239 | + draw-unit-cell(-4.5, 2, -0.2, "cell1") |
| 240 | + draw-unit-cell(-0.5, 2, 0, "cell2") |
| 241 | + draw-unit-cell(3.5, 2, 0.2, "cell3") |
235 | 242 | })
|
0 commit comments