Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compute normal vector to least square plane in PovRay only

Tags:

povray

Is it possible to calculate normal vector to a plane defined by set of points using PovRay only (proper set has more than 3 points)? At the moment I'm using external program that computes via Jacobi eigenvalues of a least square plane.

Still it would be nice not to have to switch for this step to different program but just to use internal procedures of PovRay.

Kris

like image 221
Kris_R Avatar asked Dec 04 '25 16:12

Kris_R


1 Answers

Here, I assume that the position of the plane is known and that you want to calculate the normal vector. I do not answer the question how this plane is calculated in the first place.

The normal vector to a plane defined by three points (e.g. A, B, C) in (3D) space can be calculated with the cross product of two vectors a=A-C and b=B-C (in the graph below, point A and B would be at the tips of the arrows a and b, respectively. Point C is at the starting point of the two vectors). I also assume that the points are not in a line.

The resulting vector is perpendicular to a and b, therefore it is normal to the given plane.

To get a vector of length 1, you would have to divide it by its length. Now to the question: In POVRay, I assume you have the coordinates in some variables. Then (omitting any #declare statements) you calculate the normal vector (the inices 1,2,3 correspond to the components in x,y,z direction):

n1 = a2*b3 - a3*b2;

n2 = a3*b1 - a1*b3;

n3 = a1*b2 - a2*b1;

The length L of vector n is L=sqrt(n1*n1 + n2*n2 + n3*n3). Now you divide each component by L and you have the normal vector of unit length.

The direction of the normal vector depends on how the three points are arranged on the plane. Counter-clockwise means that the normal vector is directed upwards (or outwards) from the plane, and vice versa. I used this to check whether a surface is visible or not (i.e. its normal vector points towards the point where the camera is located or away from the camera).

like image 122
Aziraphale Avatar answered Dec 06 '25 11:12

Aziraphale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!