2021-08-25 16:09:31 +02:00
|
|
|
---
|
|
|
|
title: Fitting the neck opening
|
|
|
|
order: 170
|
|
|
|
---
|
|
|
|
|
|
|
|
Here's how we'll make sure the neck opening is *just right*:
|
|
|
|
|
|
|
|
```js
|
2021-08-25 16:16:51 +02:00
|
|
|
let tweak = 1
|
|
|
|
let target = (measurements.head * options.neckRatio) /4
|
|
|
|
let delta
|
2021-08-25 16:09:31 +02:00
|
|
|
do {
|
2021-08-25 16:16:51 +02:00
|
|
|
points.right = new Point(tweak * measurements.head / 10, 0)
|
|
|
|
points.bottom = new Point(0, tweak * measurements.head / 12)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-08-25 16:16:51 +02: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)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
paths.neck = new Path()
|
|
|
|
.move(points.right)
|
2021-08-25 16:16:51 +02:00
|
|
|
.curve(points.rightCp1, points.bottomCp2, points.bottom)
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2021-08-25 16:16:51 +02:00
|
|
|
delta = paths.neck.length() - target
|
|
|
|
if (delta > 0) tweak = tweak * 0.99
|
|
|
|
else tweak = tweak * 1.02
|
|
|
|
} while (Math.abs(delta) > 1)
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
We've added a few new variables:
|
|
|
|
|
|
|
|
- `tweak`: A *tweak factor* that we'll use to increase or decrease the neck opening by making it more or less than 1
|
|
|
|
- `target`: How long our (quarter) neck opening should be
|
|
|
|
- `delta`: How far we're off. Positive numbers mean it's too long, negative means too short
|
|
|
|
|
|
|
|
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).
|
|
|
|
|
|
|
|
Then, we compare our `target` to the result of `paths.neck.length()` which — you guessed it — returns the
|
|
|
|
length of our neck path.
|
|
|
|
|
|
|
|
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:16:51 +02:00
|
|
|
We keep on doing this until `Math.abs(delta)` is less than 1. Meaning that we are within 1mm of our target value.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
<Example pattern="tutorial" part="step2" caption="It might look the same as before, but now it's just right" />
|
|
|
|
|
|
|
|
Now that we're happy with the length of our quarter neck opening, let's construct the entire neck opening.
|
|
|
|
|