darker technotes.

Categories

Latest News

Monthly archives


Search




“Hello World” is Lame. My First C App, “inthetriangle”.

At some point, it was realized learning C is something that needs to be done before trying out anything ARM core based. Learning on an AVR, after already knowing how to do things competently on the microcontroller in ASM, was frustrating as it for the most part seemed pointless, introducing a whole other layer of issues that came with the compiler and had nothing to do with the hardware itself. Something tiny was written to test the WinAVR installation, then something better to do was found.

Then the other night, a friend came over and said his C class and the instructor didnt have a working algorithm to find if a test point was within a triangle. So I stared for awhile, convinced it didnt take very complex math to figure it out. The algorithm involved calculating the points that a horizontal line passing thru the test point intercepts the triangle sides (using slope equations and a difference equation) and testing if the test point is between these points. I decided I wanted to code my algorithm in C.

So here is the end result. My first C app, inthetriangle, will indicate if a point is on, within, or outside of a triangle. It will also indicate if the triangle points are invalid because of repeated points or if they actually describe a line segment. Input with scanf() is decidely ghetto. I’ll have to change that.

inthetriangle-0.2.c

Posted by rmrubin September 2007


Comments are closed.