Cg乘法运算符

Cg语言中,对两个向量进行 "*"的乘法运算时,既不是点积(内积),也不是叉积(外积),只是两向量各分量分别相乘而已。

以下内容只是引述出处,太长可以不看。

 参考网页  <https://en.wikibooks.org/wiki/Cg_Programming/Vector_and_Matrix_Operations>

 

float3 a =float3(1.0, 2.0, 3.0);

float3 b =float3(0.1, 0.2, 0.3);

float3 c = a + b; //= float3(1.1, 2.2, 3.3)

float3 d = a * b; //= float3(0.1, 0.4, 0.9)

 

Note in particularthat a * b represents a component-wise product of two vectors, which is not often seen in linear algebra. For matrices, these operators also workcomponent-wise. Again, a component-wise product of two matrices is not often seen in linear algebra.

特别注意,a * b表示两个向量的各分量的乘积,这在线性代数中并不常见。对于矩阵,这些运算符也是分别作用于各分量的。同样,两个矩阵的各分量的乘积,在线性代数中也是不常见到。

 

For the usualmatrix-vector product or matrix-matrix product, see the built-in mul functionbelow. For the dot product and cross product between vectors, see the built-infunctions dot and cross below.

对于通常的矩阵向量乘积或矩阵-矩阵乘积,请参见下面的内置mul函数。对于向量的点积和向量积,可以看到内建的函数点和下面的点。

 

The *-operator canalso be used to multiply a floating-point value (i.e. a scalar) to allcomponents of a vector or matrix (from left or right):

运算符也可用于将浮点值(即标量)乘于向量或矩阵的所有分量(从左或右):

 

float3 a =float3(1.0, 2.0, 3.0);

float2x2 m =float2x2(1.0, 0.0, 0.0, 1.0);

float s = 10.0;

float3 b = s * a; //float3(10.0, 20.0, 30.0)

float3 c = a * s; //float3(10.0, 20.0, 30.0)

float2x2 m2 = s * m;// = float2x2(10.0, 0.0, 0.0, 10.0)

float2x2 m3 = m * s;// = float2x2(10.0, 0.0, 0.0, 10.0)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值