Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 随机生成正交3x3矩阵_C#_Matrix_Orthogonal_Siemens Nx - Fatal编程技术网

C# 随机生成正交3x3矩阵

C# 随机生成正交3x3矩阵,c#,matrix,orthogonal,siemens-nx,C#,Matrix,Orthogonal,Siemens Nx,我想在Seimens NX中做一些复杂的零件分析。我希望实现测量模型的双卡尺方法,以便找到它可能适合的最小盒子(用于加工目的)。我已经准备好了所有的测量代码,但是我完全被一个可以随机输出标准化的3x3向量作为坐标系的结构的想法所迷惑。零件是相对于该坐标系测量的,因此每个坐标系都给出了唯一的“最小零件包络”。分析后,将选择并显示最小的封套 this is the type of vector I am talking about: 1 0 0 0 1 0 0 0 1 numbers can be

我想在Seimens NX中做一些复杂的零件分析。我希望实现测量模型的双卡尺方法,以便找到它可能适合的最小盒子(用于加工目的)。我已经准备好了所有的测量代码,但是我完全被一个可以随机输出标准化的3x3向量作为坐标系的结构的想法所迷惑。零件是相对于该坐标系测量的,因此每个坐标系都给出了唯一的“最小零件包络”。分析后,将选择并显示最小的封套

this is the type of vector I am talking about:
1 0 0
0 1 0
0 0 1

numbers can be any value between -1 and 1, with decimals not only being accepted but pretty much required.

不,这不是我的家庭作业。更多的是我在工作的空闲时间里的个人追求。

如果你对一个已经正交的矩阵应用一个旋转矩阵,那么结果也应该是正交的

因此,您可以将问题重新定义为将随机旋转矩阵应用于单位矩阵


< P>也许为每个轴(x,y,z)做一个随机旋转矩阵,然后以随机的顺序应用矩阵本身(

)如果你不介意只考虑一个特殊的正交矩阵子集,那么有一个更简单的方法来实现这一点,即利用它来生成。(其行列式等于1的附加约束)

这样,您只需要生成一个随机的3x1单位向量(作为旋转轴)并指定旋转角度。此公式将它们转换为有效的旋转矩阵

MATLAB示例:

function R = rot(w, theta)
  bw = [0, -w(3), w(2); w(3), 0, -w(1); -w(2), w(1), 0];
  R = eye(3) + sin(theta)*bw + (1-cos(theta))*bw*bw;
end

w = rand(3,1)
w = w/norm(w)
R = rot(w, 3.14)
C++示例:

// w: the unit vector indicating the rotation axis
// theta: the rotation angle in radian
Eigen::Matrix3d MatrixExp3 (Eigen::Vector3d w, float theta){
  Eigen::Matrix3d bw, R;
  bw << 0, -w(2), w(1), w(2), 0, -w(0), -w(1), w(0), 0;
  R << Eigen::Matrix3d::Identity() + std::sin(theta)*bw + (1-std::cos(theta))*bw*bw;
  return R;
}

int main() {
  std::srand((unsigned int) time(0));
  Eigen::Vector3d w = Eigen::Vector3d::Random();
  Eigen::Matrix3d R = MatrixExp3(w.normalized(), 3.14f);
  std::cout << R << std::endl;
}
//w:表示旋转轴的单位向量
//θ:以弧度表示的旋转角度
特征::矩阵x3d矩阵xP3(特征::向量3d w,浮点θ){
本征::矩阵x3d bw,R;

bw这实际上可能是朝着正确方向迈出的一步。我确实可以访问零件本身的绝对坐标系,因此变换是完全可以接受的。见鬼,我相信已经有方法可以实现这一点。我花了很多时间讨论如何实现这一点,但忽略了最明显的答案。谢谢!