The normal is the line perpendicular (orthogonal) to a figure at a specific point. Normals are important - among other uses - for calculating reflection equations.
![]() |
In the figure to the left, the starting line is black and the green line is the normal at x0,y0. For a non-vertical line y = ax+b, for the slope of the normal at x0,y0 we have:
The equation of the normal is, then:
If the line is vertical, the normal is simply y = x0 |
| Form | Equation of the normal at x0,y0 | Unitary Normal vector |
y = fx+g |
if f ≠ 0 y = (-1/f)x + (y0+x0/f) If f = 0, x = x0 |
![]() |
| x1,y1,x2,y2 (two points) |
if y2- y1 ≠ 0, If y2- y1 = 0,
|
![]() |
The following Java function computes the normal of a segment. The normal is oriented so that it coincedes with the direction of the segment when it is rotated 90 degrees counter-clockwise using the starting point as a center of rotation:
0001 /** 0002 * Computes the unitary normal vector of a segment 0003 * @param x1 Starting point of the segment 0004 * @param y1 Starting point of the segment 0005 * @param x2 Ending point of the segment 0006 * @param y2 Ending point of the segment 0007 * @return 0008 */ 0009 public Point2D.Double normal(int x1,int y1,int x2, int y2) { 0010 double nx,ny; 0011 if (x1 == x2) { 0012 nx = Math.signum(y2-y1); 0013 ny = 0; 0014 } else { 0015 double f = (y2-y1)/(double)(x2-x1); 0016 nx = f*Math.signum(x2-x1)/Math.sqrt(1+f*f); 0017 ny = -1*Math.signum(x2-x1)/Math.sqrt(1+f*f); 0018 } 0019 return new Point2D.Double(nx,ny); 0020 } 0021
|
normal-segment.java ( 626 bytes ) |