A blog documenting projects and ideas

Theory about plotting (x,y) co-ordinates using any kind of plotter

For a college project last year, I built a plotter using cd drives. It had two cd drives in it, one for x direction and one for y. Pretty quickly it was drawing basic shapes like circles and squares. This was done by creating a simple function that accepted two arguments : the x and y co-ordinates to move to. Every step of the stepper motors was counted. So the positon of the platform was known. For example if the marker was at position (50,50) and I passed (30,60) to the function. The x-stepper would rotate 20 steps in the negative direction and the y stepper 10 steps in the positive direction. So printing out simple shapes was easy, but I wanted to be able to print out pictures that were made on a computer. Look at the picture below for an example of an image that could be sent to the printer:

If I could find all of the x-y points of the pixels that make up this line, I could pass them to my x-y function and the plotter would draw the line. Sounds easy! Unfortunately there are some more things to think about before this will work properly . The first thing is the computer program that is going to find all of the x-y points of the line. This program won’t ‘follow the line’ as in, it wont start at one end of the line and spit out all of the x-y points in order, as if the line was being traced by hand. Instead it would start at an edge of the image and move across. Wherever it finds a black pixel, this x-y co-ordinate is stored in an array. This is kind of like how a traditional printer works, start at top row of pixels, move across, down one row, move across etc. This is known as the rastor method of printing. Laser cutters and plotters are much better suited to vector plotting. So we need to figure out how to convert the array of pixels from raster to vector. If the array of pixels was sent as is (raster format) to the the laser printer or plotter. This would be the result:

This GIF is presuming that the laser or marker is turned off when moving between the points. If like in my case it was a marker resting on a moving platform. The image would turn out like the gif below because it never leaves the platform surface:

This method of plotting results in a jerky kind of motion as opposed to smoothly following the curve of a line. What we want is for the program to find an x-y point at one side of the line, and then ‘follow’ the line. As in, we want it to start of at one x-y point and then move to the closest x-y point after that (joining the dots). Then keep doing this until all of the points on the line have been recorded.

One way of approaching this problem is to think about a single pixel and it’s immediate neighbours. Most pixels will have eight neighbouring pixels, as shown in the image below.

Take for example this black line:

One way to arrange the points in the way we want is to start at a pixel, say for example the pixel where the line begins in the bottom left of the image. Immediately the x-y co-ordinates of this pixel are added to x-y points list. Then ask the question, are any of my immediate neighbours active? Notice in this case that this pixel has two ‘active’ neighbours. In this case it is always best to move to a pixel that is up, down, left or right. If we moved to the diagonal pixel, the chain could be broken because it may then move to the left pixel. As each new pixel is found, its x-y co-ordinate is added to a list. See the gif below for what I mean:

This is an example of why non-diagonal pixels should be give priority.

If priority is given to the non-diagonal pixels, things work quite nicely. There is an added condition that if a pixel has already been found, don’t move to that pixel. Here is an example of these simple rules in action:

Here is a simulation of what it would look like plotting an image after the points have been re-arranged in a vector type format:

It’s not working perfectly yet, I’m not sure why it traces the first part twice. This is just a rough idea at the moment so the kinks will get worked out later.