# Introduction to Cartesian Geometry

Welcome to Introduction to Cartesian Geometry

In Cartesian or Analytic Geometry we will learn how to represent points, lines, and planes using the Cartesian Coordinate System, also called Rectangular Coordinate System. This can be applied to solve a broad range of problems from geometry to algebra and it will be very useful later on Calculus.

# Cartesian Coordinate System

The foundations of Analytic Geometry lie in the search for describing geometric shapes by using algebraic equations. One of the most important mathematicians that helped to accomplish this task was René Descartes for whom the name is given to this exciting subject of mathematics.

## The Coordinate System

For a coordinate system to be useful we want to give to each point an attribute that helps to distinguish and relate different points. In the Cartesian system we do that by describing a point using the intersection of two(2D Coordinates) or more(Higher Dimensional Coordinates) lines. Therefore a point is represented as P(x1,x2,x3,...,xn) in "n" dimensions.

### 2D Coordinates

You can look at a 2D Coordinate system as a system in which a point can be defined using two values. We do this by using two perpendicular and directed lines called the abscissa(x-axis) and the ordinate(y-axis). The point of intersection of these two lines is called the origin denoted O(0,0). Any point can be determined as P(x,y), where x is the value in the x-axis and y is the value in the y-axis.

# 3d Coordinate Geometry

The coordinate system in two dimensions uses values containing width and depth expressed as values of ${\displaystyle X}$ and/or ${\displaystyle Y.}$

Coordinate geometry in three dimensions adds the dimension of height, usually expressed as a value of ${\displaystyle Z.}$ The axes of ${\displaystyle X}$ and ${\displaystyle Y}$ usually represent the horizontal plane. The ${\displaystyle Z}$ axis is thus vertical or normal to the plane of ${\displaystyle X}$ and ${\displaystyle Y.}$

In three dimensional space a point is shown as ${\displaystyle (x_{1},y_{1},z_{1})}$ where the 3 values locate the point relative to the origin along each of the ${\displaystyle X,Y,Z}$ axes respectively. The value ${\displaystyle (0,0,0)}$ is valid, usually the origin.

Within this page the values ${\displaystyle x_{1},y_{1},z_{1}}$ are all real numbers.

#### Examples of points in 3 dimensional space.

Points of 1 dimension

 Figure 1: Diagram showing ${\displaystyle X,Y,Z}$ axes of 3d Coordinate Geometry. Each of the points in the diagram has exactly one dimension. The point ${\displaystyle (10,\ 0,\ 0)}$ has only the dimension of width. It is on the ${\displaystyle X}$ axis. The point ${\displaystyle (0,\ 12,\ 0)}$ has only the dimension of depth. It is on the ${\displaystyle Y}$ axis. The point ${\displaystyle (0,\ 0,\ 13)}$ has only the dimension of height. It is on the ${\displaystyle Z}$ axis. ${\displaystyle }$${\displaystyle }$${\displaystyle }$${\displaystyle }$

Points of 2 dimensions

 Figure 2: Diagram showing ${\displaystyle X,Y,Z}$ axes of 3d Coordinate Geometry. Each of the points in the diagram has exactly two dimensions. The point ${\displaystyle (8,\ 6,\ 0)}$ has the dimensions of width and depth, no height. The point ${\displaystyle (0,\ 12,\ 6)}$ has the dimensions of depth and height, no width. The point ${\displaystyle 11,\ 0,\ -7)}$ has the dimensions of width and height, no depth.

Points of 3 dimensions

 Figure 3: Diagram showing ${\displaystyle X,Y,Z}$ axes of 3d Coordinate Geometry. Each of the points in the diagram has three dimensions.

#### Distance between 2 points

 Figure 1: Diagram illustrating distance between two points. Length ${\displaystyle OP={\sqrt {4^{2}+3^{2}}}}$ Length ${\displaystyle PQ=12-0}$ Length ${\displaystyle OQ={\sqrt {4^{2}+3^{2}+12^{2}}}}$ Consider the point ${\displaystyle Q\ (4,3,12).}$ What is the distance from point ${\displaystyle Q}$ to the origin? Point ${\displaystyle P}$ is the projection of ${\displaystyle Q}$ on to the plane of ${\displaystyle X,Y.}$ Calculate length ${\displaystyle OP={\sqrt {4^{2}+3^{2}}}.}$ Then length ${\displaystyle OQ={\sqrt {(OP)^{2}+12^{2}}}={\sqrt {4^{2}+3^{2}+12^{2}}}={\sqrt {169}}=13.}$ Length ${\displaystyle OQ={\sqrt {x_{1}^{2}+y_{1}^{2}+z_{1}^{2}}}.}$ In this case ${\displaystyle (x_{1},y_{1},z_{1})=(4,3,12).}$ The general case: For two points ${\displaystyle M\ (x_{M},y_{M},z_{M})}$ and ${\displaystyle N\ (x_{N},y_{N},z_{N})}$ the distance ${\displaystyle MN={\sqrt {(x_{M}-x_{N})^{2}+(y_{M}-y_{N})^{2}+(z_{M}-z_{N})^{2}}}.}$ Length ${\displaystyle OQ}$ is the special case in which ${\displaystyle (x_{N},y_{N},z_{N})=(0,0,0).}$ The distance ${\displaystyle MN}$ may be ${\displaystyle 0}$ in which case ${\displaystyle M}$ and ${\displaystyle N}$ are the same point.

#### The line in 3 dimensions

##### as 2 points
 In the example above line ${\displaystyle OP}$ passes through the points ${\displaystyle O\ (0,0,0)}$ and ${\displaystyle P\ (4,3,0).}$ The line ${\displaystyle OP}$ may be defined by the two points ${\displaystyle O}$ and ${\displaystyle P}$ provided that the length ${\displaystyle OP}$ is non-zero. Line ${\displaystyle OP=(O,P)=((0,0,0),\ (4,3,0))}$ There are other ways to define a line. Add a descriptor to avoid confusion: Line ${\displaystyle OP=(O,P)=((0,0,0),\ (4,3,0),}$ '${\displaystyle 2}$points'${\displaystyle )}$ where: ${\displaystyle (x_{O},y_{O},z_{O})=(0,0,0)}$ and ${\displaystyle (x_{P},y_{P},z_{P})=(4,3,0).}$ Line ${\displaystyle PO=(P,O)=((4,3,0),\ (0,0,0),}$ '${\displaystyle 2}$points'${\displaystyle ).}$ Similarly: line ${\displaystyle PQ=(P,Q)=((4,3,0),\ (4,3,12),}$ '${\displaystyle 2}$points'${\displaystyle )}$ line ${\displaystyle QP=(Q,P)=((4,3,12),\ (4,3,0),}$ '${\displaystyle 2}$points'${\displaystyle )}$ line ${\displaystyle OQ=(O,Q)=((0,0,0),\ (4,3,12),}$ '${\displaystyle 2}$points'${\displaystyle )}$ and line ${\displaystyle QO=(Q,O)=((4,3,12),\ (0,0,0),}$ '${\displaystyle 2}$points'${\displaystyle ).}$
##### as point and 3 direction numbers

For information about direction numbers see Line_(Geometry)#Direction_Numbers.

Line ${\displaystyle OQ}$ above is defined by 2 points ${\displaystyle O\ (x_{1},y_{1},z_{1})=(0,0,0)}$ and ${\displaystyle Q\ (x_{2},y_{2},z_{2})=(4,3,12).}$

The direction numbers of line ${\displaystyle OQ=[A,B,C]=[x_{2}-x_{1},y_{2}-y_{1},z_{2}-z_{1}]=[4,3,12].}$

A line may be defined as ${\displaystyle ((x_{1},y_{1},z_{1}),\ [A_{1},B_{1},C_{1}])}$ where:

${\displaystyle (x_{1},y_{1},z_{1})}$ is a known point on the line, and

${\displaystyle [A_{1},B_{1},C_{1}]}$ are the direction numbers of the line.

 In practice: The programming language python, for example, recognizes [A1, B1, C1] as a list and code can interpret these values as direction numbers. Python recognizes (x1, y1, z1) as a tuple and code can interpret these values as coordinates of a point. In python a line may be defined as: ( (x1, y1, z1), [A1, B1, C1], 'line' ) or ( (x1, y1, z1), (x2, y2, z2), 'line' ).

Line ${\displaystyle OQ}$ may be defined as ${\displaystyle ((0,0,0),(4,3,12),}$ 'p&dn'${\displaystyle ).}$

Given a point on the line and the direction numbers of the line, any other point on the line may be established by introducing constant ${\displaystyle K.}$

On line ${\displaystyle ((x_{1},y_{1},z_{1}),\ (A_{1},B_{1},C_{1}),}$ 'p&dn'${\displaystyle )}$ any second point ${\displaystyle (x_{2},y_{2},z_{2})=(x_{1}+KA_{1},y_{1}+KB_{1},z_{1}+KC_{1})}$ and distance from ${\displaystyle (x_{1},y_{1},z_{1})}$ to ${\displaystyle (x_{2},y_{2},z_{2})}$

${\displaystyle ={\sqrt {(x_{2}-x_{1})^{2}+(y_{2}-y_{1})^{2}+(z_{2}-z_{1})^{2}}}}$

${\displaystyle ={\sqrt {(x_{1}+KA_{1}-x_{1})^{2}+(x_{2}+KB_{1}-y_{1})^{2}+(z_{1}+KC_{1}-z_{1})^{2}}}}$

${\displaystyle ={\sqrt {(KA_{1})^{2}+(KB_{1})^{2}+(KC_{1})^{2}}}}$

${\displaystyle =K{\sqrt {A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}}$

It would be convenient if the value ${\displaystyle A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}$ would ${\displaystyle =1.}$

If ${\displaystyle A_{1}^{2}+B_{1}^{2}+C_{1}^{2}==1,}$ the values ${\displaystyle A_{1},B_{1},C_{1}}$ are the direction cosines of the line.

To convert direction numbers to direction cosines divide each direction number by ${\displaystyle {\sqrt {A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}.}$

${\displaystyle ({\frac {A_{1}}{\sqrt {A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}})^{2}+({\frac {B_{1}}{\sqrt {A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}})^{2}+({\frac {C_{1}}{\sqrt {A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}})^{2}}$

${\displaystyle ={\frac {A_{1}^{2}}{A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}+{\frac {B_{1}^{2}}{A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}+{\frac {C_{1}^{2}}{A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}}$

${\displaystyle ={\frac {A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}{A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}=1.}$

If ${\displaystyle [A,B,C]}$ are the direction cosines of the line, any second point on the line exactly ${\displaystyle K}$ units from ${\displaystyle (x_{1},y_{1},z_{1})}$ has coordinates ${\displaystyle (x_{1}+KA,y_{1}+KB,z_{1}+KC).}$

 While point ${\displaystyle (0,0,0)}$ is valid, direction numbers ${\displaystyle [A,B,C]=[0,0,0]}$ are not valid. For the group of direction numbers to be valid, at least one of ${\displaystyle A,B,C}$ must be non-zero.

#### Angle between two lines

In the diagram line ${\displaystyle OM}$ has direction numbers ${\displaystyle [A_{1},B_{1},C_{1}].}$ Point ${\displaystyle M}$ has coordinates ${\displaystyle (A_{1},B_{1},C_{1}).}$

Line ${\displaystyle ON}$ has direction numbers ${\displaystyle [A_{2},B_{2},C_{2}]}$ and point ${\displaystyle N}$ has coordinates ${\displaystyle (A_{2},B_{2},C_{2}).}$

Length ${\displaystyle OM={\sqrt {A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}.}$

Length ${\displaystyle ON={\sqrt {A_{2}^{2}+B_{2}^{2}+C_{2}^{2}}}.}$

Length ${\displaystyle MN={\sqrt {(A_{1}-A_{2})^{2}+(B_{1}-B_{2})^{2}+(C_{1}-C_{2})^{2}}}.}$

By the cosine rule ${\displaystyle MN^{2}=ON^{2}+OM^{2}-2\cdot OM\cdot ON\cdot \cos(\theta ).}$

${\displaystyle \cos(\theta )={\frac {MN^{2}-ON^{2}-OM^{2}}{-2\cdot OM\cdot ON}}={\frac {ON^{2}+OM^{2}-MN^{2}}{2\cdot OM\cdot ON}}}$ ${\displaystyle ={\frac {A_{1}\cdot A_{2}+B_{1}\cdot B_{2}+C_{1}\cdot C_{2}}{{\sqrt {A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}\cdot {\sqrt {A_{2}^{2}+B_{2}^{2}+C_{2}^{2}}}}}}$

If all values are direction cosines, ${\displaystyle \cos(\theta )=A_{1}\cdot A_{2}+B_{1}\cdot B_{2}+C_{1}\cdot C_{2}.}$

If ${\displaystyle \cos(\theta )==0,}$ the lines are normal.

If ${\displaystyle \cos(\theta )==1}$ or ${\displaystyle \cos(\theta )==-1,}$ the lines are parallel.

 Angle between line and each axis: Let a line have direction cosines ${\displaystyle [A_{1},B_{1},C_{1}].}$ Let ${\displaystyle X}$ axis have direction cosines ${\displaystyle [A_{2},B_{2},C_{2}]=[1,0,0].}$ Let ${\displaystyle \theta _{X}}$ be angle between line and ${\displaystyle X}$ axis. ${\displaystyle \cos(\theta _{X})=A_{1}\cdot 1+B_{1}\cdot 0+C_{1}\cdot 0=A_{1}.}$ Hence the expression direction cosine. ${\displaystyle A_{1}}$ is the cosine of the angle between line and ${\displaystyle X}$ axis. Similarly ${\displaystyle B_{1}}$ is cosine of angle between line and ${\displaystyle Y}$ axis and ${\displaystyle C_{1}}$ is cosine of angle between line and ${\displaystyle Z}$ axis.

Parallel lines:

Let one line have direction numbers ${\displaystyle [A,B,C]}$ and a second line have ${\displaystyle [KA,KB,KC].}$

${\displaystyle \cos(\theta )}$ ${\displaystyle ={\frac {A_{1}\cdot A_{2}+B_{1}\cdot B_{2}+C_{1}\cdot C_{2}}{{\sqrt {A_{1}^{2}+B_{1}^{2}+C_{1}^{2}}}\cdot {\sqrt {A_{2}^{2}+B_{2}^{2}+C_{2}^{2}}}}}}$ ${\displaystyle ={\frac {A\cdot KA+B\cdot KB+C\cdot KC}{{\sqrt {A^{2}+B^{2}+C^{2}}}\cdot K{\sqrt {A^{2}+B^{2}+C^{2}}}}}}$ ${\displaystyle ={\frac {K(A^{2}+B^{2}+C^{2})}{K(A^{2}+B^{2}+C^{2})}}=1.}$

${\displaystyle \theta =0^{\circ }}$ and the lines are parallel.

Similarly, if the second line has direction numbers ${\displaystyle [-KA,-KB,-KC],\ \cos(\theta )=-1,\ \theta =180^{\circ }}$ and the lines are parallel.

To verify that two lines are not parallel, check that ${\displaystyle |\cos(\theta )|}$ does not equal ${\displaystyle 1.}$

 If one line has direction numbers ${\displaystyle [A_{1},B_{1},C_{1}]}$ and the second line has direction numbers ${\displaystyle [A_{2},B_{2},C_{2}]=[KA_{1},KB_{1},KC_{1}]}$ then: ${\displaystyle {\frac {A_{2}}{A_{1}}}={\frac {B_{2}}{B_{1}}}={\frac {C_{2}}{C_{1}}}=K}$ ${\displaystyle A_{2}B_{1}=A_{1}B_{2},\ B_{2}C_{1}=B_{1}C_{2},\ A_{2}C_{1}=A_{1}C_{2}}$ The values ${\displaystyle B_{1}C_{2}-C_{1}B_{2},}$ ${\displaystyle C_{1}A_{2}-A_{1}C_{2},}$ ${\displaystyle A_{1}B_{2}-B_{1}A_{2}}$ are the direction numbers of the normal to both lines. If the normal to both lines has direction numbers [0, 0, 0], the lines are parallel.

#### Normal to 2 lines

A line normal or perpendicular to two lines is normal to each line.

Before attempting to calculate the direction numbers of the normal, first verify that the two lines are not parallel.

Let the normal have direction numbers ${\displaystyle [A_{1},B_{1},C_{1}].}$

Let the 2 lines have direction numbers ${\displaystyle [A_{2},B_{2},C_{2}],\ [A_{3},B_{3},C_{3}].}$

Then:

${\displaystyle A_{1}A_{2}+B_{1}B_{2}+C_{1}C_{2}=0\ \dots \ (1)}$ and

${\displaystyle A_{1}A_{3}+B_{1}B_{3}+C_{1}C_{3}=0\ \dots \ (2)}$

${\displaystyle (1)*C_{3},\ A_{1}A_{2}C_{3}+B_{1}B_{2}C_{3}+C_{1}C_{2}C_{3}=0\ \dots \ (3)}$

${\displaystyle (2)*C_{2},\ A_{1}A_{3}C_{2}+B_{1}B_{3}C_{2}+C_{1}C_{3}C_{2}=0\ \dots \ (4)}$

${\displaystyle (3)-(4),\ A_{1}(A_{2}C_{3}-A_{3}C_{2})+B_{1}(B_{2}C_{3}-B_{3}C_{2})=0\ \dots \ (5)}$

${\displaystyle {\frac {A_{1}}{B_{1}}}={\frac {B_{3}C_{2}-B_{2}C_{3}}{A_{2}C_{3}-A_{3}C_{2}}}\ \dots \ (6)}$

If divisor ${\displaystyle A_{2}C_{3}-A_{3}C_{2}==0,}$ ${\displaystyle {\frac {B_{1}}{C_{1}}}={\frac {C_{3}A_{2}-C_{2}A_{3}}{B_{2}A_{3}-B_{3}A_{2}}}\ \dots \ (7)}$

If divisor ${\displaystyle B_{2}A_{3}-B_{3}A_{2}==0,}$ ${\displaystyle {\frac {C_{1}}{A_{1}}}={\frac {A_{3}B_{2}-A_{2}B_{3}}{C_{2}B_{3}-C_{3}B_{2}}}\ \dots \ (8)}$

Provided that all inputs are valid, then at least one of ${\displaystyle [A_{1},B_{1},C_{1}]}$ must be non-zero and at least one of ${\displaystyle (6)}$ or ${\displaystyle (7)}$ or ${\displaystyle (8)}$ must be valid.

From ${\displaystyle (6),(7),(8)}$ above:

${\displaystyle {\frac {A_{1}}{B_{3}C_{2}-B_{2}C_{3}}}={\frac {B_{1}}{A_{2}C_{3}-A_{3}C_{2}}}={\frac {C_{1}}{B_{2}A_{3}-B_{3}A_{2}}}}$

Values of ${\displaystyle [A_{1},B_{1},C_{1}]}$ that satisfy this condition are:

${\displaystyle [B_{3}C_{2}-B_{2}C_{3},\ A_{2}C_{3}-A_{3}C_{2},\ B_{2}A_{3}-B_{3}A_{2}].}$

Proof:

Angle between ${\displaystyle [A_{1},B_{1},C_{1}]}$ and ${\displaystyle [A_{2},B_{2},C_{2}]:}$

${\displaystyle \cos(\theta )=(B_{3}C_{2}-B_{2}C_{3})A_{2}+(A_{2}C_{3}-A_{3}C_{2})B_{2}+(B_{2}A_{3}-B_{3}A_{2})C_{2}}$ ${\displaystyle =B_{3}C_{2}A_{2}-B_{2}C_{3}A_{2}+A_{2}C_{3}B_{2}-A_{3}C_{2}B_{2}+B_{2}A_{3}C_{2}-B_{3}A_{2}C_{2}}$ ${\displaystyle =B_{3}C_{2}A_{2}-B_{3}A_{2}C_{2}+A_{2}C_{3}B_{2}-B_{2}C_{3}A_{2}+B_{2}A_{3}C_{2}-A_{3}C_{2}B_{2}}$ ${\displaystyle =0}$

Therefore the two groups of direction numbers are normal.

Similarly it can be shown that the two groups of direction numbers ${\displaystyle (A_{1},B_{1},C_{1})}$ and ${\displaystyle (A_{3},B_{3},C_{3})}$ are normal.

The line normal to ${\displaystyle [A_{2},B_{2},C_{2}]}$ and ${\displaystyle [A_{3},B_{3},C_{3}]}$ has direction numbers:

${\displaystyle A_{1}=B_{3}C_{2}-C_{3}B_{2}}$

${\displaystyle B_{1}=C_{3}A_{2}-A_{3}C_{2}}$

${\displaystyle C_{1}=A_{3}B_{2}-B_{3}A_{2}}$

 Parallel input: Let ${\displaystyle [A_{3},B_{3},C_{3}]=[KA_{2},KB_{2},KC_{2}]}$ Then ${\displaystyle A_{1}=B_{3}C_{2}-C_{3}B_{2}=(KB_{2})(C_{2})-(KC_{2})(B_{2})=0}$ If the two groups of direction numbers ${\displaystyle [A_{2},B_{2},C_{2}],[A_{3},B_{3},C_{3}]}$ are parallel, ${\displaystyle [A_{1},B_{1},C_{1}]=[0,0,0].}$

#### Normal to 1 line

 If a given line has direction numbers [A, B, C], then any of the following groups of direction numbers is normal to the given line: [0, -C, B], [-C, 0, A], [-B, A, 0] For example: If the given line has direction numbers [1, 0, 0], arbitrary normals have direction numbers [0, 0, 0], [0, 0, 1], [0, 1, 0]. In this case only the groups [0, 0, 1], [0, 1, 0] are valid. If the given line has direction numbers [1, 3, -4], arbitrary normals have direction numbers [0, 4, 3], [4, 0, 1], [-3, 1, 0]. In this case all three groups of direction numbers are valid. If the given line has direction numbers [1, 0, -3], arbitrary normals have direction numbers [0, 3, 0], [3, 0, 1], [0, 1, 0]. In this case all three groups of direction numbers are valid. However, the groups [0, 3, 0], [0, 1, 0] are parallel.

#### Point and line

In the diagram line ${\displaystyle PQ}$ and point ${\displaystyle M}$ are well defined and ${\displaystyle \theta =\angle MPQ.}$${\displaystyle }$${\displaystyle }$

Point ${\displaystyle N}$ is on line ${\displaystyle PQ.}$

Line ${\displaystyle MN}$ is perpendicular to line ${\displaystyle PQ.}$

Calculate the coordinates of point ${\displaystyle N}$ and length ${\displaystyle MN.}$

Initial considerations:

• Points ${\displaystyle M,P}$ may be the same point in which case points ${\displaystyle M,N,P}$ are the same point and lengths ${\displaystyle MN=NP=PM=0.}$
• Point ${\displaystyle M}$ may be on line ${\displaystyle PQ}$ in which case lengths ${\displaystyle PM=PN}$ and length ${\displaystyle MN=0.}$
• line ${\displaystyle MP}$ may be perpendicular to line ${\displaystyle PQ}$ in which case lengths ${\displaystyle MP=MN}$ and length ${\displaystyle PN=0.}$

Calculate direction cosines of line ${\displaystyle PQ}$: ${\displaystyle [A1,B1,C1].}$

Calculate direction cosines of line ${\displaystyle PM}$: ${\displaystyle [A2,B2,C2].}$

Calculate ${\displaystyle \cos(\theta ).}$

Calculate length ${\displaystyle PM.}$

Calculate length ${\displaystyle PN=PM\cdot \cos(\theta ).}$

Let point ${\displaystyle P}$ have coordinates ${\displaystyle (x_{1},y_{1},z_{1})}$

Then point ${\displaystyle N=(x_{1}+}$length${\displaystyle PN*A1,\ y_{1}+}$length${\displaystyle PN*B1,\ z_{1}+}$length${\displaystyle PN*C1).}$

Calculate length ${\displaystyle MN.}$

##### By extending line PQ with constant K

Let line ${\displaystyle PN}$ be defined as ( (p,q,r), [A, B, C], 'line' ).

Let point ${\displaystyle N}$ have coordinates ( p+KA, q+KB, r+KC ).

Let point ${\displaystyle M}$ have coordinates ( s, t, u ).

Then line ${\displaystyle MN}$ has direction numbers [ p+KA-s, q+KB-t, r+KC-u ].

Lines ${\displaystyle MN,PN}$ are normal. Therefore:

${\displaystyle A(p+KA-s)+B(q+KB-t)+C(r+KC-u)=0}$ and

${\displaystyle K={\frac {As-Ap+Bt-Bq+Cu-Cr}{A^{2}+B^{2}+C^{2}}}.}$

Use this value of ${\displaystyle K}$ to calculate the coordinates of point ${\displaystyle N}$ and the direction numbers of line ${\displaystyle MN.}$

 Example: line1 is defined as ( (5,-9,17), [3,-2,5], 'line'). Point M has coordinates (-1,14,45). Calculate coordinates of point N on line1 so that line MN is normal to line1. # python code p,q,r = 5,-9,17 A,B,C = 3,-2,5 s,t,u = -1,14,45 K = (A*s - A*p + B*t - B*q + C*u - C*r)/(A*A + B*B + C*C) print ('K =', K) print ('N = (', p+K*A, ', ', q+K*B, ', ', r+K*C, ')', sep='')  K = 2.0 N = (11.0, -13.0, 27.0) 

 Distance between two parallel lines: Let ${\displaystyle M}$ be a point on a line parallel to line ${\displaystyle PQ.}$ Distance between the two lines is length ${\displaystyle MN.}$

#### Points of closest approach

Points of closest approach are the 2 points at which the distance between 2 skew lines is minimum.

Let 2 lines be line1 and line2. Verify that the lines are not parallel.

Calculate point ${\displaystyle P_{1}}$ on line1 and point ${\displaystyle P_{2}}$ on line2 so that line ${\displaystyle P_{1}P_{2}}$ is normal to line2 and line ${\displaystyle P_{2}P_{1}}$ is normal to line1.

It's possible that length ${\displaystyle P_{1}P_{2}}$ may be zero in which case points ${\displaystyle P_{1},P_{2}}$ are the same point and the lines intersect.

Let line1 be defined as point ${\displaystyle (p,q,r)}$ with direction numbers ${\displaystyle [A_{1},B_{1},C_{1}].}$

Let line2 be defined as point ${\displaystyle (s,t,u)}$ with direction numbers ${\displaystyle [A_{2},B_{2},C_{2}].}$

Calculate the direction numbers of the normal: ${\displaystyle [A_{3},B_{3},C_{3}].}$

Relative to line1 point ${\displaystyle P_{1}=(p+K_{1}\cdot A_{1},\ q+K_{1}\cdot B_{1},\ r+K_{1}\cdot C_{1})}$

and point ${\displaystyle P_{2}=(p+K_{1}\cdot A_{1}+K_{3}\cdot A_{3},\ q+K_{1}\cdot B_{1}+K_{3}\cdot B_{3},\ r+K_{1}\cdot C_{1}+K_{3}\cdot C_{3}).}$

Relative to line2 point ${\displaystyle P_{2}=(s+K_{2}\cdot A_{2},\ t+K_{2}\cdot B_{2},\ u+K_{2}\cdot C_{2})}$

Therefore:

${\displaystyle p+K_{1}\cdot A_{1}+K_{3}\cdot A_{3}=s+K_{2}\cdot A_{2}}$

${\displaystyle q+K_{1}\cdot B_{1}+K_{3}\cdot B_{3}=t+K_{2}\cdot B_{2}}$

${\displaystyle r+K_{1}\cdot C_{1}+K_{3}\cdot C_{3}=u+K_{2}\cdot C_{2}}$

or:

${\displaystyle A_{1}\cdot K_{1}-A_{2}\cdot K_{2}+A_{3}\cdot K_{3}+p-s=0\ \dots \ (1)}$

${\displaystyle B_{1}\cdot K_{1}-B_{2}\cdot K_{2}+B_{3}\cdot K_{3}+q-t=0\ \dots \ (2)}$

${\displaystyle C_{1}\cdot K_{1}-C_{2}\cdot K_{2}+C_{3}\cdot K_{3}+r-u=0\ \dots \ (3)}$

This is a system of three equations with three unknowns: ${\displaystyle K_{1},K_{2},K_{3}.}$

If ${\displaystyle [A_{3},B_{3},C_{3}]}$ are direction cosines, ${\displaystyle K_{3}=}$ length ${\displaystyle P_{1}P_{2}.}$

Example 1:

 Figure 1: Diagram illustrating points of closest approach of 2 lines in 3 dimensions. line1 is defined by points ${\displaystyle (0,5,6),(8,11,-12).}$ line2 is defined by points ${\displaystyle (3,-14,-5),(-1,-9,-8).}$ Point ${\displaystyle P_{1}}$ on line1 ${\displaystyle =(4,8,-3).}$ Point ${\displaystyle P_{2}}$ on line2 ${\displaystyle =(-5,-4,-11).}$ Line ${\displaystyle P_{1}P_{2}}$ is normal to line2. Line ${\displaystyle P_{2}P_{1}}$ is normal to line1. # python code # line1 = ((0,5,6),(8,11,-12),'line') p,q,r = 0,5,6 A1,B1,C1 = 8-0, 11-5, -12-6 # line2 = ((3,-14,-5),(-1,-9,-8),'line') s,t,u = 3,-14,-5 A2,B2,C2 = -1-3, -9-(-14), -8-(-5) # Direction numbers of the normal: A3,B3,C3 = ( B2*C1 - C2*B1, C2*A1 - A2*C1, A2*B1 - B2*A1 ) data = [ [ A1, -A2, A3, p-s ], [ B1, -B2, B3, q-t ], [ C1, -C2, C3, r-u ] ] K1,K2,K3 = solve3by4(data) print ('K1,K2,K3 = {}, {}, {}'.format( K1,K2,K3)) P1 = ( p+K1*A1, q+K1*B1, r+K1*C1 ) P2 = ( s+K2*A2, t+K2*B2, u+K2*C2 ) print ('P1 = ',P1,'\nP2 = ',P2,sep='')  K1,K2,K3 = 0.5, 1.0, 0.125 P1 = (4.0, 8.0, -3.0) P2 = (-5.0, -4.0, -11.0)  For function solve3by4(input), see "Solving_3_by_4"

Example 2:

 Two lines are defined as: line1: ((-6,1,26), [-3,2,5], 'line') and line2: ((7,9,-15), [2,7,-13], 'line') Calculate the points of closest approach. # line1 = ((-6,1,26), [-3,2,5],'line') p,q,r = -6,1,26 A1,B1,C1 = -3,2,5 # line2 = ((7,9,-15),[2,7,-13],'line') s,t,u = 7,9,-15 A2,B2,C2 = 2,7,-13 # As above, continue with: # Direction numbers of the normal:  K1,K2,K3 = -3.0, -2.0, 0.0 P1 = (3.0, -5.0, 11.0) P2 = (3.0, -5.0, 11.0)  In this case, ${\displaystyle K_{3}=0}$ and the lines intersect at point ${\displaystyle (3,-5,11).}$

# The plane in 3 dimensions

In two dimensions the point that is always equidistant from two fixed points is the line.

In three dimensions the point that is always equidistant from two fixed points is the plane.

Let point ${\displaystyle P_{1}}$ have coordinates ${\displaystyle (a,b,c).}$

Let point ${\displaystyle P_{2}}$ have coordinates ${\displaystyle (d,e,f).}$

Distance ${\displaystyle P_{1}P_{2}}$ must be non-zero.

Let point ${\displaystyle P_{xyz}}$ have coordinates ${\displaystyle (x,y,z).}$

Then length ${\displaystyle P_{1}P_{xyz}}$ = length ${\displaystyle P_{2}P_{xyz}.}$

${\displaystyle (x-a)^{2}+(y-b)^{2}+(z-c)^{2}=(x-d)^{2}+(y-e)^{2}+(z-f)^{2}}$

${\displaystyle x^{2}-2ax+a^{2}+y^{2}-2by+b^{2}+z^{2}-2cz+c^{2}}$${\displaystyle =x^{2}-2dx+d^{2}+y^{2}-2ey+e^{2}+z^{2}-2fz+f^{2}}$

${\displaystyle -2ax+a^{2}-2by+b^{2}-2cz+c^{2}=-2dx+d^{2}-2ey+e^{2}-2fz+f^{2}}$

${\displaystyle -2ax-2by-2cz+a^{2}+b^{2}+c^{2}=-2dx-2ey-2fz+d^{2}+e^{2}+f^{2}}$

${\displaystyle 2(d-a)x+2(e-b)y+2(f-c)z+a^{2}+b^{2}+c^{2}-(d^{2}+e^{2}+f^{2})=0}$

This equation has the form ${\displaystyle Ax+By+Cz+D=0}$ where:

${\displaystyle A=2(d-a);\ d-a={\frac {A}{2}}}$

${\displaystyle B=2(e-b);\ e-b={\frac {B}{2}}}$

${\displaystyle C=2(f-c);\ f-c={\frac {C}{2}}}$

${\displaystyle D=a^{2}+b^{2}+c^{2}-(d^{2}+e^{2}+f^{2})}$

#### Normal to the plane:

 Line ${\displaystyle P_{1}P_{2}}$ is normal to the plane and it has direction numbers ${\displaystyle [d-a,e-b,f-c]}$ or ${\displaystyle [{\frac {A}{2}},{\frac {B}{2}},{\frac {C}{2}}].}$ When a plane is defined as ${\displaystyle Ax+By+Cz+D=0,}$ the line normal to the plane has direction numbers ${\displaystyle [A,B,C].}$

#### Distances:

 Distance ${\displaystyle P_{1}P_{2}={\sqrt {(d-a)^{2}+(e-b)^{2}+(f-c)^{2}}}}$ ${\displaystyle ={\sqrt {({\frac {A}{2}})^{2}+({\frac {B}{2}})^{2}+({\frac {C}{2}})^{2}}}}$ ${\displaystyle ={\frac {\sqrt {A^{2}+B^{2}+C^{2}}}{2}}}$ Distance from each point ${\displaystyle P_{1},P_{2}}$ to plane ${\displaystyle ={\frac {\sqrt {A^{2}+B^{2}+C^{2}}}{4}}.}$ Consider the expression ${\displaystyle Ax+By+Cz+D.}$ Substitute ${\displaystyle (d,e,f)}$ or ${\displaystyle (a,b,c)}$ for ${\displaystyle (x,y,z).}$ ${\displaystyle Ad+Be+Cf+D={\frac {A^{2}+B^{2}+C^{2}}{4}};}$ ${\displaystyle {\frac {Ad+Be+Cf+D}{\sqrt {A^{2}+B^{2}+C^{2}}}}}$${\displaystyle ={\frac {\sqrt {A^{2}+B^{2}+C^{2}}}{4}}}$ Let ${\displaystyle A_{1}={\frac {A}{\sqrt {A^{2}+B^{2}+C^{2}}}},}$ ${\displaystyle \ B_{1}={\frac {B}{\sqrt {A^{2}+B^{2}+C^{2}}}},}$ ${\displaystyle \ C_{1}={\frac {C}{\sqrt {A^{2}+B^{2}+C^{2}}}}.}$ ${\displaystyle \ D_{1}={\frac {D}{\sqrt {A^{2}+B^{2}+C^{2}}}}.}$ Then ${\displaystyle A_{1}d+B_{1}e+C_{1}f+D_{1}}$= distance from point ${\displaystyle (d,e,f)}$ to plane. ${\displaystyle Aa+Bb+Cc+D={\frac {-(A^{2}+B^{2}+C^{2})}{4}}.}$ Similarly, ${\displaystyle A_{1}a+B_{1}b+C_{1}c+D_{1}}$= distance from point ${\displaystyle (a,b,c)}$ to plane with opposite sign. When the values ${\displaystyle (A,B,C)}$ are all direction cosines, the distance from point ${\displaystyle (a,b,c)}$ to plane ${\displaystyle =Aa+Bb+Cc+D}$ with the sign of the result determined by the position of the point relative to the origin. If on the same side of the plane as the origin, the sign of the result is the sign of D. If on the side of the plane opposite to that of the origin, the sign of the result is the sign of -D.

#### To visualize the plane:

Think of the normal to the plane. The normal has direction numbers ${\displaystyle [A,B,C].}$ The plane is perpendicular to the normal.

Note which direction number or numbers are missing. The plane is parallel to the missing axes.

The plane ${\displaystyle x=4}$ is parallel to both ${\displaystyle Y,Z}$ axes.

The plane ${\displaystyle y=3}$ is parallel to both ${\displaystyle X,Z}$ axes.

The plane ${\displaystyle z=-2}$ is parallel to both ${\displaystyle X,Y}$ axes.

The plane ${\displaystyle 3x-4y+7=0}$ is parallel to the ${\displaystyle Z}$ axis.

The plane ${\displaystyle 3x-4z=7}$ is parallel to the ${\displaystyle Y}$ axis.

The plane ${\displaystyle 3y-4z=7}$ is parallel to the ${\displaystyle X}$ axis.

The plane ${\displaystyle 9x-8y+12z+9=0}$ is not parallel to any axis.

##### Various planes in 3 dimensions
 plane x=4. plane y=3. plane z=-2. plane 3x-4y+7=0. plane 3x-4z=7. plane 3y-4z=7. plane 9x-8y+12z+9=0.

#### Defining the plane

##### By definition above

Given two points as above, the equation ${\displaystyle Ax+By+Cz+D=0}$ may be calculated.

If this is too complicated, calculate the three direction numbers and the point midway between the two given points. Proceed as under "Point and direction numbers" below.

##### By point and direction numbers

A point and direction numbers usually define a line. In this case it is a special line, the line normal to the plane with the given point being a point in the plane.

Given ${\displaystyle ((x_{1},y_{1},z_{1}),[A_{1},B_{1},C_{1}]):}$

The equation of the plane is ${\displaystyle A_{1}x+B_{1}y+C_{1}z+D=0}$ where ${\displaystyle D=-(A_{1}x_{1}+B_{1}y_{1}+C_{1}z_{1}).}$

##### By three points

Verify that the three points form a real triangle with all sides non-zero.

From the three points produce two groups of direction numbers. Calculate the direction numbers of the normal to the two groups of direction numbers. Using any one of the points and the direction numbers of the normal proceed as under "Point and direction numbers" above.

#### Plane and line

Given a plane and a line in 3 dimensions some relevant questions are:

• Is the line parallel to the plane? if so, what is distance from line to plane?
• If not parallel, what is the point within the plane at which the line enters the plane?

Let the plane be defined as: ${\displaystyle Ax+By+Cz+D=0.}$

Let the line be defined as point ${\displaystyle (x_{1},y_{1},z_{1})}$ and direction numbers ${\displaystyle [A_{1},B_{1},C_{1}].}$

The point at which the line enters the plane is: ${\displaystyle (x_{1}+KA_{1},y_{1}+KB_{1},z_{1}+KC_{1}).}$

These points satisfy the equation of the plane:

${\displaystyle A(x_{1}+KA_{1})+B(y_{1}+KB_{1})+C(z_{1}+KC_{1})+D=0}$

${\displaystyle K={\frac {-(+Ax_{1}+By_{1}+Cz_{1}+D)}{AA1+BB1+CC1}}.}$

The divisor ${\displaystyle AA1+BB1+CC1}$ is the top line of the equation for ${\displaystyle \cos \theta ,}$ angle between two lines.

If ${\displaystyle \cos \theta ==0,}$ the angle between line and normal to the plane is ${\displaystyle 90^{\circ }}$ and line is parallel to plane.

The point of intersection is: ${\displaystyle (x_{1}+KA_{1},y_{1}+KB_{1},z_{1}+KC_{1}).}$

If the direction numbers ${\displaystyle [A_{1},B_{1},C_{1}]}$ are all direction cosines, distance from point to plane along the line is ${\displaystyle K.}$

 Figure 1: Diagram illustrating point of intersection of line ${\displaystyle PR}$ and plane at point ${\displaystyle R.}$ For example: In the diagram point ${\displaystyle P}$ has coordinates ${\displaystyle (8,11,-12).}$ Line ${\displaystyle PR}$ through ${\displaystyle P}$ has direction numbers ${\displaystyle [5,25,-7].}$ Point ${\displaystyle R}$ is within the plane ${\displaystyle 9x+12y+8z+181=0.}$ What are the coordinates of point ${\displaystyle R}$? With ${\displaystyle [A,B,C]}$ as direction cosines the coefficients of the plane ${\displaystyle =(A,B,C,D)=({\frac {9}{17}},{\frac {12}{17}},{\frac {8}{17}},{\frac {181}{17}}).}$ As direction cosines the direction numbers of the line ${\displaystyle =[A_{1},B_{1},C_{1}]=[{\frac {5}{\sqrt {699}}},{\frac {25}{\sqrt {699}}},{\frac {-7}{\sqrt {699}}}].}$ Using ${\displaystyle K={\frac {-(+Ax_{1}+By_{1}+Cz_{1}+D)}{AA_{1}+BB_{1}+CC_{1}}}={\frac {-17}{0.643}}=-26.4386,}$ The point of intersection ${\displaystyle =(x_{1}+KA_{1},y_{1}+KB_{1},z_{1}+KC_{1})=(3,-14,-5).}$ Provided that all values ${\displaystyle [A,B,C],[A_{1},B_{1},C_{1}]}$ are direction cosines, ${\displaystyle -(+Ax_{1}+By_{1}+Cz_{1}+D)=}$ length ${\displaystyle PQ}$ and ${\displaystyle AA_{1}+BB_{1}+CC_{1}=\cos(\theta ).}$ If the value of ${\displaystyle \angle \theta _{1}}$ is desired, ${\displaystyle \sin(\theta _{1})=\cos(\theta ).}$

#### Plane and point

Given a plane and a point in 3 dimensions some relevant questions are:

• What is distance from point to plane?
• What is the point within the plane at which the line through the point and normal to plane enters the plane?

Let the plane be defined as: ${\displaystyle Ax+By+Cz+D=0.}$

Any line normal to the plane has direction numbers ${\displaystyle (A,B,C).}$

Let the point be defined as point ${\displaystyle (x_{1},y_{1},z_{1}).}$

Let line1 be defined as the line through point ${\displaystyle (x_{1},y_{1},z_{1})}$ with direction numbers ${\displaystyle (A,B,C).}$

Ensure that the values ${\displaystyle (A,B,C)}$ are direction cosines.

Use the method above to calculate the point at which line1 enters the plane.

Distance from point to plane is K. Alternatively, distance from point to plane is ${\displaystyle Ax_{1}+By_{1}+Cz_{1}+D.}$

 For example: plane1 is defined as ${\displaystyle 9x+12y+8z-108=0.}$ Point ${\displaystyle P}$ has coordinates ${\displaystyle (13,20,5).}$ At what point ${\displaystyle P_{1}}$ does the normal through ${\displaystyle P}$ enter plane1? What is the distance from ${\displaystyle P}$ to ${\displaystyle P_{1}}$? Convert the equation of plane1 to direction cosines: ${\displaystyle {\frac {9}{17}}x+{\frac {12}{17}}y+{\frac {8}{17}}z-{\frac {108}{17}}=0.}$ Using ${\displaystyle K={\frac {-(+Ax_{1}+By_{1}+Cz_{1}+D)}{AA1+BB1+CC1}}.}$ ${\displaystyle K={\frac {-(+{\frac {9}{17}}x_{1}+{\frac {12}{17}}y_{1}+{\frac {8}{17}}z_{1}-{\frac {108}{17}})}{A^{2}+B^{2}+C^{2}}}}$ ${\displaystyle =-(+{\frac {9}{17}}13+{\frac {12}{17}}20+{\frac {8}{17}}5-{\frac {108}{17}})=-17.}$ Point ${\displaystyle P_{1}=(13-17{\frac {9}{17}},\ 20-17{\frac {12}{17}},\ 5-17{\frac {8}{17}})=(4,8,-3).}$ Distance from ${\displaystyle P}$ to ${\displaystyle P_{1}=-17.}$

#### Plane and plane

If two planes are parallel:

• they do not intersect.
• their normals are parallel.

The distance between two parallel planes ${\displaystyle A_{1}x+B_{1}y+C_{1}z+D_{1}=0}$ and ${\displaystyle A_{2}x+B_{2}y+C_{2}z+D_{2}=0}$ is ${\displaystyle D_{1}-D_{2}}$ provided that both planes are defined with direction cosines.

 Figure 1: Diagram illustrating line of intersection of 2 planes. Line ${\displaystyle CD}$ is line of intersection of 2 planes plane1, plane2. Line ${\displaystyle PS}$ is normal to plane1. Line ${\displaystyle PQ}$ is normal to plane2. Line ${\displaystyle CD}$ in plane1 is normal to line ${\displaystyle PS}$. Line ${\displaystyle CD}$ in plane2 is normal to line ${\displaystyle PQ}$. Line ${\displaystyle PR}$ is normal to both normals ${\displaystyle PQ,PS}$. Line ${\displaystyle CD}$ is normal to both normals ${\displaystyle PQ,PS}$. Therefore line ${\displaystyle PR}$ is parallel to line ${\displaystyle CD.}$ Intersection of 2 planes: The intersection of plane and plane is a line. The word "intersection" implies that the two planes are not parallel. If two planes intersect, the line normal to both normals is parallel to the line of intersection. As the intersection of two planes, the line cannot be defined by a neat algebraic equation like that of the plane. However the concept is useful because the intersection of line and plane or line and sphere can be solved with algebra. The line defined as the intersection of two planes can be defined with the familiar point and direction numbers:
 Figure 1: Diagram illustrating conversion from line defined by 2 planes to line defined as point and direction numbers. As point and direction numbers: Line ${\displaystyle PQ}$ is defined as the intersection of two planes plane1 and plane2. Using any point (the origin ${\displaystyle O}$ is convenient,) calculate the coordinates of point ${\displaystyle R}$ within plane2 and on the normal from point ${\displaystyle O}$ to plane2. Calculate the direction numbers of line ${\displaystyle PQ.}$ Calculate the direction numbers of line ${\displaystyle RS,}$ normal to both lines ${\displaystyle OR,PQ.}$ Point ${\displaystyle S}$ is the point at which line ${\displaystyle RS}$ enters plane1. Line PQ may be defined as point ${\displaystyle S}$ with direction numbers of line ${\displaystyle PQ.}$ Any point on line ${\displaystyle PQ}$ has distance ${\displaystyle 0}$ from both planes plane1 and plane2.

Algebraic method:

Let a line be defined by two planes:

${\displaystyle \pi _{1}:\ x+y+z+1=0}$

${\displaystyle \pi _{2}:\ x+2y+3z+4=0}$

From ${\displaystyle \pi _{1},\pi _{2}}$ derive other equations:

${\displaystyle \pi _{3}:\ y+2z+3=0\ \dots \ \pi _{2}-\pi _{1}}$

${\displaystyle \pi _{4}:\ x-z-2=0\ \dots \ 2\pi _{1}-\pi _{2}}$

${\displaystyle \pi _{5}:\ 2x+y-1=0\ \dots \ 3\pi _{1}-\pi _{2}}$ ${\displaystyle }$

The line may be defined by any 2 of ${\displaystyle \pi _{1},\ \pi _{2},\ \pi _{3},\ \pi _{4},\ \pi _{5}.}$

To find a point on the line, let ${\displaystyle x=0.}$

From ${\displaystyle \pi _{4}:\ z=-2}$

From ${\displaystyle \pi _{5}:\ y=1}$

Therefore ${\displaystyle (0,1,-2)}$ is a point on the line and the line has direction numbers ${\displaystyle (A,B,C)=(-1,2,-1).}$

Any point on the line has coordinates ${\displaystyle (x+KA,\ y+KB,\ z+KC)=(0+K(-1),\ 1+K(2),\ -2+K(-1)).}$

For proof:

Substitute these values into ${\displaystyle \pi _{1}:}$ ${\displaystyle x+y+z+1=(-K)+(1+2K)+(-2-K)+1=0.}$

Substitute these values into ${\displaystyle \pi _{2}:}$ ${\displaystyle x+2y+3z+4=(-K)+2(1+2K)+3(-2-K)+4=-K+2+4K-6-3K+4=0.}$

 Line ( (0,1,-2), [-1,2,-1], 'line' ) defined as intersection of 2 planes: As intersection of π1 and π3. As intersection of π1 and π4. As intersection of π1 and π5. As intersection of π2 and π3. As intersection of π2 and π4. As intersection of π2 and π5.

 Pencil of planes: Let a line be defined as the intersection of 2 planes, ${\displaystyle \pi _{1}:\ A_{1}x+B_{1}y+C_{1}z+D_{1}=0,\ \pi _{2}:\ A_{2}x+B_{2}y+C_{2}z+D_{2}=0.}$ Let a 3rd plane be defined as : ${\displaystyle \pi _{3}:\ \pi _{1}+k\pi _{2}=(A_{1}+kA_{2})x+(B_{1}+kB_{2})y+(C_{1}+kC_{2})z+(D_{1}+kD_{2})=0.}$ The 3 planes ${\displaystyle \pi _{1},\pi _{2},\pi _{3}}$ belong to a group of planes called a pencil of planes, every member of which contains a line common to all other members of the group, the line defined by the intersection of ${\displaystyle \pi _{1},\pi _{2}.}$ In the block above this was proved for a special case of ${\displaystyle \pi _{1},\pi _{2}.}$ The reader is invited to prove it for the general case.

Conversion to plane and plane:

If a line is defined as a point (x, y, z) and direction numbers [A, B, C], this section describes how to define the line as the intersection of 2 planes.

Let a line be defined as point (-2, 1, -2) and direction numbers [5, 1, 3].

Normals to the line have direction numbers [1, -5, 0], [0, 3, -1], [3, 0, -5].

Planes that contain the line are of format:

${\displaystyle 1x-5y+0z+D_{1}=0}$

${\displaystyle 0x+3y-1z+D_{2}=0}$

${\displaystyle 3x+0y-5z+D_{3}=0}$

All planes contain the point (-2, 1, -2) and the 3 equations above become:

${\displaystyle \pi _{1}:\ x-5y+7=0}$

${\displaystyle \pi _{2}:\ 3y-z-5=0}$

${\displaystyle \pi _{3}:\ 3x-5z-4=0}$

Any 2 of ${\displaystyle \pi _{1},\ \pi _{2},\ \pi _{3}}$ may be used to define the line.

Proof:

Any point on the line has coordinates (x, y, z) = (-2+5K, 1+1K, -2+3K).

Substitute these values of (x, y, z) into ${\displaystyle \pi _{1},\ \pi _{2},\ \pi _{3}:}$

x - 5y + 7 = -2+5K - 5(1+K) + 7 = -2+5k -5-5K + 7 = 0.

3y - z - 5 = 3(1+K) -(-2+3K) - 5 = 3+3K +2-3K - 5 = 0.

3x - 5z - 4 = 3(-2+5K) - 5(-2+3K) - 4 = -6+15K +10-15K - 4 = 0.

When K == -1, (x, y, z) = (-7, 0, -5). This point is used for reference in the gallery below.

Line ( (-2, 1, -2), [5, 1, 3], 'line' ) defined as intersection of 2 planes:

 As intersection of π1 and π2. As intersection of π1 and π3. As intersection of π2 and π3.

#### Reviewing:

Now that information about the plane is available to the reader, some of the concepts above can be reviewed and simplified.

##### Point and line
 Figure 1: Diagram illustrating line ${\displaystyle PQ,}$ point ${\displaystyle M}$ and line ${\displaystyle MN}$ normal from ${\displaystyle M}$ to ${\displaystyle PQ.}$${\displaystyle }$. Line ${\displaystyle PQ}$ and point ${\displaystyle M}$ are given. Calculate the coordinates of point ${\displaystyle N}$ on line ${\displaystyle PQ}$ so that line ${\displaystyle MN}$ is normal to line ${\displaystyle PQ.}$ Calculate the direction numbers of line ${\displaystyle PQ:\ (A,B,C).}$ Using ${\displaystyle (A,B,C)}$ and point ${\displaystyle M}$ calculate the plane normal to line ${\displaystyle PQ}$ and containing point ${\displaystyle M,}$ plane ${\displaystyle MNR.}$ Point ${\displaystyle N}$ is the point at which line ${\displaystyle PQ}$ enters plane ${\displaystyle MNR.}$
##### Points of closest approach
 Figure 1: Diagram illustrating points of closest approach of 2 skew lines ${\displaystyle PQ,RS.}$ Lines ${\displaystyle PQ,RS}$ are skew. Calculate point ${\displaystyle R}$ so that distance from point ${\displaystyle R}$ to line ${\displaystyle PQ}$ is minimum. Calculate direction numbers of line ${\displaystyle RT}$ normal to both ${\displaystyle PQ,RS.}$ Calculate direction numbers of line ${\displaystyle UV}$ normal to both ${\displaystyle PQ,RT.}$ Using direction numbers of line ${\displaystyle UV}$ and point ${\displaystyle P}$ or point ${\displaystyle Q,}$ calculate plane ${\displaystyle PQT.}$ Point ${\displaystyle R}$ is the point at which line ${\displaystyle SR}$ enters plane ${\displaystyle PQT.}$

#### Three planes

The intersection of 3 planes is a point. The word "intersection" implies that the three planes actually intersect.

Given three random planes, there are two situations that do not produce a point of intersection:

• If two of the planes are parallel.
• If the three planes form a "tent" or "awning."
 Figure 1: 3 planes that do not intersect at a point. In diagram to the right: No two planes are parallel. The line of intersection of any 2 planes is parallel to the third plane. For example, line ${\displaystyle CD}$ is the line of intersection of two planes plane1, plane2. Line ${\displaystyle CD}$ is parallel to plane3 and there is no point of intersection.
 Figure 1: Diagram showing 3 planes that intersect. Point of intersection: In the diagram line ${\displaystyle CD}$ is line of intersection of two planes plane1, plane2. Point ${\displaystyle E}$, the point of intersection of the 3 planes, is the point at which line ${\displaystyle CD}$ enters plane3. Similarly: Line ${\displaystyle EF}$ is common to plane1, plane3. Point ${\displaystyle E}$ is the point at which line ${\displaystyle FE}$ enters plane2. Line ${\displaystyle EG}$ is common to plane2, plane3. Point ${\displaystyle E}$ is the point at which line ${\displaystyle GE}$ enters plane1.

# The sphere

The sphere is the locus of a point that is always a fixed non-zero distance from a given fixed point.

Let the point be (d, e, f) and the distance be r.

Let (x, y, z) be any point on the surface of the sphere.

Then ${\displaystyle (x-d)^{2}+(y-e)^{2}+(z-f)^{2}=r^{2}}$

${\displaystyle x^{2}-2dx+d^{2}+y^{2}-2ey+e^{2}+z^{2}-2fz+f^{2}=r^{2}}$

${\displaystyle x^{2}+y^{2}+z^{2}-2dx-2ey-2fz+d^{2}+e^{2}+f^{2}-r^{2}=0}$

${\displaystyle x^{2}+y^{2}+z^{2}+Ax+By+Cz+D=0}$

where:

${\displaystyle A=-2d,}$ ${\displaystyle B=-2e,}$ ${\displaystyle C=-2f,}$ ${\displaystyle D=d^{2}+e^{2}+f^{2}-r^{2}.}$

Given a sphere defined as (point, radius, 'sphere'), the sphere may be defined as ((A, B, C, D), 'sphere') where it is understood that the coefficients of ${\displaystyle (x^{2},\ y^{2},\ z^{2})}$ are (1, 1, 1).

#### reversing the conversion

Given a sphere defined as ((A, B, C, D), 'sphere'), calculate point and radius.

${\displaystyle d={\frac {-A}{2}},}$ ${\displaystyle e={\frac {-B}{2}},}$ ${\displaystyle f={\frac {-C}{2}},}$ ${\displaystyle r={\sqrt {d^{2}+e^{2}+f^{2}-D}}.}$

point = (d, e, f) and radius = r.

 Two definitions of the sphere: ( (A, B, C, D), 'sphere' ), the algebraic definition of the sphere. ( (d, e, f), r, 'sphere' ), the trigonometric definition of the sphere.

#### examples

 Errors in definition: The tuple ((3,-2,7), 0, 'sphere') does not define a valid sphere because radius=0. The tuple ((-6, 4, -3, 70), 'sphere') does not define a valid sphere because the value ${\displaystyle (d^{2}+e^{2}+f^{2}-D)}$ is negative. Consequently the value ${\displaystyle r={\sqrt {d^{2}+e^{2}+f^{2}-D}}}$ is a complex number.
 Sphere at origin: If center of sphere is at origin, ${\displaystyle (d,e,f)=(0,0,0).}$ For example, a sphere at origin with radius ${\displaystyle 7}$ may be defined as: ( (0,0,0), 7, 'sphere' ) or ( (0,0,0,-49), 'sphere' ).

Point inside, on or outside sphere:

If distance from point to center ${\displaystyle point is inside sphere.

If distance from point to center ${\displaystyle ==r,}$ point is on surface of sphere.

If distance from point to center ${\displaystyle >r,}$ point is outside sphere.

 A sphere is defined as ( (1,7,-3), 13, 'sphere' ). 3 points are given: (3,4,3), (-3,19,0), (9,-5,6). For each point, determine position of point relative to surface of sphere. for point (3,4,3), distance from point to center is 7. Point is inside sphere. for point (-3,19,0), distance from point to center = 13 = r. Point is on surface of sphere. for point (9,-5,6), distance from point to center is 17. Point is outside sphere.

#### Sphere and line

Given a sphere and a line:

• The line may pierce the sphere in 2 places,
• The line may touch the sphere in 1 place, or
• The line may not touch or pierce the sphere. In other words, the distance to the line

from the center of the sphere is always greater than the radius of the sphere.

The possible point/s of intersection may be calculated by trigonometry or by algebra.

Given a sphere defined as ( (3,5,-2), 7, 'sphere' ) and a line defined as ( (4,-5,10), [1,4,-9], 'line' ) calculate the point/s of intersection, if any.

##### By trigonometry:

Let center of sphere ${\displaystyle P=(3,5,-2).}$ and point ${\displaystyle M=(4,-5,10).}$

Calculate coordinates of point ${\displaystyle N}$ on the line so that line ${\displaystyle PN}$ is normal to the given line.

${\displaystyle N=(5.5,1,-3.5).}$

Calculate length ${\displaystyle PN={\sqrt {24.5}}=4.949747468305833.}$ This length is less than the radius of the sphere. The line intersects the sphere in 2 points. Let these points be ${\displaystyle S,T.}$

Length ${\displaystyle NS=}$ length ${\displaystyle NT={\sqrt {(7)^{2}-24.5}}={\sqrt {24.5}}.}$${\displaystyle }$

Redefine the line so that direction numbers are direction cosines: ( (4,-5,10), [${\displaystyle {\frac {1}{\sqrt {98}}},{\frac {4}{\sqrt {98}}},{\frac {-9}{\sqrt {98}}}}$], 'line' )

Point ${\displaystyle S=(5.5+{\sqrt {24.5}}\cdot {\frac {1}{\sqrt {98}}},1+{\sqrt {24.5}}\cdot {\frac {4}{\sqrt {98}}},-3.5+{\sqrt {24.5}}\cdot {\frac {-9}{\sqrt {98}}})}$ = (6, 3, -8).

Point ${\displaystyle T=(5.5-{\sqrt {24.5}}\cdot {\frac {1}{\sqrt {98}}},1-{\sqrt {24.5}}\cdot {\frac {4}{\sqrt {98}}},-3.5-{\sqrt {24.5}}\cdot {\frac {-9}{\sqrt {98}}})}$ = (5, -1, 1).

 Proof: Distance from point S to center ${\displaystyle ={\sqrt {(6-3)^{2}+(3-5)^{2}+(-8-(-2))^{2}}}=7=}$ radius. Distance from point T to center ${\displaystyle ={\sqrt {(5-3)^{2}+(-1-5)^{2}+(1-(-2))^{2}}}=7=}$ radius. Direction numbers of line SM = [6-4, 3-(-5), -8-10] = [2, 8, -18]. Direction numbers of line TM = [5-4, -1-(-5), 1-10] = [1, 4, -9]. Lines SM, TM and original line are all parallel and all pass through point M. Points S, T are on the original line.

##### By extending line with constant K
 Let the line be defined as point and direction numbers: ( (s,t,u), [E,F,G], 'line' ). Let the point at which the line enters the sphere be: ( s+KE, t+KF, u+KG ). These values of ${\displaystyle (x,y,z)}$ satisfy the equation of the sphere: ${\displaystyle x^{2}+y^{2}+z^{2}+Ax+By+Cz+D=0.}$ Therefore: ${\displaystyle (s+KE)^{2}+(t+KF)^{2}+(u+KG)^{2}+A(s+KE)+B(t+KF)+C(u+KG)+D=0}$ Expand and the result is: ${\displaystyle (E^{2}+F^{2}+G^{2})K^{2}+(AE+BF+CG+2Es+2Ft+2Gu)K+As+Bt+Cu+D+s^{2}+t^{2}+u^{2}=0.}$ This is a quadratic equation in ${\displaystyle K:}$ ${\displaystyle A_{0}K^{2}+B_{0}K+C_{0}=0}$ where: ${\displaystyle A_{0}=E^{2}+F^{2}+G^{2}}$ ${\displaystyle B_{0}=AE+BF+CG+2Es+2Ft+2Gu}$ and ${\displaystyle C_{0}=As+Bt+Cu+D+s^{2}+t^{2}+u^{2}.}$ # python code d,e,f = 3,5,-2 r = 7 A = -2*d B = -2*e C = -2*f D = d*d + e*e + f*f - r*r s,t,u = 4,-5,10 E,F,G = 1,4,-9 A0 = E*E + F*F + G*G B0 = A*E + B*F + C*G + 2*E*s + 2*F*t + 2*G*u C0 = A*s + B*t + C*u + D + s*s + t*t + u*u disc = B0*B0 - 4*A0*C0 root = disc**.5 v1 = (-B0 + root)/(2*A0) v2 = (-B0 - root)/(2*A0) print ('values of K = ',v1,', ',v2,sep='') L1 = [] for K in (v1,v2) : L1 += [( s+K*E, t+K*F, u+K*G )] print ('points of intersection =', L1)  values of K = 2.0, 1.0 points of intersection = [(6.0, 3.0, -8.0), (5.0, -1.0, 1.0)] 
##### By algebra:

Let the sphere be defined as ( (${\displaystyle A_{1},B_{1},C_{1},D_{1}}$), 'sphere' ).

Let the line be defined as the intersection of 2 planes ( (${\displaystyle A_{2},B_{2},C_{2},D_{2}}$), 'plane' ) and ( (${\displaystyle A_{3},B_{3},C_{3},D_{3}}$), 'plane' ).

The relevant equations are :

${\displaystyle x^{2}+y^{2}+z^{2}+A_{1}x+B_{1}y+C_{1}z+D_{1}=0\ \dots \ (1)}$

${\displaystyle A_{2}x+B_{2}y+C_{2}z+D_{2}=0\ \dots \ (2)}$

${\displaystyle A_{3}x+B_{3}y+C_{3}z+D_{3}=0\ \dots \ (3)}$

The point/s of intersection are the solution/s of these 3 equations for ${\displaystyle x,y,z.}$

The value/s of ${\displaystyle x}$ are the solution/s of the quadratic equation ${\displaystyle c_{2}x^{2}+c_{1}x+c_{0}=0.}$

# python code
def sphereAndLine(input) :
row1,row2,row3 = input
A1,B1,C1,D1 = row1
A2,B2,C2,D2 = row2
A3,B3,C3,D3 = row3

c2 = (
- (A2)*(A2)*(B3)*(B3) - (A2)*(A2)*(C3)*(C3) + 2*(A2)*(B2)*(A3)*(B3) + 2*(A2)*(C2)*(A3)*(C3)
- (B2)*(B2)*(A3)*(A3) - (B2)*(B2)*(C3)*(C3) + 2*(B2)*(C2)*(B3)*(C3) - (C2)*(C2)*(A3)*(A3)
- (C2)*(C2)*(B3)*(B3)
)

c1 = (
- (A1)*(B2)*(B2)*(C3)*(C3) + 2*(A1)*(B2)*(C2)*(B3)*(C3) - (A1)*(C2)*(C2)*(B3)*(B3)
+ (B1)*(A2)*(B2)*(C3)*(C3) - (B1)*(A2)*(C2)*(B3)*(C3) - (B1)*(B2)*(C2)*(A3)*(C3)
+ (B1)*(C2)*(C2)*(A3)*(B3) - (C1)*(A2)*(B2)*(B3)*(C3) + (C1)*(A2)*(C2)*(B3)*(B3)
+ (C1)*(B2)*(B2)*(A3)*(C3) - (C1)*(B2)*(C2)*(A3)*(B3) + 2*(A2)*(B2)*(B3)*(D3)
+ 2*(A2)*(C2)*(C3)*(D3) - 2*(A2)*(D2)*(B3)*(B3) - 2*(A2)*(D2)*(C3)*(C3)
- 2*(B2)*(B2)*(A3)*(D3) + 2*(B2)*(D2)*(A3)*(B3) - 2*(C2)*(C2)*(A3)*(D3)
+ 2*(C2)*(D2)*(A3)*(C3)
)

c0 = (
- (B1)*(B2)*(C2)*(C3)*(D3) + (B1)*(B2)*(D2)*(C3)*(C3) + (B1)*(C2)*(C2)*(B3)*(D3)
- (B1)*(C2)*(D2)*(B3)*(C3) + (C1)*(B2)*(B2)*(C3)*(D3) - (C1)*(B2)*(C2)*(B3)*(D3)
- (C1)*(B2)*(D2)*(B3)*(C3) + (C1)*(C2)*(D2)*(B3)*(B3) - (D1)*(B2)*(B2)*(C3)*(C3)
+ 2*(D1)*(B2)*(C2)*(B3)*(C3) - (D1)*(C2)*(C2)*(B3)*(B3) - (B2)*(B2)*(D3)*(D3)
+ 2*(B2)*(D2)*(B3)*(D3) - (C2)*(C2)*(D3)*(D3) + 2*(C2)*(D2)*(C3)*(D3)
- (D2)*(D2)*(B3)*(B3) - (D2)*(D2)*(C3)*(C3)
)

listOf_xs = []
disc = c1*c1 - 4*c2*c0
if disc < 0 :
print ('sphereAndLine(input) : disc < 0.')
elif disc == 0 :
x = -c1/(2*c2)
listOf_xs += [x]
else :
root = disc**0.5
x1 = (-c1 + root)/(2*c2)
x2 = (-c1 - root)/(2*c2)
listOf_xs += [x1,x2]

output = []
for x in listOf_xs :
y = -(+ (A2)*(C3)*(x) - (C2)*(A3)*(x) - (C2)*(D3) + (D2)*(C3))/(+ (B2)*(C3) - (C2)*(B3))
z = -(+ (A3)*(x) + (B3)*(y) + (D3))/(+ (C3)) # Choose C3 so that C3 is non-zero.
output += [(x,y,z)]

print ('sphereAndLine(input) : output =', output)
return output

d,e,f,r = 3,5,-2,7
A1,B1,C1,D1 = -2*d, -2*e, -2*f, d*d + e*e + f*f - r*r # The sphere.

DN1 = [ 0, 9, 4 ] #
DN2 = [ 9, 0, 1 ] # These 3 groups of direction numbers are all normal to [ 1,4,-9 ]
DN3 = [ 4, -1, 0 ]#

# point M = (4,-5,10)
Mx,My,Mz = 4,-5,10

A2,B2,C2 = DN3
A3,B3,C3 = DN1 # Choose C3 so that C3 is non-zero.

D2 = -( A2*Mx + B2*My + C2*Mz )
D3 = -( A3*Mx + B3*My + C3*Mz )

output = sphereAndLine(
(
(A1,B1,C1,D1) , # The sphere.
(A2,B2,C2,D2) , ## These 2 groups are the 2 planes that define the line.
(A3,B3,C3,D3) , ##
)
)

print (output)

[(5.0, -1.0, 1.0), (6.0, 3.0, -8.0)] # The 2 points of intersection.

###### Exchange rows
 Rows 2 and 3 may be exchanged, one for the other: output = sphereAndLine( ( (A1,B1,C1,D1) , # The sphere. (A3,B3,C3,D3) , ## (A2,B2,C2,D2) , ## These 2 groups are the 2 planes that define the line. ) ) print (output)  Traceback (most recent call last): File "./3d.tmp", line 1124, in (A2,B2,C2,D2) , ## These 2 groups are the 2 planes that define the line. File "./3d.tmp", line 1097, in sphereAndLine z = -(+ (A3)*(x) + (B3)*(y) + (D3))/(+ (C3)) # Choose C3 so that C3 is non-zero. ZeroDivisionError: float division by zero 
###### Exchange columns
 If data supplied to sphereAndLine produces an error (as above), try exchanging two columns: output = sphereAndLine( ( (A1,C1,B1,D1) , # The sphere. (A3,C3,B3,D3) , ## (A2,C2,B2,D2) , ## These 2 groups are the 2 planes that define the line. ) ) print (output)  [(5.0, 1.0, -1.0), (6.0, -8.0, 3.0)]  Exchange appropriate columns in output to produce correct values: output = [ (v[0], v[2], v[1]) for v in output ] print (output)  [(5.0, -1.0, 1.0), (6.0, 3.0, -8.0)] 

#### Defined as 4 points

If 4 unique points on surface of sphere are known, the center and radius may be calculated.

From above, equation of sphere is: ${\displaystyle x^{2}+y^{2}+z^{2}+Ax+By+Cz+D=0}$

When ${\displaystyle x,y,z}$ are known and ${\displaystyle A,B,C,D}$ are unknown the above equation becomes: ${\displaystyle xA+yB+Cz+(1)D+x^{2}+y^{2}+z^{2}=0\ \dots \ (1)}$

With four points provided, equation ${\displaystyle (1)}$ may be used to construct a system of 4 simultaneous equations that, when solved, provide the values ${\displaystyle (A,B,C,D).}$

For example:

 # python code point1 = (16,11,29) point2 = (17,-5,20) point3 = (25,3,14) point4 = (10,19,13) t1 = ( point1, point2, point3, point4 ) L1 = [] for t in t1 : x,y,z = t L1 += [[x, y, z, 1, x*x + y*y + z*z]] for v in L1 : x,y,z,one,constant = v print (v, '# {}A + {}B + {}C + {}D + {} = 0'.format(x,y,z,one,constant)) 
 [16, 11, 29, 1, 1218] # 16A + 11B + 29C + 1D + 1218 = 0 [17, -5, 20, 1, 714] # 17A + -5B + 20C + 1D + 714 = 0 [25, 3, 14, 1, 830] # 25A + 3B + 14C + 1D + 830 = 0 [10, 19, 13, 1, 630] # 10A + 19B + 13C + 1D + 630 = 0

The above matrix of 4 rows by 5 columns is input to function solveMbyN(). See Solving_M_by_(M+1)

 # python code A,B,C,D = output = solveMbyN(L1) print ('(A, B, C, D) =',output) d = -A/2 e = -B/2 f = -C/2 r = (d**2 + e**2 + f**2 - D)**.5 print ('center = ({}, {}, {}), radius = {}'.format(d,e,f,r)) for point in t1 : x,y,z = point distance = ((x-d)**2 + (y-e)**2 + (z-f)**2)**0.5 print ('for point',point,'distance from center ==',r,':',distance==r) 
 (A, B, C, D) = (-26.0, -14.0, -34.0, 338.0) center = (13.0, 7.0, 17.0), radius = 13.0 for point (16, 11, 29) distance from center == 13.0 : True for point (17, -5, 20) distance from center == 13.0 : True for point (25, 3, 14) distance from center == 13.0 : True for point (10, 19, 13) distance from center == 13.0 : True

##### Center as intersection of 3 planes
 Let center of sphere be ${\displaystyle (d,e,f).}$ Let 4 points on surface of sphere be ${\displaystyle (a,b,c),\ (g,h,j),\ (k,l,m),\ (n,p,q).}$ ${\displaystyle (d-a)^{2}+(e-b)^{2}+(f-c)^{2}=r^{2}}$ ${\displaystyle (d-g)^{2}+(e-h)^{2}+(f-j)^{2}=r^{2}}$ ${\displaystyle (d-k)^{2}+(e-l)^{2}+(f-m)^{2}=r^{2}}$ ${\displaystyle (d-n)^{2}+(e-p)^{2}+(f-q)^{2}=r^{2}}$ ${\displaystyle (d-a)^{2}+(e-b)^{2}+(f-c)^{2}=(d-g)^{2}+(e-h)^{2}+(f-j)^{2}}$ or ${\displaystyle (d-a)^{2}+(e-b)^{2}+(f-c)^{2}-((d-g)^{2}+(e-h)^{2}+(f-j)^{2})=0\ \dots \ (1)}$ ${\displaystyle (d-a)^{2}+(e-b)^{2}+(f-c)^{2}-((d-k)^{2}+(e-l)^{2}+(f-m)^{2})=0\ \dots \ (2)}$ ${\displaystyle (d-a)^{2}+(e-b)^{2}+(f-c)^{2}-((d-n)^{2}+(e-p)^{2}+(f-q)^{2})=0\ \dots \ (3)}$ When expanded, equation ${\displaystyle (1)}$ above has the form ${\displaystyle Ad+Be+Cf+D=0.}$ This is the equation of the plane normal to line ${\displaystyle ((a,b,c),\ (g,h,j),}$ 'line'${\displaystyle )}$ and containing the point midway between points ${\displaystyle (a,b,c),\ (g,h,j).}$ # python code: point1 = a,b,c = (16,11,29) point2 = g,h,j = (17,-5,20) point3 = k,l,m = (25,3,14) point4 = n,p,q = (10,19,13) def plane (point1, point2) : a,b,c = point1 d,e,f = point2 x,y,z = (a+d)/2, (b+e)/2, (c+f)/2 A,B,C = a-d, b-e, c-f if A == B == C == 0 : print ('plane (point1, point2) : distance between point1 and point2 must be non-zero.') return None ''' Ax + By + Cz + D = 0 ''' D = -( A*x + B*y + C*z ) return (A,B,C,D) input = [] for point in (point2, point3, point4) : A,B,C,D = plane(point1,point) input.append( (A,B,C,D) ) print (input) output = solve3by4(input) print (output)  [ (-1, 16, 9, -252.0), (-9, 8, 15, -194.0), (6, -8, 16, -294.0) ] (13.0, 7.0, 17.0) # Coordinates of center of sphere.  For function solve3by4(input), see "Solving_3_by_4"

# Third line

Given:

• line1 has direction numbers [A1, B1, C1].
• line2 has direction numbers [A2, B2, C2].
• cos1 is cosine of angle between line1 and line3.
• cos2 is cosine of angle between line2 and line3.

Calculate direction numbers of line3.

 Figure 1: Diagram illustrating calculation of direction numbers of line3. This is a plan view of a 3 dimensional image. Point P is above plane of line OM and line ON. ${\displaystyle \theta _{1}+\theta _{2}\geq \angle MON.}$ In the diagram: line1 has direction cosines ${\displaystyle [a_{1},b_{1},c_{1}].}$ line2 has direction cosines ${\displaystyle [a_{2},b_{2},c_{2}].}$ ${\displaystyle \theta _{1}}$ is angle between line1 and line3. ${\displaystyle \theta _{2}}$ is angle between line2 and line3. cos1 ${\displaystyle =\cos(\theta _{1}).}$ cos2 ${\displaystyle =\cos(\theta _{2}).}$ Length OM = cos1. Length ON = cos2. Point M has coordinates (cos1*a1, cos1*b1, cos1*c1) Point N has coordinates (cos2*a2, cos2*b2, cos2*c2) plane1 is normal to line1 and contains point M. plane2 is normal to line2 and contains point N. Point P is on line of intersection of plane1 and plane2, and point P is distance 1 from point O. Point P may have no value. ${\displaystyle (\theta _{1}+\theta _{2}<\angle MON)}$ Point P may have 1 value. ${\displaystyle (\theta _{1}+\theta _{2}=\angle MON)}$ Point P may have 2 values. ${\displaystyle (\theta _{1}+\theta _{2}>\angle MON)}$
 # python code def dcOfLine3 (dn1, dn2, cos1, cos2) : ''' direction cosines of line 3 output = dcOfLine3 ([A1,B1,C1], [A2,B2,C2], cos1, cos2) output may be: [] no solution [[a1,b1,c1]] 1 group of direction cosines [[a1,b1,c1], [a2,b2,c2]] 2 groups of direction cosines ''' A1,B1,C1 = dn1 A2,B2,C2 = dn2 ''' A1 = B3C2 - C3B2 B1 = C3A2 - A3C2 C1 = A3B2 - B3A2 ''' # Direction numbers of the normal: An = B1*C2 - C1*B2 Bn = C1*A2 - A1*C2 Cn = A1*B2 - B1*A2 if An == Bn == Cn == 0 : print ('dcOfLine3 (dn1, dn2, cos1, cos2) : dn1 and dn2 are parallel.') return None # Convert direction numbers to direction cosines: K1 = (A1*A1 + B1*B1 + C1*C1)**.5 a1,b1,c1 = A1/K1, B1/K1, C1/K1 K2 = (A2*A2 + B2*B2 + C2*C2)**.5 a2,b2,c2 = A2/K2, B2/K2, C2/K2 c0 = a1*a2 + b1*b2 + c1*c2 print ('cos angle MON =',c0) # Coordinates of point M: M = ( cos1*a1, cos1*b1, cos1*c1 ) # plane1 has direction numbers [a1,b1,c1] and it contains point M. # a1 x + b1 y + c1 z + d1 = 0 d1 = - ( a1*M[0] + b1*M[1] + c1*M[2] ) # plane1: a1 x + b1 y + c1 z + d1 = 0 print ('plane1: ({})x + ({})y + ({})z + ({}) = 0'.format( a1,b1,c1,d1)) plane1 = ( a1,b1,c1,d1) # Coordinates of point N: N = ( cos2*a2, cos2*b2, cos2*c2 ) # plane2 has direction numbers [a2,b2,c2] and it contains point N. # a2 x + b2 y + c2 z + d2 = 0 d2 = - ( a2*N[0] + b2*N[1] + c2*N[2] ) # plane2: a2 x + b2 y + c2 z + d2 = 0 print ('plane2: ({})x + ({})y + ({})z + ({}) = 0'.format( a2,b2,c2,d2)) plane2 = ( a2,b2,c2,d2) # Points P1,P2 are the intersection of line and sphere. # Line is intersecton of 2 planes, plane1 and plane2, and # sphere has center origin and radius 1. plane3 = (An, Bn, Cn, 0) # The plane of OM and ON. print ('plane3: ({})x + ({})y + ({})z + ({}) = 0'.format( plane3[0], plane3[1], plane3[2], plane3[3] )) Pbase = x,y,z = solve3by4 ((plane1, plane2, plane3)) distanceFromOriginToPbase = (x**2 + y**2 + z**2)**.5 print ('distanceFromOriginToPbase =', distanceFromOriginToPbase) L1 = [] if distanceFromOriginToPbase > 1 : print ('dcOfLine3 (dn1, dn2, cos1, cos2) : distanceFromOriginToPbase > 1 :', distanceFromOriginToPbase) elif distanceFromOriginToPbase == 1 : L1 += [Pbase] else : distanceFromPbaseToP = (1 - distanceFromOriginToPbase**2)**.5 print ('distanceFromPbaseToP =', distanceFromPbaseToP) Kn = (An**2 + Bn**2 + Cn**2)**.5 an,bn,cn = An/Kn, Bn/Kn, Cn/Kn P1 = ( x+an*distanceFromPbaseToP, y+bn*distanceFromPbaseToP, z+cn*distanceFromPbaseToP, ) L1 += [ P1 ] P2 = ( x-an*distanceFromPbaseToP, y-bn*distanceFromPbaseToP, z-cn*distanceFromPbaseToP, ) L1 += [ P2 ] L2 = [] for dn in L1 : a,b,c = dn K = (a*a + b*b + c*c)**.5 L2 += [[a/K, b/K, c/K]] if len(L2) < 2 : print ('''output =''', L2) else : str1 = ''' output = [{}, {}] '''.format(L2[0], L2[1]) print (str1) return L2  For function solve3by4(input), see "Solving_3_by_4"
 Figure 2: Diagram illustrating calculation of direction numbers of line3. Length ${\displaystyle OM=\cos 1=0.3.}$ Length ${\displaystyle ON=\cos 2=0.4.}$ plane1 is normal to line1 at point M. plane2 is normal to line2 at point N. plane3 contains line1 and line2. Point Pbase is at intersection of plane1, plane2 and plane3. Line Pbase-P1 is line of intersection of plane1 and plane2. Length ${\displaystyle OP_{1}=1.}$ Coordinates of point ${\displaystyle P_{1}}$ are direction numbers of line3. Point ${\displaystyle P_{2}}$ is not visible in this view. An example: A1,B1,C1 = -2,1,1 A2,B2,C2 = 1,1,0 cos1,cos2 = 0.3,0.4 output = dcOfLine3 ([A1,B1,C1], [A2,B2,C2], cos1, cos2) # Convert to direction cosines. a1,b1,c1 = [ v/K for K in ((A1**2 + B1**2 + C1**2)**.5,) for v in [A1,B1,C1] ] a2,b2,c2 = [ v/K for K in ((A2**2 + B2**2 + C2**2)**.5,) for v in [A2,B2,C2] ] if output : for dn in output : a3,b3,c3 = dn c1_ = a1*a3 + b1*b3 + c1*c3 c2_ = a2*a3 + b2*b3 + c2*c3 print() print('for',dn) print (c1_,c2_)  cos angle MON = -0.2886751345948129 plane1: (-0.8164965809277261)x + (0.4082482904638631)y + (0.4082482904638631)z + (-0.30000000000000004) = 0 plane2: (0.7071067811865475)x + (0.7071067811865475)y + (0.0)z + (-0.39999999999999997) = 0 plane3: (-1)x + (1)y + (-3)z + (0) = 0 distanceFromOriginToPbase = 0.5901759666430051 distanceFromPbaseToP = 0.8072746300962236 output = [[-0.23811146541000267, 0.8037968903592405, -0.5451728983442925], [0.2486934529176556, 0.3169919720315823, 0.9152418566386824]] for [-0.23811146541000267, 0.8037968903592405, -0.5451728983442925] 0.30000000000000004 0.3999999999999998 # Expecting cos1 = 0.3 and cos2 = 0.4. for [0.2486934529176556, 0.3169919720315823, 0.9152418566386824] 0.3000000000000001 0.3999999999999999 # Expecting cos1 = 0.3 and cos2 = 0.4. 

## Rotate line through given angle

Given:

• plane1 defined as ((A,B,C,D), 'plane')
• line1 wholly within plane1 and with direction numbers [A1,B1,C1]
• angle ${\displaystyle \theta }$

Calculate:

• direction numbers of line2 wholly within plane1 and making angle ${\displaystyle \theta }$ with line1.

This is a special case of function dcOfLine3 above in which line2 makes the angle of ${\displaystyle 90^{\circ }}$ with the normal to the plane, and angle ${\displaystyle \theta }$ with line1.

# python code.

def rotateLine(ABCD, A1B1C1, cosθ, flag=None) :
'''
ABCD contains the direction numbers A,B,C of the normal to the plane.
A1B1C1 contains [A1,B1,C1], direction numbers of line1.
cosθ is cosine of angle between line1 and line2.
if flag is non-zero, cosθ is an angle in degrees and cosθ is to be calculated.
direction_numbers1,direction_numbers2 = rotateLine(ABCD, A1B1C1, cosθ, flag=None)
'''
rotateLine__ = 'rotateLine(ABCD, A1B1C1, cosθ, flag=None) : '
if flag :
angleInDegrees = cosθ

A,B,C,D = ABCD
A1,B1,C1 = A1B1C1
# Verify that direction numbers are normal.
sum = A*A1 + B*B1 + C*C1
# If sum is close to zero, make it zero.
sum = (sum,0)[abs(sum) < 1e-14]
if sum :
print ( rotateLine__ + 'error 1. direction numbers not normal, sum =',sum)
return None
#output = dcOfLine3 ([A1,B1,C1], [A2,B2,C2], cos1, cos2)
output = dcOfLine3 ([A1,B1,C1], [A,B,C], cosθ, 0)
# cosθ is associated with line1 [A1,B1,C1]
# 0 = cos(90) is asociated with normal to plane [A,B,C]
return output


A simple example:

ABCD = A,B,C,D = 0,0,1,0 # Plane of x and y.

A1B1C1 = A1,B1,C1 = 0,1,0 # Y axis

output = rotateLine(ABCD, A1B1C1, 45, 1) # 45 degrees.
print (output)

[[0.7071067811865475, 0.7071067811865476, 0.0], # 45 degrees to right of Y axis.
[-0.7071067811865475, 0.7071067811865476, 0.0]]  # 45 degrees to left of Y axis.


### Spokes of a wheel

 Given: plane1 defined as ((A,B,C,D), 'plane') line1 wholly within plane1 and with direction numbers [A1,B1,C1] Rotate line1 5 times through ${\displaystyle 72^{\circ },}$ wholly within plane1. # python code ABCD = A,B,C,D = 5,-7 ,2,11 A1B1C1 = A1,B1,C1 = 8, 2, -13 a1b1c1 = [ v/K for K in [ (A1**2 + B1**2 + C1**2)**.5 ] for v in A1B1C1 ] print ('initial a1b1c1 =',a1b1c1) for count in range (1,6) : output = rotateLine(ABCD, a1b1c1, 72, 1) a1b1c1 = output[1] print ('after rotation #',count,', a1b1c1 =',a1b1c1,sep='' )  initial a1b1c1 = [0.5196558419693047, 0.12991396049232617, -0.8444407432001202] after rotation #1, a1b1c1 =[0.7691434680719993, 0.6067368804016525, 0.2007204112257853] after rotation #2, a1b1c1 =[-0.04429903647583955, 0.245070053823975, 0.9684927795735114] after rotation #3, a1b1c1 =[-0.7965217782829397, -0.4552752575136696, 0.39784104440950446] after rotation #4, a1b1c1 =[-0.4479784952825248, -0.5264456372042838, -0.7226134920086813] after rotation #5, a1b1c1 =[0.5196558419693048, 0.1299139604923262, -0.8444407432001202]  5 times ${\displaystyle 72^{\circ }=360^{\circ }.}$ After 5 rotations the direction cosines ${\displaystyle [a_{1},b_{1},c_{1}]}$ match their initial values.

## By algebra

 Ensure that all values ${\displaystyle [a_{1},b_{1},c_{1}],\ [a_{2},b_{2},c_{2}]}$ are direction cosines. The relevant equations are: ${\displaystyle a_{1}\cdot a_{3}+b_{1}\cdot b_{3}+c_{1}\cdot c_{3}}$ = cos1 ${\displaystyle \dots \ (1)}$ ${\displaystyle a_{2}\cdot a_{3}+b_{2}\cdot b_{3}+c_{2}\cdot c_{3}}$