Monthly Archives: December 2007

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.

Straightening scanned plans and working out their pixel scale

Looks like I do have a bit of time to do one or two more blogs…
 
When you scan a plan from a book, 99.9 times out of a 100 they are not perfectly straight.
Using a paint program it is a relatively simple process to fix this.
It is also a good idea to work out the pixel scale for the image.
This can then be used to get unlisted dimensions from plans by using a pixel tool in a 2D paint program.
First load up your image.
My paint tool (the rather ancient Picture Publisher 8) has a pointer tool that lets me mark out a rectangle on an image without drawing anything.

plan1

 

The status bar shows the start coordinates and the width and height of the box.
 

plan2

Most locomotive drawings show the rail top as a line. Using one end of this line as a start point I draw the rectangle to the other end of the rail top line.
In the example below (red rectangle) it shows I have a height of 25 and a width of 2965.
 
 
I then start up the most useful application in Windows – the calculator. 
Make sure it is switched to Scientific view.
 

plan3

 
Divide the height by the width:
25 / 2965 = 0.0084317032040472175379426644182125
 
Then click Inv and press Tan
Inv Tan  =  0.48308955972084815380076833108458
This is the number of degrees that the image must be rotated by.
 
I then select the rotate by arbitrary amount option in my paint program and enter 0.483 degrees (anti-clockwise)
  

Now we have a horizontal plan, I pick a known dimension from the drawing, In this case the 32′ wheelbase.
 
plan4
This is 1532 pixels wide.
This translates to 1523/32  =  47.59 pixels per foot
or the other way up (32 * 12) / 1523 = 0.2521 inches per pixel
and multiply by 2.54 to get to centimetres per pixel = 0.6404
 
So now, if you measure 10 pixels on the drawing you know it is 10 * 0.2521 = 25.2 inches or 64cm
 
I usually mark this information directly on the drawing that way it never gets lost – provided you remember to save the altered image file.

Christmas & stuff

Most of my new N gauge train set has arrived and christmas is fast approaching. It’s the season to take time off from the train sim hobby… Not
 
I’ll try and sneak in a bit more programming and modelling whilst I’m off work.
 
Here’s one I did yesterday – 7500 polys, for that! My first model using the new extra high poly wheels.
 
SFCAN041
You can see the full size image in the picture gallery.
 
Anyway if I don’t type anything before, *************** Happy Christmas everyone ***************.

Plugins

I’ve been busy programming the FSX plugins this week, fixing a few bugs and adding the attachment tool.
I’ve also been reviewing the future of the TS Engineer plugin.
 
I have changed the materials generated for the wheel rim to make those polygons easily selectible (by material)
I also incorporated a couple of extra faces to the flange profile to make it a bit more accurate.
 
Here is a sample of the output:
 
This is starting to build a serious number of polygons – the pacific wheelset, using a 40 sided rim, generated over 9000 polys for the wheels alone.