向量投影证明

https://stackoverflow.com/questions/52339320/unity-shader-hlsl-equivalent-of-vector3-projectonplane
a 在 b 上的投影

感觉向量还是这样写好看
在这里插入图片描述
在这里插入图片描述
mathmatica

Dot[{1,0} , {-1,0}]    // 点乘   是一个数
{1,0} x {-1,0}			// 叉乘   是一个向量
// If your plane normal vector is normalized:

inline float3 projectOnPlane( float3 vec, float3 normal )
{
    return vec - normal * dot( vec, normal );
}
// If it's not:

inline float3 projectOnPlane( float3 vec, float3 normal )
{
    return vec - normal * ( dot( vec, normal ) / dot( normal, normal ) );
}
// Same formula, depending on GPU model & driver version can be either faster or slower:

inline float3 projectOnPlane( float3 v, float3 n )
{
    float3 r;
    r.x = n.y * n.y * v.x + n.z * n.z * v.x - n.x * n.y * v.y - n.x * n.z * v.z;
    r.y = n.x * n.x * v.y - n.x * n.y * v.x - n.y * n.z * v.z + n.z * n.z * v.y;
    r.z = n.x * n.x * v.z - n.x * n.z * v.x + n.y * n.y * v.z - n.y * n.z * v.y;
    return r / dot(n, n);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值