具体的代码还是线性代数。
主要是旋转和平移。
这个例子的中模型是在世界原点建立。所以旋转会以自身轴心旋转。
如果不在世界原点建立模型,还想以自身为旋转轴旋转。
则是需要以下步骤:
模型的中心点为V1(100,100,0)假设中心为轴(平行于Y轴),旋转A度,也就是说自身中心点的Y轴旋转。
步骤:
(1)v1平移到世界原点后其他八个顶点的坐标。(中心点坐标的三个参数如果是大于0就是(每个)顶点减去相对应XYZ,如果中心点坐标的三个参数如果是小于0,则是(每个)顶点加上相对应XYZ,或者使用平移矩阵)
(2)(每个)顶点先是平移到V1在原点时的所在的位置,再使用旋转矩阵经行旋转
(3) (每个)旋转后的顶点在平移回中心点原先所在位置。
ATP 附加属性类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Shapes;
namespace ATP
{
public class ATP_Y
{
public static readonly DependencyProperty P_YProperty = DependencyProperty.RegisterAttached("P_Y", typeof(double), typeof(ATP.ATP_Y), new PropertyMetadata(0.0, new PropertyChangedCallback(OnP_YChanged)));
private static void OnP_YChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
PY = (double)e.NewValue;
Draw(d, X, Y, Z);
}
public static void SetP_Y(DependencyObject d, double v) => d.SetValue(P_YProperty, v);
public static double GetP_Y(DependencyObject d) => (double)d.GetValue(P_YProperty);
public static readonly DependencyProperty P_XProperty = DependencyProperty.RegisterAttached("P_X", typeof(double), typeof(ATP.ATP_Y), new PropertyMetadata(0.0, new PropertyChangedCallback(OnP_XChanged)));
private static void OnP_XChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
PX= (double)e.NewValue;
Draw(d, X, Y, Z);
}
public static void SetP_X(DependencyObject d, double v) => d.SetValue(P_XProperty, v);
public static double GetP_X(DependencyObject d) => (double)d.GetValue(P_XProperty);
public static readonly DependencyProperty P_ZProperty = DependencyProperty.RegisterAttached("P_Z", typeof(double), typeof(ATP.ATP_Y), new PropertyMetadata(0.0, new PropertyChangedCallback(OnP_ZChanged)));
private static void OnP_ZChanged(DependencyObject d, DependencyPropertyChan