How to get the normal vector of vertex ???

By using RWStl::ReadFile to read STL file, how to get the normal vector of vertex ???

Sharjith Naramparambath's picture

You cannot get normal vector from vertex alone. The StL file consists of data arranged in the fashion of three vertices and a normal like this...

facet normal 0.1847056E-06 -0.7029399 0.7112494
outer loop
vertex -493.6454 -94.08998 267.8512
vertex -587.0032 -94.09003 267.8512
vertex -493.6454 -95.34873 266.6071
endloop
endfacet

The first line defining the normal is the normal vector of the plane formed by the following three vertices. Think in that direction and try to get the triangle for which you need a normal. If you want averaged normal at any vertex, you will have to first find the normals of all triangles to which the vertex is common and then calculate the average. This will give you the averaged normal at that vertex. This is generally used for smooth shading and lighting calculations. But if you want to do some application like Rapid Prototyping or tool-path generation then the normal vector of your interest should be the one of the triangle's plane.

Jun WANG's picture

Thanks a lot. I am gonna estimate the average normal of vertex. Two methods are utilized in my program.

#1. area-weighted average normal method.
#2. fitting the neighbor of the vertex with Bezier surface/quadric surface, then estimate the 1, 2-order geometry properties, such as normal, curvature, tensor,...

Thanks again.

Sharjith Naramparambath's picture

Sounds interesting, is it for something like building surface from point cloud. Just curious about it.

Jun WANG's picture

surface recognition in computer graphics...