title: Plotting an Ellipse in 3D
body: <p>A while ago I had an issue with plotting an ellipse in 3D space. The solution I had seemed to work, and rotated things the way I needed (at the time). The solution I have works almost perfectly. It rotates the ellipses to the correct orientation... However, the start and end points of the ellipse (signified in the picture by the cyan and red crosses) are always aligned incorrectly. Here are some pictures to show what is happening, and what I need to happen.</p>
  
  <p><img src="https://i.stack.imgur.com/hZxB1.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/RSwtp.png" alt="enter image description here"></p>
  
  <p>As you can see the first picture shows the results when rotation only happens on the y-axis, the cyan cross sits on the foot, and the red sits on the opposite end of the ellipse. However the second picture has the ellipse correctly oriented, but the crosses don't seem to end up in the right place. (they should be on the points where the black line joins the ellipse.</p>
  
  <p>The code for it as it stands at the moment is this.</p>
  
  <pre><code>public static void DrawEllipse(Vector3 p1, Vector3 p2, float height, Vector3 up)
  {
      Quaternion quat = Quaternion.identity;
      int halfPoints = 25;
      int totalPoints = halfPoints*2;
      Vector3[] points1 = new Vector3[halfPoints];
      Vector3[] points2 = new Vector3[halfPoints];
      Vector3 midPoint = (p1 + ((p2 - p1)) * 0.5f);
      Vector3 tmp = Vector3.zero;
  
      quat *= Quaternion.LookRotation(Vector3.Cross(up,p2-p1));
  
      for (int i = 0; i &lt; totalPoints; i++)
      {
         // build the coordinates in arbitrary space.
         tmp = Vector3.zero;
         tmp.x = Mathf.Cos(((float)i / totalPoints) * (Mathf.PI * 2)) * (Vector3.Distance(p1, p2) * 0.5f);
         tmp.y = Mathf.Sin(((float)i / totalPoints) * (Mathf.PI * 2)) * height;
  
         // modify the point for correct orientation.
         tmp = (quat * tmp);
  
         // push to the arrays (split to show outward and return halves)
         if (i &lt; halfPoints)
           points1[i] = tmp + midPoint;
         else
           points2[i - halfPoints] = tmp + midPoint;
      }
      DrawPath(points1, Color.cyan, false);
      DrawPath(points2, Color.red, false);
      Debug.DrawLine(p1, p2, Color.black);
      DrawCross(points1[0], 0.2f, Color.cyan);
      DrawCross(points2[0], 0.2f, Color.red);
  }
  </code></pre>
  
  <p>'ve no doubt this is a stupid issue where there's an extra bit of rotation I'm missing, or I'm missing out a tweak to the ellipse generation prior to rotating it, but I've been running in circles for a while now and its time to ask anyone who might know better.</p>