A “Quick” Cab – and the development of a new Canvas Operation

Still time for one more before Christmas.
A while ago I wrote a Cab builder plugin.
You simply enter a few dimensions for the size, curve height and overhangs and it automatically generates a box with a curved roof.
So that part is easy. I took the dimensions from the plan, as mentioned in the pervious blog post, and filled in the form (dimensions in metres)
 
sw1500-3g
 
Ta-da! A cab with a lovely curved roof in a few seconds.
sw1500-3h
 
Then I hit a problem.
Being a bit of a stickler for straight edges, I couldn’t think of an accurate way to move the points that make up the roof edge to match the plan.
Shown below (I applied a translucent material to the roof so the plan could be seen)
sw1500-3i
 
Ideally the points needed to be "sheared" or I could shift them by hand – but that could lead to inaccuracies.
 
Then I had an idea – I vaguely remember back to my days of experimental physics at university. There was a method of finding the best straight line through a set of points of one axis was known accurately, which the X axis (left/right) is in this case.
A bit of a search threw up the Least Squares methodhttp://www.che.udel.edu/pdf/FittingData.pdf
I put this algorithm into a small program that takes a set of selected points, a fixed axis and a variable axis which then processes them into a straight line.
 
The result is a new operation button for 3D canvas.
From the plan view, I dragged the points, restricting them to Z axis only movement (hold down the Z key)
(I did exaggerate the zig zag for illustrative purposes, normally I would be a bit more accurate when shifting points)
sw1500-4a
 
Select the points and run the operation, selecting the "Align Z, X fixed" option.

sw1500-4b

The result is a mathematically straight line – no human error.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: