Click here to Skip to main content
15,896,063 members
Articles / Programming Languages / C#

Plot 3D surfaces

Rate me:
Please Sign up or sign in to vote.
4.86/5 (55 votes)
21 Feb 20072 min read 256.2K   17.1K   135  
Simply render a 3D surface on your screen without OpenGL/DirectX.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Plot3D
{
    public partial class Plot3DMainForm : Form
    {
        Surface3DRenderer sr;
        
        public Plot3DMainForm()
        {
            InitializeComponent();
            sr = new Surface3DRenderer(70, 35, 40, 0, 0, ClientRectangle.Width, ClientRectangle.Height, 0.5, 0, 0);
            sr.ColorSchema = new ColorSchema(tbHue.Value);
            sr.SetFunction("sin(x1)*cos(x2)/(sqrt(sqrt(x1*x1+x2*x2))+1)*10");
            Form1_Resize(null, null);
            ResizeRedraw = true;
            DoubleBuffered = true;
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(BackColor);
            sr.RenderSurface(e.Graphics);
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            sr.ReCalculateTransformationsCoeficients(70, 35, 40, 0, 0, ClientRectangle.Width, ClientRectangle.Height, 0.5, 0, 0);
        }

        private void tbHue_Scroll(object sender, EventArgs e)
        {
            sr.ColorSchema = new ColorSchema(tbHue.Value);
            Invalidate();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Nokia Siemens Networks
Poland Poland
Michał is C# and whole .NET enthusiast. He graduated from computer science MSc studies at Wroclaw University of Technology, Poland.

He is interested in photography and diving. He is member of PADI, currently with divemaster certificate.

His favorite movies are Matrix, Amélie(Le Fabuleux Destin d'Amélie Poulain), Stargate SG-1 TV Serie and comedies of Mel Brooks.

Michał lives in Wroclaw, Poland. To contact Michał, email him at michal.brylka[mail-'"at'"-sign]op.pl.

Comments and Discussions