球面碰撞解决 [英] Sphere-plane collision resolve
问题描述
我想编写一个c ++程序,该程序将计算球体和平面之间的碰撞.
I want to write a c++ program that will calculate collision between sphere and plane.
规则是下落物体的角度等于反射角度.
The rule is that the angle of the falling object equals to angle of reflection.
我对球有什么看法
//sphere coordinates and radius
float x;
float y;
float z;
float r;
//sphere velocity vector projections
float vx;
float vy;
float vz;
平面由平面方程系数来描述:
Plane is described by plane equation coefficients:
float A;
float B;
float C;
float D;
通过球体平面碰撞检测,我没有问题.但是碰撞后如何求速度呢?
With sphere-plane collision detection I have no problem. But how to find velocity after collision?
我发现了什么
因此,最终我需要计算 vx vy vz
的更新值.
So, ultimately I need to calculate updated values for vx vy vz
.
推荐答案
定义平面的方程为
Ax + By + Cz + D = 0
所以垂直于平面的向量是
So the vector normal to the plane is
W = (A, B, C)
归一化:
n = W/|W|
现在获取速度矢量:
V = (vx, vy, vz)
其垂直于飞机的分量是
Vn = (V . n) n
其余部分,与平面平行的部分是
and the rest of it, the part parallel to the plane is
Vp = V - Vn
我们要反转普通分量,并保持并行分量不变:
We want to reverse the normal component and leave the parallel component unchanged:
V' = -Vn + Vp
可以解决
V' = V - 2(V . n)n
这篇关于球面碰撞解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!