Página 4
Angle between two lines
Página 5
Índice
See this article in english 
Página 6
Reflections and point-collisions in 2D

Lo sentimos - la página solicitada no está disponible en castellano. Mostrando la versión : en

Line normals

Alexander Hristov

The normal is the line perpendicular (orthogonal) to a figure at a specific point. Normals are important - among other uses - for calculating reflection equations.

Normal at a point

Normal to line

 

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:

tan(φ-π/2) = -tan(π/2-φ) = -cot(φ) = -1/tan(φ).

The equation of the normal is, then:

y = (-1/a)x + (y0+x0/a)

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

Unitary normal vector to line
x1,y1,x2,y2
(two points)

if y2- y1 ≠ 0, 

If y2- y1 = 0,
x = x0


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:

Oriented normal

normal-segment.java
 
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  
 

Código Fuente



 

Comentarios

 

Añadir Comentario

Nombre (opcional)
EMail (opcional, no se muestra)

Texto