title: How do I get three non-colinear points on a plane? - C++
body: <p>I'm trying to implement at line-plane intersection algorithm. According to <a href="http://en.wikipedia.org/wiki/Line-plane_intersection" rel="nofollow">Wikipedia</a> I need three non-colinear points on the plane to do that.</p>
  
  <p>I therefore tried implementing <a href="http://answers.yahoo.com/question/index?qid=20110208155831AAAuuwO&amp;r=w&amp;show_comments=true&amp;pa=FZB6NWHjDG3N56z6v_2xXHROAYBIZOHrMtsP40rDtUdMwIdIub7uGQ--&amp;paid=add_comment#openions" rel="nofollow">this algorithm</a> in C++, however. Something is definitely wrong, cause it makes no sense that I can choose whatever x and y coordinates and they'll fit in the plane. What if the plane is vertical and along the x-axis? No point with y=1 would then be in the plane.</p>
  
  <p>I realize that this problem has been posted a lot on StackOverflow, and I see lots of solutions where the plane is defined by 3 points. But I only have a normal and a position. And I can't test my line-plane intersection algorithm before I sort out my non-colinear point finder.</p>
  
  <p>The problem right now, is that I'm dividing by normal.z, and that obviously won't work when normal.z is 0.</p>
  
  <p>I'm testing with this plane: Plane* p = new Plane(Color(), Vec3d(0.0,0.0,0.0), Vec3d(0.0,1.0,0.0)); // second parameter : position, third parameter : normal</p>
  
  <p>The current code gives this incorrect answer: </p>
  
  <pre><code>{0 , 0 , 0} // alright, this is the original
  {12.8377 , 17.2728 , -inf} // obviously this is not a non-colinear point on the given plane
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre><code>std::vector&lt;Vec3d&gt;* Plane::getThreeNonColinearPoints() {
      std::vector&lt;Vec3d&gt;* v = new std::vector&lt;Vec3d&gt;();
  
      v-&gt;push_back(Vec3d(position.x, position.y, position.z)); // original position can serve as one of the three non-colinear points.
  
      srandom(time(NULL));
  
      double rx, ry, rz, start;
  
      rx = Plane::fRand(10.0, 20.0);
      ry = Plane::fRand(10.0, 20.0);
      // Formula from here: http://en.wikipedia.org/wiki/Plane_(geometry)#Definition_with_a_point_and_a_normal_vector
      // nx(x-x0) + ny(y-y0) + nz(z-z0) = 0
      // |-----------------| &lt;- this is "start"
      //I'll try to insert position as x0,y0,z0 and normal as nx,ny,nz, and solve the equation
      start = normal.x * (rx - position.x) + normal.y * (ry - position.y);
      // nz(z-z0) = -start
      start = -start;
      // (z-z0) = start/nz
      start /= normal.z; // division by zero
      // z = start+z0
      start += position.z;
      rz = start;
  
      v-&gt;push_back(Vec3d(rx, ry, rz));
  
      // TODO one more point
  
      return v;
  }
  </code></pre>
  
  <p>I realize that I might be trying to solve this totally wrong. If so, please link a concrete implementation of this. I'm sure it must exist, when I see so many line-plane intersection implementations.</p>
  
  <p>Thanks in advance.</p>