duheng
2025-02-19 ad8f813f5eddd66740b4e09801e4ea02ddf70a4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Yw.WinFrmUI.Q3d
{
    [Serializable]
    public class PointF3D
    {
        public float X { get; set; }
        public float Y { get; set; }
        public float Z { get; set; }
 
        public PointF3D(float x, float y, float z)
        {
            X = x;
            Y = y;
            Z = z;
        }
        //定义减法运算符
        public static PointF3D operator -(PointF3D p1, PointF3D p2)
        {
            return new PointF3D(p1.X - p2.X, p1.Y - p2.Y, p1.Z - p2.Z);
        }
        //定义加法运算符
        public static PointF3D operator +(PointF3D p1, PointF3D p2)
        {
            return new PointF3D(p1.X + p2.X, p1.Y + p2.Y, p1.Z + p2.Z);
        }
        //定义乘法运算符
        public static PointF3D operator *(PointF3D p1, float f)
        {
            return new PointF3D(p1.X * f, p1.Y * f, p1.Z * f);
        }
        //定义点乘运算符
        public static float operator *(PointF3D p1, PointF3D p2)
        {
            return p1.X * p2.X + p1.Y * p2.Y + p1.Z * p2.Z;
        }
        //定义叉乘运算符
        public static PointF3D operator ^(PointF3D p1, PointF3D p2)
        {
            return new PointF3D(p1.Y * p2.Z - p1.Z * p2.Y, p1.Z * p2.X - p1.X * p2.Z, p1.X * p2.Y - p1.Y * p2.X);
        }
    }
 
    public class Cube
    {
        public Dictionary<int, List<PointF3D>> FacesVertices { get; private set; }
        public List<PointF3D> Vertices { get; private set; }
 
        public Cube()
        {
            InitializeVertices();
            InitializeFaces();
        }
 
        private void InitializeVertices()
        {
            Vertices = new List<PointF3D>
        {
            new PointF3D(200, 200, 200), // Vertex 0
            new PointF3D(200, 200, -200), // Vertex 1
            new PointF3D(200, -200, 200), // Vertex 2
            new PointF3D(200, -200, -200), // Vertex 3
            new PointF3D(-200, 200, 200), // Vertex 4
            new PointF3D(-200, 200, -200), // Vertex 5
            new PointF3D(-200, -200, 200), // Vertex 6
            new PointF3D(-200, -200, -200) // Vertex 7
        };
        }
 
        private void InitializeFaces()
        {
            FacesVertices = new Dictionary<int, List<PointF3D>>
        {
            { 1, new List<PointF3D> { Vertices[0], Vertices[1], Vertices[3], Vertices[2] } }, // Face 1
            { 2, new List<PointF3D> { Vertices[4], Vertices[5], Vertices[7], Vertices[6] } }, // Face 2
            { 3, new List<PointF3D> { Vertices[0], Vertices[1], Vertices[5], Vertices[4] } }, // Face 3
            { 4, new List<PointF3D> { Vertices[2], Vertices[3], Vertices[7], Vertices[6] } }, // Face 4
            { 5, new List<PointF3D> { Vertices[0], Vertices[2], Vertices[6], Vertices[4] } }, // Face 5
            { 6, new List<PointF3D> { Vertices[1], Vertices[3], Vertices[7], Vertices[5] } }  // Face 6
        };
        }
    }
}