# Ernie's automatic parking valet

I was helping Ernie out in his shed a while back, when his favorite screwdriver suddenly wore out. I offered to go and pick up a new one for him and Ernie thought it was a great opportunity to test-drive his new electric car.

Ernie's car is a work in progress. The body of the car is a rectangular prism exactly 2 m long, 1 m wide and 0.5 m high. On the top is a circular control-dais on which is mounted a steering-wheel, a console with three buttons, and a single acceler-brake pedal (no seat - Ernie believes it is healthier to stand). The car rests on two wheels, one at each end. Each is mounted so its contact point with the ground is on the centre-line of the vehicle and exactly over the relevant end-face of the vehicle. Both the front and back wheels can be turned to steer, through a vertical axis that passes through the wheel's contact point.

I climbed on board to familiarise myself with the controls. "The drive mechanism is a bit unusual," said Ernie. "To move forwards, press the F button. This locks the steering of the back wheel so it is oriented at 0 degrees, parallel to the long axis of the car. The front wheel can be turned up to 90 degrees to either side and is driven by an electric motor to move the car forwards." I was impressed by the steering lock. "So if you turn the wheel to 90 degrees, the whole car will pivot around the contact point of the rear wheel?", I asked. "Correct," replied Ernie, "and if you turn it just under 76 degrees, the car will pivot around one of the back corners".

Ernie explained that with the F button pressed, the car could only go forwards. "Try pressing the R button" he suggested. To my surprise, when I did, the whole steering dais rotated 180 degrees so I was now facing the back of the car. "Now the former front wheel locks into the forward-aft orientation, and steering and drive is through what was the back wheel. It can also be turned by +/-90 degrees, so in reverse the car handles exactly the same as when driving forwards. You can think of the old back as the new front and the old front as the new back".

"And the P button?", I asked. "That is the automatic parking assist" Ernie replied. "If you press that while on the street, the car senses the nearest car-park, calculates exactly the minimum number of maneuvers required to park, then carries them out to park. If you are already parked, it calculates the minimum number of maneuvers required to un-park, and then carries them out.

I asked him to define exactly what he meant by some of the terms he had used:

Maneuver
1) starts with the car staionary
2) forward or reverse is chosen automatically
3) the driving wheel is turned to a fixed angle automatically
4) the car moves a distance automatically then stops

Park
1) a park is always made into a space between two neighbouring vehicles.
2) when parked the car's centre-line is no more than 45 degrees from the curb.
3) when parked every part of the car is closer to the curb than the furthest out parts of both neighbouring vehicles.

Un-park
1) when un-parked the car's centre-line is exactly parallel to the curb.
2) when un-parked every part of the car is further from the curb than the furthest out parts of both neighbouring vehicles.


I headed confidently into town in Ernie's car. I found a suitable gap between two trucks parked outside the Hardware store. The bodies of the trucks were perfect rectangular prisms much longer and wider than Ernie's car. They were parked exactly parallel to the curb, and exactly the same distance out from the curb (note that the road was straight). I stopped the car, exactly parallel to them, with the front face of the car exactly level with the back edge of the gap. When I pressed the P button, the car moved forwards in a single maneuver to park. I happened to have a tape-measure in my pocket and measured the length of the parking space. After picking up the screw-driver I returned to find that the truck parked behind me had moved forwards so the parking space was now significantly shorter. Once again I measured the length of the space. I got into the car, pressed P again and the car automatically un-parked in a single maneuver.

When I returned I described my trip to Ernie (exactly as above), then told him the two distances I had measured. "Interesting", said Ernie, "the exact events you describe wouldn't have been possible if either of the parking spaces had been any shorter". He then went on to tell me exactly what steering angles had been set for each maneuver.

I can't remember the lengths I measured (or the steering angles Ernie calculated). Can you help me?

• That was long... It felt more like reading a short story than a puzzle I have to solve. – warspyking Oct 23 '14 at 0:30
• @warspyking I feel the whole point of a puzzle is that it should entertain - preferably in more ways than one. Hope you enjoy it... – Penguino Oct 23 '14 at 1:08
• This seems like it should have multiple answers. Just to check, there is a single, unique answer, right? I love the story format, by the way, thank you for the extra work that went into setting up this puzzle well. – Jason Patterson Oct 23 '14 at 15:14
• The car has automatic park and both wheels can turn 90 degrees. I'd have made my automatic park turn both wheels 90 degrees and just move into the spot sideways. (I still like the puzzle, I just thought that was going to be the trick) – Joel Rondeau Oct 24 '14 at 12:51
• @JasonPatterson yeah i got disinterested when i realised i might have to math it out. Each wheel has its own turn radius, the distance between them determined by the angle of the wheels, so that when the back wheel is tangent to its turning circle the front wheel is tangent to its circle. now i think it turns into the park, reaches 45 and hits the front truck, then leaves backwards. – user3125280 Oct 27 '14 at 5:32

Illustration

Leaving the parking

The smallest possible parking from where the car still can go out is when the car is at an angle of 45º from the road and both sides of the parking touch the car. You could fit the car in a smaller place if you placed it more parallel to the road, but the car wouldn’t be able to turn, because the parking would need to be at least as long as the diagonal of the car. The required size for a car at 45º is still smaller.

In the position at 45º, even with both sides touching, you still can get out. If the front wheel is at 53.13º, the center of rotation is exactly 1 unit from the rear right corner of the car, and the front left corner starts to moves parallel to the right parking side. As it happens, the inner circle is just large enough to pass the left corner of the parking. This is shown in red lines.

This gives the minimal parking size for the exit maneuver, the size is ${3 \sqrt2\over2}$.

This also defines the target position we need to reach in the parking entry maneuver.

Entering the parking

There are 2 routes to enter the parking from a position parallel to the road. Either you come from the left and do a $3/8$-turn left, or you come from the right and do a $1/8$ turn right.

Given that the maneuver starts exactly parallel to the road and that the car front is exactly level with the end of the parking doesn’t give much choices.

Entering the parking from the left

This scenario is shown in green lines. At this point, we know where the left side of the parking is, we will adjust the right side to the minimum afterwards.

The center of rotation is uniquely determined by the constraints that it must be on the diagonal extending the back of the parked car and on a line 2m back from the left side of the parking.

The inner radius is given by $r = 2+2\sqrt2$.
The outer radius satisfies $R^2 = (r+1)^2 + 2^2 = (3+2\sqrt2)^2 + 4 = (21 + 12\sqrt2)$.
The distance from the center of rotation to the border is $d = \sqrt2+2$.
The minimum parking width that fits the outer radius satisfies: $(width+2)^2 + d^2 = R^2$
This gives the minum width:
$width = \sqrt{R^2 - r^2} - 2 = \sqrt{13 + 8\sqrt2} - 2 = 3.1297…$

Entering the parking from the right

That scenario is shown in blue lines. The calculations are more complicated because we start aligned with the right side of the parking but we don’t know yet where the right side is. We'll have to assume that the inner circle just touches the right corner of the parking and find out what it implies on the inner radius.

Let's call $x$ the vertical distance of the blue center of rotation to the border (the fat gray line):
The inner radius is given by: $r^2 = x^2 + 2^2$
But we also have: $r+1 = x \sqrt2$
This resolves to $x = \sqrt2+\sqrt5$.

If $width$ is the width of the parking, the distance of the blue line from the left parking side is given by $width + 2$ but also by $\sqrt2+x$.
This gives a calculation for the parking width:

$width = \sqrt2+x-2 = 2 \sqrt2+\sqrt5-2 = 3.0645…$

This is slightly better than with the green path. So this is the minimum parking size for the entry maneuver.

For the blue path, the angle of the front wheel is $arctan(2/(r+1/2)) = 23.22º$

Summary

The parking is 3.0645m wide.

The car arrives from the right, parallel to the road. It turns the front wheel 23.22º right and moves forward into the parking.

The parking then shrinks to 2.1213m wide and both vehicles touch the car.

The car doesn’t bother, it reverses direction, turns the front wheel 53.13º right and moves forward for a 3/8 turn until it is back parallel to the road. Facing the traffic as it should.