矩阵变换可以实现位移与旋转,四元数的经典使用,向量可以写成矩阵的形式,左乘后相当于将当前向量进行位移缩放旋转。
第一列代表对应x轴(1,0,0)当然实际结果肯定不是只是相当于。
第二列代表对应Y轴(0,1,0)
第三列代表对应Z轴(0,0,1)
double[] normalizedX = new double[3];
double[] normalizedY = new double[3];
double[] normalizedZ = new double[3];
myMath.Subtract(endPoint, startPoint, ref normalizedX);
double length = myMath.Norm(normalizedX);
myMath.Normalize(ref normalizedX);
double[] arbitrary = new double[] {
vtkMath.Random(-10,10),
vtkMath.Random(-10,10),
vtkMath.Random(-10,10)
};
myMath.Cross(normalizedX, arbitrary, ref normalizedZ);
myMath.Normalize(ref normalizedZ);
myMath.Cross(normalizedZ, normalizedX, ref normalizedY);
vtkMatrix4x4 matrix = vtkMatrix4x4.New();
matrix.Identity();
for(int i=0;i<3;i++)
{
matrix.SetElement(i, 0, normalizedX[i]);
matrix.SetElement(i, 1, normalizedY[i]);
matrix.SetElement(i, 2, normalizedZ[i]);
}
vtkTransform transform = vtkTransform.New();
transform.Translate(startPoint[0], startPoint[1], startPoint[2]);
transform.Concatenate(matrix);
transform.Scale(length, length, length);
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
vtkActor actor = vtkActor.New();
mapper.SetInputConnection(arrowSource.GetOutputPort());
actor.SetUserMatrix(transform.GetMatrix());
actor.SetMapper(mapper);