layout: post
title: VMD的向量与矩阵操作
categories:
Tcl对数学表达式的处理不够好, 计算表达式的速度很慢, 并且没有提供处理向量或矩阵的便利工具. 由于进行结构分析时经常涉及向量或矩阵, 因此我们添加了一些操作它们的函数.
VMD中的向量是一些数字的列表. 所有的向量函数都可以处理任意长度的向量, 但veccross
除外, 它只能用于含3个数字的向量. VMD中的矩阵是一个4x4的数字集合, 存储形式为4个向量的列表, 每个向量包含4个数字, 存储时行优先.
以下是所有命令的说明和示例. 用于测试向量实现的脚本$env(VMDDIR)/scripts/vmd/test-vectors.tcl
中包含了更多的示例, 但相关文档并不多.
由于Tcl的数学运算很慢, 其中的一些命令已经用C++重新实现了(命令的原始定义见VMD脚本的发行版, 但稍后在VMD内部进行了重新定义). 有时, 加速比可以达到40或更多. 这样的命令用(C++)标识出来.
向量
veczero
: 零向量, {0 0 0}
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span><span style="color: #666666">></span>veczero
<span style="color: #B8860B">0</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span></pre></div>vecadd v1 v2 [v3 ... vn]
: 所有向量的向量和 (C++)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecadd <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">4</span> <span style="color: #666666">5</span> <span style="color: #666666">6</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">7</span> <span style="color: #666666">8</span> <span style="color: #666666">9</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-11</span> <span style="color: #666666">-11</span> <span style="color: #666666">-11</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">1</span> <span style="color: #666666">4</span> <span style="color: #666666">7</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecadd <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.1</span> <span style="color: #666666">0.2</span> <span style="color: #666666">0.4</span> <span style="color: #666666">0.8</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3</span> <span style="color: #666666">1</span> <span style="color: #666666">4</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">4.1</span> <span style="color: #666666">2.2</span> <span style="color: #666666">6.4</span> <span style="color: #666666">4.8</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecadd <span style="color: #666666">4</span> <span style="color: #666666">5</span>
<span style="color: #B8860B">9</span></pre></div>vecmul v1 v2
: 两个向量的分量逐项相乘后得到的向量
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecmul <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">4</span> <span style="color: #666666">5</span> <span style="color: #666666">6</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">4</span> <span style="color: #666666">10</span> <span style="color: #666666">18</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecmul <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.1</span> <span style="color: #666666">0.2</span> <span style="color: #666666">0.4</span> <span style="color: #666666">0.8</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">0.1</span> <span style="color: #666666">0.2</span> <span style="color: #666666">0.8</span> <span style="color: #666666">2.4</span></pre></div>vecsub v1 v2
: 第一个向量减去第二个向量的差向量 (C++)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecsub <span style="color: #666666">6</span> <span style="color: #666666">3.2</span>
<span style="color: #B8860B">2.8</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecsub <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">10</span> <span style="color: #666666">9.8</span> <span style="color: #666666">7</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.1</span> <span style="color: #666666">0</span> <span style="color: #666666">-0.1</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">9.9</span> <span style="color: #666666">9.8</span> <span style="color: #666666">7.1</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecsub <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span> <span style="color: #666666">4</span> <span style="color: #666666">5</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">6</span> <span style="color: #666666">7</span> <span style="color: #666666">8</span> <span style="color: #666666">9</span> <span style="color: #666666">10</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">-5</span> <span style="color: #666666">-5</span> <span style="color: #666666">-5</span> <span style="color: #666666">-5</span> <span style="color: #666666">-5</span></pre></div>vecsum v
: 向量v
中所有元素的和 (C++)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecsum <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span> <span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">6.0</span></pre></div>vecmean v
: 向量v
中所有元素的平均值 (C++)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecmean <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span> <span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">2.0</span></pre></div>vecstddev v
: 向量v
中所有元素的标准偏差 (C++)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecstddev <span style="color: #AA22FF; font-weight: bold">{</span> <span style="color: #B8860B">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span> <span style="color: #666666">4</span> <span style="color: #666666">5</span> <span style="color: #666666">6</span> <span style="color: #666666">7</span> <span style="color: #666666">8</span> <span style="color: #666666">9</span> <span style="color: #666666">10</span> <span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">2.87228131294</span></pre></div>vecscale c v
或 vecscale v c
: 向量v
中的每个元素与标量c
相乘后得到的向量 (C++)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecscale .2 <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">0.2</span> <span style="color: #666666">0.4</span> <span style="color: #666666">0.6</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecscale <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-5</span> <span style="color: #666666">4</span> <span style="color: #666666">-3</span> <span style="color: #666666">2</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #666666">-2</span>
<span style="color: #B8860B">10</span> <span style="color: #666666">-8</span> <span style="color: #666666">6</span> <span style="color: #666666">-4</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecscale <span style="color: #666666">-2</span> <span style="color: #666666">3</span>
<span style="color: #B8860B">-6</span></pre></div>vecdot v1 v2
: 两个向量的标量点积
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecdot <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">-2</span> <span style="color: #666666">3</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">4</span> <span style="color: #666666">5</span> <span style="color: #666666">6</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">12</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecdot <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3</span> <span style="color: #666666">4</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3</span> <span style="color: #666666">4</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">25</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecdot <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span> <span style="color: #666666">4</span> <span style="color: #666666">5</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">5</span> <span style="color: #666666">4</span> <span style="color: #666666">3</span> <span style="color: #666666">2</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">35</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecdot <span style="color: #666666">3</span> <span style="color: #666666">-2</span>
<span style="color: #B8860B">-6</span></pre></div>veccross v1 v2
: 两个向量的向量叉积
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> veccross <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">1</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">0</span> <span style="color: #666666">0</span> <span style="color: #666666">1</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> veccross <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">2</span> <span style="color: #666666">2</span> <span style="color: #666666">2</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-1</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">0</span> <span style="color: #666666">-2</span> <span style="color: #666666">2</span></pre></div>veclength v
: 向量v
的标量长度($\Vert v \Vert$)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span><span style="color: #666666">></span> veclength <span style="color: #666666">5</span>
<span style="color: #B8860B">5.0</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> veclength <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">5</span> <span style="color: #666666">12</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">13.0</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> veclength <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3</span> <span style="color: #666666">4</span> <span style="color: #666666">12</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">13.0</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> veclength <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">-2</span> <span style="color: #666666">3</span> <span style="color: #666666">-4</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">5.47723</span></pre></div>veclength2 v
: 向量标量长度的平方($\Vert v \Vert^2$)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> veclength2 <span style="color: #666666">5</span>
<span style="color: #B8860B">25</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> veclength2 <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">5</span> <span style="color: #666666">12</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">169</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> veclength2 <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3</span> <span style="color: #666666">4</span> <span style="color: #666666">12</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">169</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> veclength2 <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">-2</span> <span style="color: #666666">3</span> <span style="color: #666666">-4</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">30</span></pre></div>vecnorm v
: 沿向量v
方向的单位向量
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecnorm <span style="color: #666666">-10</span>
<span style="color: #B8860B">-1.0</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecnorm <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">1</span> <span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">0.707109</span> <span style="color: #666666">0.707109</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecnorm <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">2</span> <span style="color: #666666">-3</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">0.534522</span> <span style="color: #666666">-0.801783</span> <span style="color: #666666">0.267261</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecnorm <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">2</span> <span style="color: #666666">2</span> <span style="color: #666666">-2</span> <span style="color: #666666">2</span> <span style="color: #666666">-2</span> <span style="color: #666666">-2</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">0.408248</span> <span style="color: #666666">0.408248</span> <span style="color: #666666">-0.408248</span> <span style="color: #666666">0.408248</span> <span style="color: #666666">-0.408248</span> <span style="color: #666666">-0.408248</span></pre></div>vecdist v1 v2
: 两个向量之间的距离($\Vert v_2-v_1\Vert$)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecdist <span style="color: #666666">-1.5</span> <span style="color: #666666">5.5</span>
<span style="color: #B8860B">7.0</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecdist <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3</span> <span style="color: #666666">4</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">5.0</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecdist <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span> <span style="color: #666666">4</span> <span style="color: #666666">5</span> <span style="color: #666666">6</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-6</span> <span style="color: #666666">-5</span> <span style="color: #666666">-4</span> <span style="color: #666666">-3</span> <span style="color: #666666">-2</span> <span style="color: #666666">-1</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">15.8745</span></pre></div>vecinvert v
: 向量v
的逆向量($-v$)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecinvert <span style="color: #666666">-11.1</span>
<span style="color: #B8860B">11.1</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecinvert <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3</span> <span style="color: #666666">-4</span> <span style="color: #666666">5</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">-3</span> <span style="color: #666666">4</span> <span style="color: #666666">-5</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vecinvert <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">-1</span> <span style="color: #666666">2</span> <span style="color: #666666">-3</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">0</span> <span style="color: #666666">1</span> <span style="color: #666666">-2</span> <span style="color: #666666">3</span></pre></div>矩阵
由于以文本形式显示矩阵时相当大, 因此在示例中会使用以下定义.
transidentity
: 单位矩阵
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transidentity
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span></pre></div>transtranspose m
: 给定矩阵的转置
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transtranspose <span style="color: #AA22FF; font-weight: bold">{ {</span><span style="color: #B8860B">0</span> <span style="color: #666666">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span> <span style="color: #666666">4</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">5</span> <span style="color: #666666">6</span> <span style="color: #666666">7</span> <span style="color: #666666">8</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">9</span> <span style="color: #666666">10</span> <span style="color: #666666">11</span> <span style="color: #666666">12</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">13</span> <span style="color: #666666">14</span> <span style="color: #666666">15</span> <span style="color: #666666">16</span><span style="color: #AA22FF; font-weight: bold">} }</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">5</span> <span style="color: #666666">9</span> <span style="color: #666666">13</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">6</span> <span style="color: #666666">10</span> <span style="color: #666666">14</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">2</span> <span style="color: #666666">7</span> <span style="color: #666666">11</span> <span style="color: #666666">15</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3</span> <span style="color: #666666">8</span> <span style="color: #666666">12</span> <span style="color: #666666">16</span><span style="color: #AA22FF; font-weight: bold">}</span></pre></div>transmult m1 m2 [m3 ... mn]
: 给定矩阵的乘积 (C++)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set mat1 <span style="color: #AA22FF; font-weight: bold">{ {</span><span style="color: #B8860B">1</span> <span style="color: #666666">2</span> <span style="color: #666666">3</span> <span style="color: #666666">4</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-2</span> <span style="color: #666666">3</span> <span style="color: #666666">-4</span> <span style="color: #666666">5</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3</span> <span style="color: #666666">-4</span> <span style="color: #666666">5</span> <span style="color: #666666">-6</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">4</span> <span style="color: #666666">5</span> <span style="color: #666666">-6</span> <span style="color: #666666">-7</span><span style="color: #AA22FF; font-weight: bold">} }</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set mat2 <span style="color: #AA22FF; font-weight: bold">{ {</span><span style="color: #B8860B">1</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">0.7071</span> <span style="color: #666666">-0.7071</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">0.7071</span> <span style="color: #666666">0.7071</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">} }</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set mat3 <span style="color: #AA22FF; font-weight: bold">{ {</span><span style="color: #B8860B">0.866025</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">1</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-0.5</span> <span style="color: #666666">0</span> <span style="color: #666666">0.866025</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">} }</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transmult <span style="color: #B8860B">$mat1</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">transidentity</span><span style="color: #AA22FF; font-weight: bold">]</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1.0</span> <span style="color: #666666">2.0</span> <span style="color: #666666">3.0</span> <span style="color: #666666">4.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-2.0</span> <span style="color: #666666">3.0</span> <span style="color: #666666">-4.0</span> <span style="color: #666666">5.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">3.0</span> <span style="color: #666666">-4.0</span> <span style="color: #666666">5.0</span> <span style="color: #666666">-6.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">4.0</span> <span style="color: #666666">5.0</span> <span style="color: #666666">-6.0</span> <span style="color: #666666">-7.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transmult <span style="color: #B8860B">$mat1</span> <span style="color: #B8860B">$mat2</span> <span style="color: #B8860B">$mat3</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.512475</span> <span style="color: #666666">3.5355</span> <span style="color: #666666">0.612366</span> <span style="color: #666666">4.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.7428</span> <span style="color: #666666">-0.7071</span> <span style="color: #666666">-4.28656</span> <span style="color: #666666">5.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-0.58387</span> <span style="color: #666666">0.7071</span> <span style="color: #666666">5.5113</span> <span style="color: #666666">-6.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">7.35315</span> <span style="color: #666666">-0.7071</span> <span style="color: #666666">-6.73603</span> <span style="color: #666666">-7.0</span><span style="color: #AA22FF; font-weight: bold">}</span></pre></div>transaxis <x|y|z> amount [deg|rad|pi]
: 绕指定轴旋转给定角度所需的变换矩阵.
默认情况下, 角度以度为单位, 但也可以使用rad(弧度)或pi(π).
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transaxis x <span style="color: #666666">90</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">-3.67321</span>e-06 <span style="color: #666666">-1.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">-3.67321</span>e-06 <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transaxis y <span style="color: #666666">0.25</span> pi
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.707107</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.707107</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-0.707107</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.707107</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transaxis z <span style="color: #666666">3.1415927</span> rad
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-1.0</span> <span style="color: #666666">-2.65359</span>e-06 <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">2.65359e-06</span> <span style="color: #666666">-1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span></pre></div>transvec v
: 使x轴沿向量v方向所需的变换矩阵.
构造方式为先沿y轴旋转, 再沿z轴旋转. 这个矩阵并不唯一, 因为最终仍可以沿向量进行任意旋转.
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transvec <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">1</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-3.67321e-06</span> <span style="color: #666666">-1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1.0</span> <span style="color: #666666">-3.67321</span>e-06 <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vectrans <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">transvec</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">0</span> <span style="color: #666666">2</span><span style="color: #AA22FF; font-weight: bold">}]</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span></pre></div>transvecinv v
: 使向量v沿x轴方向所需的变换矩阵.
结果为transvec
的逆矩阵, 构造方式为先沿z轴旋转, 再沿y轴旋转.
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transvecinv <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">-1</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-3.67321e-06</span> <span style="color: #666666">-1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1.0</span> <span style="color: #666666">-3.67321</span>e-06 <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vectrans <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">transvecinv</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-3</span> <span style="color: #666666">4</span> <span style="color: #666666">-12</span><span style="color: #AA22FF; font-weight: bold">}]</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-3</span> <span style="color: #666666">4</span> <span style="color: #666666">-12</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">13.0</span> <span style="color: #666666">-1.8</span>e-05 <span style="color: #666666">5.8</span>e-05
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transmult <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">transvec</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">6</span> <span style="color: #666666">-5</span> <span style="color: #666666">7</span><span style="color: #AA22FF; font-weight: bold">}]</span> <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">transvecinv</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">6</span> <span style="color: #666666">-5</span> <span style="color: #666666">7</span><span style="color: #AA22FF; font-weight: bold">}]</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.999999</span> <span style="color: #666666">2.29254</span>e-07 <span style="color: #666666">-6.262</span>e-09 <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">2.29254e-07</span> <span style="color: #666666">0.999999</span>
<span style="color: #B8860B">-4.52228e-07</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-6.262e-09</span> <span style="color: #666666">-4.52228</span>e-07 <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span></pre></div>transoffset v
: 沿给定偏移量进行平移所需的变换矩阵 (C++)
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transoffset <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transoffset <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-6</span> <span style="color: #666666">5</span> <span style="color: #666666">-4.3</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">-6</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">5</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">-4.3</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span></pre></div>transabout v amount [deg|rad|pi]
: 绕通过原点并沿给定向量方向的轴逆时针旋转给定角度所需的变换矩阵.
与transvec
一样, 旋转角度的单位可以是度, 弧度或π.
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #008800; font-style: italic"># 绕 x 轴 180 度</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transabout <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #666666">180</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">-1.0</span> <span style="color: #666666">-2.65359</span>e-06 <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">2.65359</span>e-06
<span style="color: #B8860B">-1.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #008800; font-style: italic"># 绕 z 轴 90 度 (同"transaxis z 90")</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transabout <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0</span> <span style="color: #666666">0</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #666666">1.5709</span> rad
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.999624</span> <span style="color: #666666">-0.027414</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.027414</span> <span style="color: #666666">0.999624</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> transabout <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">1</span> <span style="color: #666666">1</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #666666">1</span> pi
<span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-0.333335</span> <span style="color: #666666">0.666665</span> <span style="color: #666666">0.666669</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.666668</span> <span style="color: #666666">-0.333334</span> <span style="color: #666666">0.666666</span>
<span style="color: #B8860B">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.666666</span> <span style="color: #666666">0.66667</span> <span style="color: #666666">-0.333332</span> <span style="color: #666666">0.0</span><span style="color: #AA22FF; font-weight: bold">}</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">0.0</span> <span style="color: #666666">1.0</span><span style="color: #AA22FF; font-weight: bold">}</span></pre></div>trans [center {x y z}] [origin {x y z}] [offset {x y z}] [axis x amount [rad|deg|pi]] [axis y amount [rad|deg|pi]] [axis z amount [rad|deg|pi]] [x amount [rad|deg|pi]] [y amount [rad|deg|pi]] [z amount [rad|deg|pi]] [axis {x y z} amount [rad|deg|pi]] [bond {x1 y1 z1} {x2 y2 z2} amount [rad|deg|pi]] [angle {x1 y1 z1} {x2 y2 z2} {x3 y3 z3} amount [rad|deg|pi]]
: 通用命令
此命令几乎可以进行其他命令支持的所有操作, 还支持其他一些操作. 它是用于生成变换矩阵的主要函数.
正确使用它需要了解其内部工作方式. 共有三个矩阵: 居中, 旋转和偏移. 居中矩阵确定旋转中心的位置. 默认为原点, 但也可以更改为任何点. 旋转矩阵定义了绕中心点的旋转, 偏移矩阵定义了旋转后的进行的最终平移.
例如, 要绕一个给定点旋转, 变换应该是: 1) 使用居中矩阵将该点变为原点, 2) 绕中心旋转, 3) 使用偏移矩阵将原点平移回最初位置.
trans
命令的不同选项可以不同的方式改变矩阵.
center {x y z}
: 设定居中矩阵, 将点{x y z}变为原点
offset {x y z}
: 设定偏移矩阵, 将原点变为{x y z}
origin {x y z}
: 居中矩阵和偏移矩阵同时设定为{x y z}
axis x amount [rad|deg|pi]
: 为旋转矩阵增加绕x轴旋转给定角度的旋转
axis y amount [rad|deg|pi]
: 为旋转矩阵增加绕y轴旋转给定角度的旋转
axis z amount [rad|deg|pi]
: 为旋转矩阵增加绕z轴旋转给定角度的旋转
axis {x y z} amount [rad|deg|pi]
: 为旋转矩阵增加绕指定向量旋转给定角度的旋转
bond {x1 y1 z1} {x2 y2 z2} amount [rad|deg|pi]
: 将居中和偏移矩阵设定为第一个点, 然后定义绕键轴旋转给定角度的旋转
angle {x1 y1 z1} {x2 y2 z2} {x3 y3 z3} amount [rad|deg|pi]
: 将居中和偏移矩阵设定为第二个点, 然后定义绕三个点所在平面法向旋转给定角度的旋转(平面法向为连接前两个点的向量和连接后两个点的向量的叉积).
向量与矩阵相乘
有两个命令用来对矩阵和向量进行相乘, vectrans
和coordtrans
. 它们假定向量为列形式, 并将矩阵乘以向量. 如果向量包含4个数字, 这两个命令完全相同. 如果向量只有3个元素, 会添加第4个元素; 对vectrans
会添加0, 对coordtrans
会添加1. 不同之处在于, 在变换过程中, 向量不受平移的影响, 但坐标会受到影响.
vectrans m v
: 将矩阵m与向量v(长度为4)相乘; 返回向量 (C++)
coordtrans m v
: 将矩阵m与坐标v(长度为3)相乘; 返回向量
示例:
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vectrans <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">transaxis</span> z <span style="color: #666666">90</span><span style="color: #AA22FF; font-weight: bold">]</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">1</span> <span style="color: #666666">0</span> <span style="color: #666666">0</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">-3.67321e-06</span> <span style="color: #666666">1.0</span> <span style="color: #666666">0.0</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> vectrans <span style="color: #AA22FF; font-weight: bold">[</span><span style="color: #B8860B">transvecinv</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-3</span> <span style="color: #666666">4</span> <span style="color: #666666">-12</span><span style="color: #AA22FF; font-weight: bold">}]</span> <span style="color: #AA22FF; font-weight: bold">{</span><span style="color: #B8860B">-3</span> <span style="color: #666666">4</span> <span style="color: #666666">-12</span><span style="color: #AA22FF; font-weight: bold">}</span>
<span style="color: #B8860B">13.0</span> <span style="color: #666666">-1.8</span>e-05 <span style="color: #666666">5.8</span>e-05</pre></div>其他函数和值
向量包中还包含其他一些项. 第一个是变量M_PI
, 表示pi的值.
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set M_PI
<span style="color: #B8860B">3.14159265358979323846</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> expr <span style="color: #666666">90</span> <span style="color: #666666">*</span> <span style="color: #AA22FF; font-weight: bold">(</span><span style="color: #B8860B">$M_PI</span> <span style="color: #666666">/</span> <span style="color: #B8860B">180</span><span style="color: #AA22FF; font-weight: bold">)</span>
<span style="color: #B8860B">1.5708</span></pre></div>函数trans_from_rot
, trans_to_rot
, trans_from_offset
和trans_to_offset
用于从3x3旋转矩阵或偏移矢量获取或设置变换矩阵. 按照目前的设计, 这些函数假设矩阵没有缩放. trans_from_offset
与transoffset
完全相同, 包含二者只是出于完整性的考虑.
最后一个函数是find_rotation_value varname
, 它接受一个变量名称, 并从其开头提取说明描述旋转的项. 变量中的其余数据会保留下来, 然后返回以弧度为单位的旋转角度.
那些需要旋转的函数使用这个函数. 有效值为: 一个数字, 后面跟着rad
, radian
或radians
表示以弧度为单位的值, pi
表示以pi为单位, deg
, degree
或degrees
表示以度为单位. 如果未指定单位, 则假定以度为单位.
示例:
<div class="highlight"><pre style="line-height:125%"><span></span><span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set a <span style="color: #BB4444">"180 deg north"</span>
<span style="color: #B8860B">180</span> deg north
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> find_rotation_value a
<span style="color: #B8860B">3.14159</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set a
<span style="color: #B8860B">north</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set a <span style="color: #BB4444">"1 pi to eat"</span>
<span style="color: #B8860B">1</span> pi to eat
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> find_rotation_value a
<span style="color: #B8860B">3.14159</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set a
<span style="color: #B8860B">to</span> eat
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set a <span style="color: #666666">45</span>
<span style="color: #B8860B">45</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> find_rotation_value a
<span style="color: #B8860B">0.785398</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> expr <span style="color: #B8860B">$M_PI</span> <span style="color: #666666">*</span> <span style="color: #666666">3.0</span> <span style="color: #666666">/</span> <span style="color: #666666">2.0</span>
<span style="color: #B8860B">4.71239</span>
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> set a <span style="color: #BB4444">"4.71238 radians"</span>
<span style="color: #B8860B">4.71238</span> radians
<span style="color: #B8860B">vmd</span> <span style="color: #666666">></span> find_rotation_value a
<span style="color: #B8860B">4.71238</span></pre></div>