Skip to content or navigation

Write a 3D Software Engine from Scratch

Ever wondered what was involved in making a drawing or CAD program draw a basic line between two points?


We have wondered this too.

Over at Sitepoint, a site for web programming tutorials and education, a Javascript software tutorial explains the process of what is involved in drawing a line between two points. The math and nature of the algorithm is remarkably simple and eloquent.

You Will Never Get to the Wall

Remember that game where someone told you that if you walked half way to the wall in sequential steps, always just walking to the mid-point, you will never actually reach the wall. Ever.

Remember that? 

Like me you probably heard this as a kid and thought it didn’t make common sense but knowing basic math and division knew it make perfect mathematical logic. That is if you grasp infinity.

The Half Problem Ends

Here is how you program a computer to draw a line between two points. You define two points (point 0 and point 1). If the distance between the two points is less than 2 pixels you do nothing.

If the distance is more than 2 pixels you locate the mid-point (point 2). You change the color of this pixel. You repeat this basic algorithm recursively between point 0 and mid-point and between mid-point and point 1. Eventually you cut down the distances until you reach the first rule of this algorithm. And then the line is complete.


01 – To draw a line in 2D or 3D space within a CAD/3D program requires at least a basic algorithm. The trick to this algorithm is divide and conquer.

Over at Sitepoint they provide the coding examples for this in C#, TypeScript and Javascript. If you are a coder or are just curious hop on over and take a look at the code.

The Write a 3D Software Engine from Scratch article is written by David Rouset, developer evangelist at Microsoft. It was published a few days ago. We think it’s cool. And for Part 1 of this story you can click on that here.

Reader Comments

  1. Apollo Spiliotis liked this on Facebook.

  2. Write a 3D Software Engine from Scratch

Comments are closed.