首页 > 其他分享 >wpf 空间坐标系下,画一个立方体轮廓

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

时间:2023-01-23 09:55:26浏览次数:45  
标签:canvas 100 var Add CreateLine 立方体 wpf Point3d 坐标系

代码:

  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;
        }
    }

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

标签:canvas,100,var,Add,CreateLine,立方体,wpf,Point3d,坐标系
From: https://www.cnblogs.com/HelloQLQ/p/17065012.html

相关文章

  • PPT 当中的立方体如何增加宽度
    拖住右端点比如说我拖到这一点了,我觉得可以了然后再拖这个黄点,就可以调整侧面的形状了yes!......
  • 【转】WPF 菜单Menu的自定义样式
    菜单Menu的自定义样式:页面代码:<MenuHeight="50"Name="menu1"Width="50"VerticalAlignment="Center"HorizontalAlignment="Center"Foreground="{x:Null}"Backgrou......
  • Linux中使用原生Wpf之Avalonia
    快速开始新建avalonia.mvvm项目getting-started#安装Avalonia.TemplatesdotnetnewinstallAvalonia.Templates#查看已经安装的模板dotnetnewlist|grepAvalo......
  • WPF-AutoMapper映射帮助类
    /***┌──────────────────────────────────────────────────────────────┐*│描述:AutoMapper映......
  • WPF通用权限平台系统,正在研发中(基本于:VS2019 WPF+WebAPI(.NET 6.0)+SqlSugar +SQLSer
                  ......
  • dll注入 进程中注入WPF dll
    dll注入进程中注入WPFdll介绍尝试一下向进程中注入WPF应用程序为什么直接注入不可以失败的原因如下.NETDLL(也称为托管DLL)不能注入到尚未加载.NET运行时的远程......
  • 在WPF程序中,使用Freetype显示字体
    本人使用WPF开发了一款OFD阅读器,显示字体是阅读器中最重要的功能。处理字体显示有多种方案,几易其稿,最终选用Freetype方案。本文对WPF中如何使用了Freetype做简单描述。OFD......
  • 84坐标系与02坐标系的转化
    importcom.alibaba.fastjson.JSON;importcom.alibaba.fastjson.JSONArray;importcom.google.common.collect.Lists;importjavax.sound.midi.Soundbank;importja......
  • 界面组件DevExpress WPF v22.2最新版本系统环境配置要求
    DevExpressWPF 拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpressWPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序......
  • WPF StreamGeometry
    使用路径标记语法StreamGeometry来设计最大化最小化恢复和关闭按钮,以下为恢复按钮的路径,和拿邮件系统按钮做了对比,完全吻合前一张图片设置了不透明度为40后一张为邮......