0
간단한 광선 추적 알고리즘을 구현해야하지만 구형의 반지름과 반지름이있는 경우 구의 법선 벡터를 얻을 수있는 방법을 알아낼 수 없습니다. 감사 Wiki aboute sphere하지만 난 내가 해결책을 찾을 수있는이구의 법선 벡터는 어떻게 얻을 수 있습니까?
간단한 광선 추적 알고리즘을 구현해야하지만 구형의 반지름과 반지름이있는 경우 구의 법선 벡터를 얻을 수있는 방법을 알아낼 수 없습니다. 감사 Wiki aboute sphere하지만 난 내가 해결책을 찾을 수있는이구의 법선 벡터는 어떻게 얻을 수 있습니까?
에서 그것을 알아낼 수 없습니다 :
Double alpha = Math.Asin(sphere.Radius/(Math.Sqrt(Math.Pow(sphere.Origin.X-ray.Origin.X,2)+Math.Pow(sphere.Origin.Y-ray.Origin.Y,2)+Math.Pow(sphere.Origin.Z-ray.Origin.Z,2))));
Double beta = Math.Acos((ray.Direction * (sphere.Origin - ray.Origin))/(ray.Direction.Length * (sphere.Origin - ray.Origin).Length));
ray.HitParam = VypA(sphere.Origin - ray.Origin, beta, sphere.Radius)/ray.Direction.Length;
Vector4 g = ray.Origin + ray.Direction * ray.HitParam;
ray.HitNormal = (g - sphere.Origin).Normalized;
////the VypA function
public static Double VypA(Vector4 b, Double beta, Double radius)
{
return b.Length * (Math.Cos(beta) - Math.Sqrt(((radius * radius)/(b.Length2) - (Math.Sin(beta) * (Math.Sin(beta))))));
}
: 여기에 C#에서 코드입니다