title: Finding orientation of a point with respect to another point in xy plane
body: <p>I have a problem (and a solution too). What I want to know is how to arrive at &quot;that&quot; solution. &quot;That&quot; solution is perfect and working fine for all possible combinations.</p>
  <p>Assume that you have 3 points in the XY coordinate system: <code>P1(x1, y1)</code>, <code>P2(x2, y2)</code> and <code>P3(x3, y3)</code>.</p>
  <p>Now, join the point P2 with P3. It will result in &quot;ray&quot; originating from point P2 and passing through point P3. I used word <em>ray</em> because I want it in only one direction, i.e. from P2 to P3.</p>
  <p>Now, with respect to point P1, is the <em>ray</em> <code>P2 --&gt; P3</code> in a clockwise or counterclockwise direction?</p>
  <hr />
  <p>Solution is:</p>
  <blockquote>
  <p>use following formulae to find value of z1:</p>
  <p><code>z1 = (x3 - x1)(y2 - y1) - (y3 - y1)(x2 - x1)</code></p>
  <p>If <code>z1</code> is positive, <code>P2 --&gt; P3</code> is clockwise. If <code>z1</code> is negative, <code>P2 --&gt; P3</code> is counterclockwise. And if it is 0 the points are on the same imaginary line extending from <code>P1</code>.</p>
  </blockquote>
  <p>Can someone please help me how to arrive at this solution?</p>