随机生成正交 3x3 矩阵

发布于 2024-12-25 03:37:19 字数 422 浏览 7 评论 0原文

我希望在 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.

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

I'm looking to do some complex part analysis within Seimens NX. I'm looking to implement the double caliper method of measuring a model in order to find the minimum possible box that it could possibly fit into(for machining purposes). I've got all of my measurement code in place, but I am completely baffled by the idea of a construct that can randomly output normalized 3x3 vectors for use as coordinate systems. The part is measured with respect to this coordinate system, so each coordinate system gives a unique "minimum part envelope". Once analyzed, the smallest envelope is selected and displayed.

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.

and no, this isn't my homework. More of an individual pursuit in my free time at work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两个我 2025-01-01 03:37:19

如果将旋转矩阵应用于已经正交的矩阵,那么结果也应该是正交的。

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

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

If you apply a rotation matrix to an already orthogonal matrix, then the result should also be orthogonal.

So you can redefine your problem as applying a random rotation matrix to the identity matrix.

Perhaps do one random rotation matrix for each axis (x,y,z) and then apply the matrices themselves in a random order?

度的依靠╰つ 2025-01-01 03:37:19

如果您不介意仅考虑正交矩阵的特殊子集,则有一种更简单的方法可以实现此目的,即利用 Rodrigues 旋转公式 生成 旋转矩阵(它有一个附加约束,即行列式等于 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;
}

If you don't mind to consider only a special subset of the orthogonal matrices, there is an easier way to achieve this, which is to take advantage of the Rodrigues' rotation formula to generate rotation matrices (which has an additional constraint that its determinant is equal to 1).

Image of the Rodrigues' rotation formula

Image of the bracket notation

With this, you only need to generate a random 3x1 unit vector (as the rotation axis) and specify a rotation angle. This formula will transform them into a valid rotation matrix.

MATLAB example:

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++ example:

// 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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文