User Tools

Site Tools

blog:2023-06-01_c_graph_3d_create_new_project



2023-06-01 C#: Graph 3D Create New Project

  • Found a good project and want to porting to my projects.

My Steps

  • 1, Add file in project
    • ColorSchema.cs
    • FunctionCompiler.cs
    • Graph3D.cs
  • 2, Change Graph3D.cs for prevent FormEditor opent it
  • 3, We can put the Graph3D object on form
  • 4, Porting related codes to my projects

My Test Codes

  •         protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
    
                // This is optional. If you don't want to use Trackbars leave this away.
                //graph3D.AssignTrackBars(trackRho, trackTheta, trackPhi);
    
               // comboRaster.Sorted = false;
               // foreach (eRaster e_Raster in Enum.GetValues(typeof(eRaster)))
               // {
               //     comboRaster.Items.Add(e_Raster);
               // }
               // comboRaster.SelectedIndex = (int)eRaster.Labels;
    
               // comboColors.Sorted = false;
               // foreach (eSchema e_Schema in Enum.GetValues(typeof(eSchema)))
               // {
               //     comboColors.Items.Add(e_Schema);
               // }
                //comboColors.SelectedIndex = (int)eSchema.Rainbow1;
    
               // comboDataSrc.SelectedIndex = 0; // set "Callback"
            }
    
            private void LoadSurface()
            {
                #region int s32_Values definition
    
                int[,] s32_Values = new int[,]
                {
                    { 34767, 34210, 33718, 33096, 32342, 31851, 31228, 30867, 31457, 30867, 30266, 28934, 27984, 26492, 25167, 25167, 25167},
                    { 34669, 34210, 33653, 33096, 32539, 32047, 31490, 30933, 31293, 30671, 29983, 28803, 27886, 26492, 25167, 25167, 25167},
                    { 34603, 34144, 33718, 33227, 32768, 32342, 31719, 30999, 31228, 30333, 29622, 28606, 27886, 26492, 25167, 25167, 25167},
                    { 34472, 34079, 33653, 33161, 32768, 32408, 31785, 31162, 30802, 30048, 29360, 28312, 27755, 26367, 25049, 25049, 25049},
                    { 34210, 33784, 33423, 33161, 32801, 32408, 31785, 31097, 30474, 29622, 29000, 28115, 27623, 26367, 25049, 25049, 25049},
                    { 33980, 33587, 33161, 32935, 32588, 32342, 31621, 30802, 29852, 29000, 28377, 27689, 27421, 26367, 25049, 25049, 25049},
                    { 33522, 33227, 32702, 32615, 32452, 31851, 30933, 30179, 29295, 28358, 27984, 27132, 27301, 26367, 25049, 25049, 25049},
                    { 32672, 32178, 31916, 31469, 31246, 30540, 29852, 29065, 28377, 27623, 27263, 26706, 26935, 26367, 25049, 25049, 25049},
                    { 30769, 30423, 29917, 29231, 29392, 28705, 28075, 27726, 27263, 26691, 26417, 26182, 26575, 26575, 25246, 25246, 25246},
                    { 27525, 27518, 26701, 27334, 27682, 27402, 26903, 26707, 26444, 25887, 25719, 25690, 26122, 26122, 26122, 26122, 26122},
                    { 23475, 23888, 24478, 25330, 26212, 26199, 25701, 25664, 25740, 25013, 24904, 25068, 25374, 25374, 25374, 25374, 25374},
                    { 20677, 21445, 22544, 23593, 24441, 24785, 24538, 24644, 24773, 24299, 24062, 24576, 24510, 24510, 24510, 24510, 24510},
                    { 18743, 19792, 20808, 22086, 22805, 23167, 23486, 23366, 23757, 23411, 23691, 23822, 23822, 23822, 23822, 23822, 23822},
                    { 17334, 18579, 19497, 20775, 21463, 21848, 22288, 22446, 22643, 22446, 22643, 22708, 23069, 23069, 23069, 23069, 23069},
                    { 16155, 17236, 18350, 19399, 20251, 20677, 21016, 21332, 21660, 21791, 21889, 21955, 22217, 22217, 22217, 22217, 22217},
                    { 14746, 15860, 17039, 17990, 18842, 19595, 20050, 20349, 20546, 20840, 20972, 20972, 21332, 21332, 21332, 21332, 21332},
                    { 13337, 14516, 15729, 16679, 17564, 18514, 18907, 19169, 19399, 19661, 19792, 19594, 20152, 20152, 20152, 20152, 20152},
                    { 12452, 13435, 14615, 15499, 16253, 17105, 17596, 17924, 18153, 18285, 18428, 18776, 19104, 19104, 19104, 19104, 19104},
                    { 11469, 12354, 13533, 14287, 15008, 15925, 16187, 16482, 16690, 16976, 17105, 17302, 17531, 17531, 17531, 17531, 17531},
                    { 10486, 11370, 12255, 13009, 13861, 14746, 15172, 15368, 15434, 15630, 15794, 15991, 16351, 16351, 16351, 16351, 16351},
                    {  9684, 10387, 11141, 11796, 12546, 13337, 14029, 14320, 14549, 14811, 14939, 15434, 15794, 15794, 15794, 15794, 15794},
                    {  9059,  9634, 10617, 11141, 11838, 12681, 13411, 13861, 14121, 14624, 14868, 15172, 15368, 15368, 15368, 15368, 15368},
                };
    
                #endregion
    
                cPoint3D[,] i_Points3D = new cPoint3D[s32_Values.GetLength(0), s32_Values.GetLength(1)];
                for (int X = 0; X < s32_Values.GetLength(0); X++)
                {
                    for (int Y = 0; Y < s32_Values.GetLength(1); Y++)
                    {
                        i_Points3D[X, Y] = new cPoint3D(X * 10, Y * 500, s32_Values[X, Y]);
                    }
                }
    
                // Setting one of the strings = null results in hiding this legend
                graph3D_View.AxisX_Legend = "X";
                graph3D_View.AxisY_Legend = "Force";
                graph3D_View.AxisZ_Legend = "Speed";
    
                // IMPORTANT: Normalize X,Y,Z separately because there is an extreme mismatch 
                // between X values (< 300) and Z values (> 30000)
                graph3D_View.SetSurfacePoints(i_Points3D, eNormalize.Separate);
    
                // *********************************
                // eSchema = 0, Autumn
                //         = 1, ColorCube
                //         = 2, Cool
                Color[] c_Colors = ColorSchema.GetSchema((eSchema)10);
                graph3D_View.SetColorScheme(c_Colors, 3);
    
                // *********************************
                // eRaster = 0, Off
                //         = 1, MainAxis
                //         = 2, Raster
                //         = 3, Labels
                graph3D_View.Raster = (eRaster)3;
    
                // *********************************
                graph3D_View.SetCoefficients(1350, 70, 230);
            }

TAGS

  • 84 person(s) visited this page until now.

Permalink blog/2023-06-01_c_graph_3d_create_new_project.txt · Last modified: 2023/06/01 09:55 by jethro

oeffentlich