wpf 空间坐标系下,画一个立方体轮廓

Posted HelloLLLLL

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wpf 空间坐标系下,画一个立方体轮廓相关的知识,希望对你有一定的参考价值。

wpf C# 空间坐标系下画一个立方体轮廓

代码:

  public partial class MainWindow : Window
    
        public MainWindow()
        
            InitializeComponent();
            Worignpt = new Point(250, 200);//空间坐标系原点
            o = new Point3d(0, 0, 0);
            a = new Point3d(100, 0, 0);
            b = new Point3d(100, 100, 0);
            c = new Point3d(0, 100, 0);
            d = new Point3d(100, 100, 100);
            e = new Point3d(100, 0, 100);
            f = new Point3d(0, 0, 100);
            g = new Point3d(0, 100, 100);
            //xishu = Math.Sqrt(2d) / 2.0;
            xishu = 0.5;
        
        Point Worignpt;
        Point3d o;
        Point3d a;
        Point3d b;
        Point3d c;
        Point3d d;
        Point3d e;
        Point3d f;
        Point3d g;
        double xishu = 0d;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        
            var wo = Worignpt;
            var wa = ConvertCPoint(wo, Convert2d(a));
            var wb = ConvertCPoint(wo, Convert2d(b));
            var wc = ConvertCPoint(wo, Convert2d(c));
            var wd = ConvertCPoint(wo, Convert2d(d));
            var we = ConvertCPoint(wo, Convert2d(this.e));
            var wf = ConvertCPoint(wo, Convert2d(f));
            var wg = ConvertCPoint(wo, Convert2d(g));

            var oa = CreateLine(wo, wa);
            canvas.Children.Add(oa);

            var ab = CreateLine(wa, wb);
            canvas.Children.Add(ab);

            var bc = CreateLine(wb, wc);
            canvas.Children.Add(bc);

            var oc = CreateLine(wo, wc);
            canvas.Children.Add(oc);

            var ae = CreateLine(wa, we);
            canvas.Children.Add(ae);


            var ed = CreateLine(we, wd);
            canvas.Children.Add(ed);

            var db = CreateLine(wd, wb);
            canvas.Children.Add(db);

            var dg = CreateLine(wd, wg);
            canvas.Children.Add(dg);

            var gc = CreateLine(wg, wc);
            canvas.Children.Add(gc);

            var ef = CreateLine(we, wf);
            canvas.Children.Add(ef);

            var fg = CreateLine(wf, wg);
            canvas.Children.Add(fg);

            var of = CreateLine(wo, wf);
            canvas.Children.Add(of);



        

        public Line CreateLine(Point pt1,Point pt2)
        
            Line l = new Line();
            l.Stroke = Brushes.Red;
            l.StrokeThickness = 1;
            l.X1 = pt1.X;
            l.X2 = pt2.X;
            l.Y1 = pt1.Y;
            l.Y2 = pt2.Y;

            return l;
        
//空间坐标系转直角坐标系
        public Point Convert2d(Point3d p3d)
        
            Point p = default;

            int x = p3d.y;
            int y = p3d.z;


            p.X = x - p3d.x * xishu;
            p.Y = y - p3d.x * xishu;


            return p;
        
   //直角坐标系转wpf客户端坐标
        public Point ConvertCPoint(Point orign,Point pt)
        
            Point wPt = default;
            wPt.X = pt.X + orign.X;
            wPt.Y = orign.Y - pt.Y;
            return wPt;
        
    

   public struct Point3d
    
       public int x;
        public int y;
        public int z;
      public  Point3d(int x,int y,int z)
        
            this.x = x;
            this.y = y;
            this.z = z;
        
    

以高中数学里的空间坐标系为基础,做的。做出来,看着还行,感觉画的挺标准的。

以上是关于wpf 空间坐标系下,画一个立方体轮廓的主要内容,如果未能解决你的问题,请参考以下文章

怎样用WPF绘制简单的三维曲线?

WPF中画虚线

C语言编程实现根据坐标批量绘制长方体的三维图,最好可以用鼠标移动和旋转

如何在OpenGL中的对象空间坐标中获得近剪裁平面坐标

Python直角坐标系画图

WPF 画一个3D矩形并旋转