我有一个向量落在平面上。我知道她正好落在飞机上,我知道坠落的地点。我需要找到一个反射向量。
该平面由3个点表示。
我在做什么错了?
public static Vector3 GetReflectedVector(Vector3 direction,Vector3 vert0, Vector3 vert1, Vector3 vert2)
{
Vector3 normalizeDirection = Normalize(direction);
Vector3 planeNormal = Normalize(Cross(vert1 - vert0, vert0 - vert2));
double dot = Dot(normalizeDirection, planeNormal);
double mod = VectorModule(planeNormal);
double pr = dot / mod;
Vector3 projection = planeNormal * (float)pr * 2f;
return direction - projection;
}
这种逻辑(应该是):
答案 0 :(得分:0)
这是答案:
public static Vector3 GetReflectedVector(Vector3 direction,Vector3 vert0, Vector3 vert1, Vector3 vert2)
{
Vector3 normalizeDirection = Normalize(direction);
Vector3 planeNormal = Normalize(Cross(vert1 - vert0, vert0 - vert2));
return CombineVector(normalizeDirection, planeNormal, 1, (float)(-2 * Dot(normalizeDirection, planeNormal)));
}
private static Vector3 CombineVector(Vector3 v1, Vector3 v2, float f1, float f2)
{
Vector3 vector3;
vector3.X = (f1 * v1.X) + (f2 * v2.X);
vector3.Y = (f1 * v1.Y) + (f2 * v2.Y);
vector3.Z = (f1 * v1.Z) + (f2 * v2.Z);
return vector3;
}