How to plot (x,y,z)

Is there anyway to plot x(from x textbox), y(from y textbox), and z(from z textbox) in vb form? It is windows application. I have three text boxes that indicates x,y,z coordinate. I was wondering if there is any tool or method to show this point to user.

Answers


There are two main avenues here. 1) Transform the (x,y,z) coordinate into a planar project (x,y) and use gdi+ to draw on the screen, or 2) Use opentk to draw a point directly into an GLControl, but you have to setup the viewport and projection first.

It is not very pretty, but here is a proof of concept with VS2010 using OpenTK.

public partial class Form1 : Form
{
    bool loaded=false;

    public Form1()
    {
        InitializeComponent();
    }

    public Vector3 PointCoordinates
    {
        get
        {
            float x=0, y=0, z=0;
            float.TryParse(xTextBox.Text, out x);
            float.TryParse(yTextBox.Text, out y);
            float.TryParse(zTextBox.Text, out z);

            return new Vector3(x, y, z);
        }
        set
        {
            xTextBox.Text=value.X.ToString();
            yTextBox.Text=value.Y.ToString();
            zTextBox.Text=value.Z.ToString();
        }
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        PointCoordinates=new Vector3(0, 0, 0);
        loaded=true;
        SetupViewPort();
    }

    private void glControl1_Resize(object sender, EventArgs e)
    {
        if(!loaded) return;
        SetupViewPort();
    }

    private void glControl1_Paint(object sender, PaintEventArgs e)
    {
        glControl1.MakeCurrent();
        GL.ClearColor(glControl1.BackColor);
        GL.Clear(ClearBufferMask.ColorBufferBit|ClearBufferMask.DepthBufferBit);

        GL.MatrixMode(MatrixMode.Modelview);
        GL.LoadIdentity();

        SetupCamera();

        // Draw Coordinate System
        GL.LineWidth(1.5f);
        GL.Begin(PrimitiveType.Lines);
        GL.Color3(Color.Red);
        GL.Vertex3(0, 0, 0);
        GL.Vertex3(1, 0, 0);
        GL.Vertex3(0.85, 0.05, -0.05);
        GL.Vertex3(1, 0, 0);
        GL.Vertex3(0.85, -0.05, 0.05);
        GL.Vertex3(1, 0, 0);
        GL.Color3(Color.Green);
        GL.Vertex3(0, 0, 0);
        GL.Vertex3(0, 1, 0);
        GL.Vertex3(-0.05, 0.85, 0.05);
        GL.Vertex3(0, 1, 0);
        GL.Vertex3(0.05, 0.85, -0.05);
        GL.Vertex3(0, 1, 0);
        GL.Color3(Color.Blue);
        GL.Vertex3(0, 0, 0);
        GL.Vertex3(0, 0, 1);
        GL.Vertex3(-0.05, 0.05, 0.85);
        GL.Vertex3(0, 0, 1);
        GL.Vertex3(0.05, -0.05, 0.85);
        GL.Vertex3(0, 0, 1);
        GL.End();

        // Draw a single point
        var vector=PointCoordinates;
        GL.PointSize(5f);
        GL.Begin(PrimitiveType.Points);
        GL.Color3(Color.Black);
        GL.Vertex3(vector);
        GL.End();
        GL.PointSize(3f);
        GL.Begin(PrimitiveType.Points);
        GL.Color3(Color.Yellow);
        GL.Vertex3(vector);
        GL.End();

        glControl1.SwapBuffers();
    }

    void SetupViewPort()
    {
        float wt=Math.Max(1, glControl1.Width);
        float ht=Math.Max(1, glControl1.Height);
        float sz=(float)Math.Sqrt(ht*wt);
        GL.Viewport((int)(wt-sz)/2, (int)(ht-sz)/2, (int)sz, (int)sz);
        var ortho=Matrix4.CreateOrthographic(
            10f, 10f, 1f, 200f);
        GL.MatrixMode(MatrixMode.Projection);
        GL.LoadMatrix(ref ortho);
    }

    void SetupCamera()
    {
        Matrix4 lookAt=Matrix4.LookAt(
                        10f, 5f, 15f,
                        0f, 0f, 0f,
                        0f, 1f, 0f);
        GL.MatrixMode(MatrixMode.Modelview);
        GL.LoadMatrix(ref lookAt);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        glControl1.Refresh();
    }

}

Need Your Help

MySQL query grouping by date and retrieving varchar value on row

php mysql

It's highly likely this has been answered elsewhere, i can't find anything so if you can link to another post that would be ace.

How to retain f:viewParam values after postback with validation failed

validation jsf jsf-2 postback viewparams

I have xhtml page with simple form. This page is using for several data tables. To specify data table (and so on), I use GET request parameters. xhtml page receive it through