这是如何code的工作? [英] How does this code work?

查看:395
本文介绍了这是如何code的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这块C ++ code在一个论坛上,我不能完全理解。因为我没有自己的库进行矩阵/矢量数学,我需要手动看着办吧和复制功能。

I found this piece of C++ code on a forum that I can't fully understand. Since I don't have their library that performs matrix/vector math, I need to manually figure it out and replicate the functionality.

计算Euler旋转2矢量之间的角度。我们用罗德里格公式

    vector $V1 = << my first vector >>;
    vector $V2 = << my second vector >>;


    vector $axis;
    float $angle;

    $angle = acos($V1*$V2);
    $axis = normalizeVector((cross($V1,$V2)));


    matrix $axis_skewed[3][3] = <<
    0, (-$axis.z), ($axis.y) ;
    ($axis.z), 0, (-$axis.x) ;
    (-$axis.y), ($axis.x), 0 >>;

    matrix $eye3[3][3] = <<
    1, 0, 0;
    0, 1, 0;
    0, 0, 1 >>;

从这里开始事情就变得棘手:

From here onwards things get tricky:

    // here's Rodrigues
    $R = $eye3 + sin($angle)*$axis_skewed + (1-cos($angle))*$axis_skewed*$axis_skewed;

你添加eye3矩阵的所有属性?
你乘的axis_skewed矩阵的所有属性?
什么是R'向量或矩阵?或号码?

do you add all the properties of the eye3 matrix?
do you multiply with all the properties of the axis_skewed matrix?
and what is R? a vector or matrix? or number?

这是简单的。

    matrix $vectorMatr[3][1];
    $vectorMatr[0][0] = ($V1.x);
    $vectorMatr[1][0] = ($V1.y);
    $vectorMatr[2][0] = ($V1.z);

再次,这是棘手的:

Again, this is tricky:

    // $result is the resulting vector

    $result = ($R * $vectorMatr);

你与基体使用标准矩阵乘法来获得合成矢量乘以矢量?
你乘两个矩阵的,然后使用矩阵变换了吧?

do you multiply the vector with the matrix to get the resultant vector using standard matrix multiplying?
do you multiply the two matrix's and then transform the point using the matrix?

推荐答案

我是pretty的肯定是伪code。这绝对不是C ++。所有的功能是pretty的自我解释。

I'm pretty sure that's psuedocode. It's definitely not C++. All the functions are pretty self explanatory.

ACOS()---自我解释

acos() --- self explanatory

$ V1 * $ V2 ---积 (注意:,这通常是PTED作为一个普通矩阵乘法跨$ P $,但却在的背景下浮$角= ACOS($ V1 * $ V2);,这不是T意义为以外的任何一个点积)

$V1 * $V2 --- dot product (note:, that would normally be interpreted as a regular matrix multiplication, but but in the context of "float $angle = acos($V1*$V2);", it doesn't make sense as anything other than a dot product)

交叉()---叉积

normalizeVector()---自我解释

normalizeVector() --- self explanatory

罪($角)* $ axis_skewed ---这是一个标量乘

sin($angle)*$axis_skewed --- this is a scalar multiply

怎么做呢?

修改

$ R = $ eye3 +罪($角)* $ axis_skewed +(1-COS($角))* $ axis_skewed * $ axis_skewed;

$R = $eye3 + sin($angle)*$axis_skewed + (1-cos($angle))*$axis_skewed*$axis_skewed;

$ eye3 - 是一个3×3的矩阵

$eye3 -- is a 3x3 matrix

罪($角)* $ axis_skewed ---这是一个标量乘法,从而产生另一个3x3矩阵

sin($angle)*$axis_skewed --- this is a scalar multiply, resulting in another 3x3 matrix

(1-COS($角))* $ axis_skewed ---这是一个标量乘法,从而产生另一个3x3矩阵

(1-cos($angle))*$axis_skewed --- this is a scalar multiply, resulting in another 3x3 matrix

(previous)* $ axis_skewed ---这是一个普通的矩阵乘法,从而导致另一3x3矩阵

(previous)*$axis_skewed --- this is a regular matrix multiplication, resulting in another 3x3 matrix

这给我们留下了:

$ R = [3x3矩阵] + [3x3矩阵] + [3x3矩阵]

$R = [3x3 matrix] + [3x3 matrix] + [3x3 matrix]

这仅仅是常规entrywise矩阵加法。

Which is just regular entrywise matrix addition.

这篇关于这是如何code的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆