I spent some of today learning basic, but useful calculus. There are various bits of maths that never made sense to me, and which seemed really complicated. For example working out if two lines intersect each other. Previously whenever I tried to understand this the maths confused me, so this time I tried a different method.
The great thing about 2D geometry maths is that it can be drawn on a piece of graph paper. Finding out whether two lines cross on a piece of graph paper is fairly obvious, and the line lengths and so on can be measured with a ruler. It provides an excellent way of checking the accuracy of code. What I did was draw two intersecting lines on a piece of graph paper, work out the co-ordinates of the intersection, and then manually work through the equations I found on Paul Bourke’s excellent website. After ten minutes of computing I came out with an answer that was exactly the same as what I’d worked out on my graph.
I tried the same with a circle/line intersection test and that was equally accurate and successful.
Following on from this I created two test Processing applications just to make sure the code worked as I expected. They’re nothing too fancy, but they illustrate the point well. Test the code below:
- line/line intersection – click to set the points for the lines, the red dot shows where the intersection will be
- circle/line intersection – click to set the points for the line, then click to set the circle and its radius. Blue line shows the radius, green line is drawn from the centre of the circle towards the test line.
I often wonder if the things I found difficult back then were due to motivation as much as difficulty. I’d love to go through some of that old work and after reading this article I may just do that. Maybe flick through an old A Level revision book or something
Thanks for the inspiration!