Click here to Skip to main content
15,887,683 members
Articles / Desktop Programming / WPF

High performance WPF 3D Chart

Rate me:
Please Sign up or sign in to vote.
4.89/5 (79 votes)
7 Sep 2009CPOL13 min read 328.4K   26.7K   167  
An article on WPF 3D performance enhancement techniques
//------------------------------------------------------------------
// (c) Copywrite Jianzhong Zhang
// This code is under The Code Project Open License
// Please read the attached license document before using this class
//------------------------------------------------------------------

// class for a 3d pyramid.
// version 0.1

//				   0  
//				/  | \		 
//			   /   1  \
//            /  /   \ \  
//          3/----------2 

namespace WPFChart3D
{
    public class Pyramid3D : Mesh3D
    {
        public Pyramid3D(double size)
        {
            SetMesh();
            double W = size;
            double L = size * System.Math.Sqrt(3)/2;
            double H = size * System.Math.Sqrt(2.0/3.0);
            SetData(W, L, H);
        }

        public Pyramid3D(double W, double L, double H)
        {
            SetMesh();
            SetData(W, L, H);
        }

        // set mesh structure (triangle connection)
        void SetMesh()
        {
            SetSize(4, 4);
            SetTriangle(0, 0, 2, 1);
            SetTriangle(1, 0, 3, 2);
            SetTriangle(2, 0, 1, 3);
            SetTriangle(3, 1, 2, 3);
        }

        // set vertices position
        public void SetData(double W, double L, double H)
	    {
		    SetPoint(0, 0, 0, H);
		    SetPoint(1, 0, L/2, 0);
            SetPoint(2, +W / 2, -L / 2, 0);
            SetPoint(3, -W / 2, -L / 2, 0);
            m_xMin = - W / 2;
            m_xMax = + W / 2;
            m_yMin = - L / 2;
            m_yMax = + L / 2;
            m_zMin = - H / 2;
            m_zMax = + H / 2;
        }
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions