surface normal to a cone

2019-04-13 07:41发布

问题:

Im writing a program in OpenGL/C++ to ray trace a cone.For my intensity calculations I need to know the surface normal.Given a base radius,height and centre coordinates,how do I calculate the surface normal?

回答1:

I am supposing that you need to find the normal to the surface given a point on the surface. I am further assuming that this is a cone oriented such that the base is facing down (-y axis) and the point of the cone points up (+y axis). If any of these conditions are not the case, I can edit my answer to fit your situation.

Let us call your point on the surface P, the center coordinates C, the radius r, the height h, and the normal N.

All points and vectors have three components (x, y, z), so I will refer to these by using a ".". For example P.x is the x component of P.

First, we need a unit vector projected on to the x/z plane which points from C to P.

V.x=P.x-C.x

V.y=0

V.z=P.z-C.z

This vector has the correct direction, but the magnitude is greater than one. It is not a unit vector yet, so we must scale it accordingly.

m=sqrt(V.x2+V.z2)

m is now the magnitude of V, which we will use to scale V...

V.x/=m

V.z/=m

The final calculations to find the normal are...

N.x=V.x*h/r

N.y=r/h

N.z=V.z*h/r



回答2:

If you have your Cone faced down and an opening angel (α), base at h on (+z). You can chose your co-system on the top of con. Which means that the cone is balanced on the pointy part.

In this case you can derive a general expression for the normal komponent to this surface.

Step 1:

Express the normal i spherical coordinates(e_r,e_θ,e_φ), there all components are unit vectors and θ is defined as azimuthal angel.

result --> e_θ(θ==α,φ)

if you work with som other property of this shape such as magnetization M or electric flux. One can easily trasform this i cylindrical coordinates.

Step 2:

e_θ==-sin(θ) e_z +cos(θ) e_s(φ) there θ==α.



标签: graphics