Weekend Programming Challenge – Week #48 Geometry



Let have three points A(x,y), B(x,y), C(x,y). Make code which prints if A->B->C sequence makes clockwise, counter clockwise turn, or A,B,C stay in one line. In the above picture ABC makes counter clockwise turn.

The rules:

You can code the solution in any programming language during the weekend and have to submit it to info@olimex.com latest on Sunday March 30th.

On Monday we will upload the solutions on GitHub https://github.com/OLIMEX/WPC

You can play with your real name or with nick if you want to be anonymous, we will not disclosure your personal info if you do not want to.

5 Comments (+add yours?)

  1. Emiliano Daddario
    Mar 28, 2014 @ 22:04:28

    Easy. Cross product of vectors.


    • Dylan
      Mar 29, 2014 @ 22:26:41

      You seem to have confused this programming challenge with the Twitter quiz, Emiliano.


      • Emiliano Daddario
        Mar 30, 2014 @ 21:50:05

        I’m sure I didn’t confuse this with the twitter quiz, since I haven’t even seen the latter. I intentionally didn’t explain what I meant, I’ll do it now. Let x, y and z be the Cartesian (right-handed) axes. Let AB and BC be the “oriented” vectors (oriented this way: A->B and B->C) in the xy plane. Now, let P be the z coordinate of the cross product of vectors AB X BC. Here is the solution in pseudocode.
        If P>0 then A->B->C->A is a counterclockwise path. Else if P<0 it's clockwise. Else if P==0 it's a degenerate triangle (three collinear points i.e. neither clockwise nor counterclockwise)
        If you choose different vectors the solution could be different.
        If you use the more general winding number trick instead, you need to check its sign.

      • Dylan
        Mar 30, 2014 @ 22:41:03

        Yeah yeah. Submit code to info@olimex.com. And if the “challenge” is to trivial for you… let others take it on for themselves. Oh, and visit Project Euler 😉

  2. Emiliano Daddario
    Mar 28, 2014 @ 22:08:58

    A more general solution for arbitrary polygons (considering a particular polygon among all the possible ones which have these points as vertices) would be the winding number, I used it in the past


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: