Create an ellipse / circle in Unity + C# - using Point3d and Virtualdraw

Asked

Viewed 283 times

2

I need to implement a Unity project, creating an ellipse. In the project there is already the code of creation of "line" and "rectangle" that works perfectly. The project is for a master’s degree and professor has already made available a "skeleton" of the code. So the code part of the circle is with the code that creates the line.

Code that creates the rectangle:

private void draw(double x, double y, double z) //criar retangulo
{
  string text;

  if (m_pts.Count != 1)
    return;

  if (m_pDrawObj == null)
    return;

  // obtain initial and final point in local coordenate system
  Point3D p00 = m_plane.uvPoint(m_pts[0]);
  Point3D p11 = m_plane.uvPoint(new Point3D(x,y,z));

  // obtain other corner points
  Point3D p01 = m_plane.eval(p00.getX(), p11.getY());
  Point3D p10 = m_plane.eval(p11.getX(), p00.getY());

  m_pDrawObj.Line(m_pts[0].getX(), m_pts[0].getY(), m_pts[0].getZ(), p01.getX(), p01.getY(), p01.getZ());
  m_pDrawObj.Line(p01.getX(), p01.getY(), p01.getZ(), x, y, z);
  m_pDrawObj.Line(m_pts[0].getX(), m_pts[0].getY(), m_pts[0].getZ(), p10.getX(), p10.getY(), p10.getZ());
  m_pDrawObj.Line(p10.getX(), p10.getY(), p10.getZ(), x, y, z);

  // draw text update length
  Point3D pt = new Point3D(x, y, z);
  text = "Rectangle = " + m_pts[0].distance(pt).ToString();

  Point3D c = (m_pts[0] + pt) / 2.0;
  m_pDrawObj.text(c.getX(), c.getY(), c.getZ(), text);

}

Circle code:

private void draw(double x, double y, double z) //criar circulo
    {
        string text;

        if (m_pts.Count != 1)
            return;

        if (m_pDrawObj == null)
            return;

        m_pDrawObj.Line(m_pts[0].getX(), m_pts[0].getY(), m_pts[0].getZ(), x, y, z);

        // draw text update length
        Point3D pt = new Point3D(x, y, z);

        text = "Line = " + m_pts[0].distance(pt).ToString();

        Point3D c = (m_pts[0] + pt) / 2.0;

        m_pDrawObj.text(c.getX(), c.getY(), c.getZ(), text);

    }

If possible, I would like it to be indicated how I can create a circle in this project, already using this point3D class and Virtualdraw.Line. I’ve done several searches but I couldn’t find anything similar to the code that already exists

Here it is possible to see the project running, basically is to click on the figure circle on the top and click and drag on the plane and assemble the circle

Any help will be welcome! Thank you.

  • I only saw her question today, but even so far she has had no answer or even a comment. The reason: it is very difficult to help you, because your code is difficult to understand. Take the rectangle drawing, for example. The function receives a single 3D coordinate! The drawing itself seems to use structures that external (such a m_pts, for example). As much as one could give a tangential answer, the fact that your question is difficult discourages this.

  • My suggestion then is: create a [mcve] that reproduces what you already have and your difficulty, and make available so that someone can download, test and help you pragmatically. :)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.