2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
title: Fitting the neck opening
|
2023-09-30 14:04:18 +02:00
|
|
|
order: 70
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-10 04:50:43 +02:00
|
|
|
We are not going to create some opening that we _hope_ is the right size, we're
|
|
|
|
going to make sure it is. Here's how we'll make sure the neck opening is _just
|
|
|
|
right_:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-10 04:50:43 +02:00
|
|
|
<Example tutorial caption="It might look the same as before, but now it's just right">
|
2024-03-14 02:13:56 +00:00
|
|
|
```design/src/bib.mjs
|
2023-01-06 19:29:29 -08:00
|
|
|
function draftBib({
|
|
|
|
Path,
|
|
|
|
Point,
|
|
|
|
paths,
|
|
|
|
points,
|
2022-10-10 04:50:43 +02:00
|
|
|
measurements,
|
|
|
|
options,
|
|
|
|
part,
|
|
|
|
}) {
|
|
|
|
|
2024-03-12 02:02:06 +00:00
|
|
|
/*
|
|
|
|
* Construct the quarter neck opening
|
|
|
|
*/
|
2024-03-14 02:13:56 +00:00
|
|
|
// highlight-start
|
2022-10-10 04:50:43 +02:00
|
|
|
let tweak = 1
|
|
|
|
let target = (measurements.head * options.neckRatio) /4
|
|
|
|
let delta
|
|
|
|
do {
|
2024-03-14 02:13:56 +00:00
|
|
|
// highlight-end
|
2024-03-12 02:02:06 +00:00
|
|
|
points.right = new Point(
|
2024-03-14 02:13:56 +00:00
|
|
|
// highlight-start
|
2024-03-12 02:02:06 +00:00
|
|
|
tweak * measurements.head / 10,
|
2024-03-14 02:13:56 +00:00
|
|
|
// highlight-end
|
2024-03-12 02:02:06 +00:00
|
|
|
0
|
|
|
|
)
|
|
|
|
points.bottom = new Point(
|
|
|
|
0,
|
2024-03-14 02:13:56 +00:00
|
|
|
// highlight-start
|
2024-03-12 02:02:06 +00:00
|
|
|
tweak * measurements.head / 12
|
2024-03-14 02:13:56 +00:00
|
|
|
// highlight-end
|
2024-03-12 02:02:06 +00:00
|
|
|
)
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2024-03-12 02:02:06 +00:00
|
|
|
points.rightCp1 = points.right.shift(
|
|
|
|
90,
|
|
|
|
points.bottom.dy(points.right) / 2
|
|
|
|
)
|
|
|
|
points.bottomCp2 = points.bottom.shift(
|
|
|
|
0,
|
|
|
|
points.bottom.dx(points.right) / 2
|
|
|
|
)
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2023-08-08 13:20:46 -05:00
|
|
|
paths.quarterNeck = new Path()
|
|
|
|
.move(points.right)
|
2024-03-12 02:02:06 +00:00
|
|
|
.curve(
|
|
|
|
points.rightCp1,
|
|
|
|
points.bottomCp2,
|
|
|
|
points.bottom
|
|
|
|
)
|
2023-01-06 19:29:29 -08:00
|
|
|
|
2024-03-14 02:13:56 +00:00
|
|
|
|
|
|
|
// highlight-start
|
2023-08-08 13:20:46 -05:00
|
|
|
delta = paths.quarterNeck.length() - target
|
2022-10-10 04:50:43 +02:00
|
|
|
if (delta > 0) tweak = tweak * 0.99
|
|
|
|
else tweak = tweak * 1.02
|
|
|
|
} while (Math.abs(delta) > 1)
|
2024-03-14 02:13:56 +00:00
|
|
|
// highlight-end
|
2022-10-10 04:50:43 +02:00
|
|
|
return part
|
|
|
|
}
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|
2022-10-10 04:50:43 +02:00
|
|
|
</Example>
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
We've added a few new variables:
|
|
|
|
|
2022-10-10 04:50:43 +02:00
|
|
|
- `tweak`: A _tweak factor_ that we'll use to increase or decrease the neck
|
|
|
|
opening by making it more or less than 1
|
2022-02-20 14:44:38 +01:00
|
|
|
- `target`: How long our (quarter) neck opening should be
|
2022-10-10 04:50:43 +02:00
|
|
|
- `delta`: How far we're off. Positive numbers mean it's too long, negative
|
|
|
|
means too short
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-10 04:50:43 +02:00
|
|
|
Now that we know what `target` is, we construct our path as we did before. But
|
|
|
|
this time around, we multiply our point coordinates with our `tweak` variable
|
|
|
|
(1 at the start).
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-10 04:50:43 +02:00
|
|
|
Then, we compare our `target` to the result of `paths.neck.length()` which —
|
|
|
|
you guessed it — returns the length of our neck path.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-10 04:50:43 +02:00
|
|
|
If the delta is positive, our path is too long and we reduce the tweak factor.
|
|
|
|
If the delta is negative, our path is too short and we increase the tweak
|
|
|
|
factor.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-10 04:50:43 +02:00
|
|
|
We keep on doing this until `Math.abs(delta)` is less than 1. Meaning that we
|
2022-12-29 06:25:01 -08:00
|
|
|
are within 1 mm of our target value.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-10 04:50:43 +02:00
|
|
|
Now that we're happy with the length of our quarter neck opening, let's
|
2024-03-12 02:02:06 +00:00
|
|
|
complete the entire neck opening.
|