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