Introduction to Cartesian Geometry

From Wikiversity
Jump to navigation Jump to search

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[edit | edit source]

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[edit | edit source]

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[edit | edit source]

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.

Fig 1 - Cartesian coordinate system with the origin marked in purple


3d Coordinate Geometry[edit | edit source]

The coordinate system in two dimensions uses values containing width and depth expressed as values of and/or

Coordinate geometry in three dimensions adds the dimension of height, usually expressed as a value of The axes of and usually represent the horizontal plane. The axis is thus vertical or normal to the plane of and

In three dimensional space a point is shown as where the 3 values locate the point relative to the origin along each of the axes respectively. The value is valid, usually the origin.

Within this page the values are all real numbers.

Examples of points in 3 dimensional space.[edit | edit source]

Points of 1 dimension

Figure 1: Diagram showing axes of 3d Coordinate Geometry.

Each of the points in the diagram has exactly one dimension.

The point has only the dimension of width. It is on the axis.

The point has only the dimension of depth. It is on the axis.

The point has only the dimension of height. It is on the axis.


Points of 2 dimensions

Figure 2: Diagram showing axes of 3d Coordinate Geometry.

Each of the points in the diagram has exactly two dimensions.

The point has the dimensions of width and depth, no height.

The point has the dimensions of depth and height, no width.

The point has the dimensions of width and height, no depth.

Points of 3 dimensions

Figure 3: Diagram showing axes of 3d Coordinate Geometry.

Each of the points in the diagram has three dimensions.

Distance between 2 points[edit | edit source]

Figure 1: Diagram illustrating distance between two points.
Length
Length
Length

Consider the point What is the distance from point to the origin?

Point is the projection of on to the plane of

Calculate length

Then length

Length In this case

The general case:

For two points and

the distance

Length is the special case in which

The distance may be in which case and are the same point.

The line in 3 dimensions[edit | edit source]

as 2 points[edit | edit source]

In the example above line passes through the points and

The line may be defined by the two points and provided that the length is non-zero.

Line

There are other ways to define a line. Add a descriptor to avoid confusion:

Line 'points' where:

and

Line 'points'

Similarly:

line 'points'

line 'points'

line 'points' and

line 'points'

as point and 3 direction numbers[edit | edit source]

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

Line above is defined by 2 points and

The direction numbers of line

A line may be defined as where:

is a known point on the line, and

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 may be defined as 'p&dn'

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

On line 'p&dn' any second point and distance from to

It would be convenient if the value would

If the values are the direction cosines of the line.

To convert direction numbers to direction cosines divide each direction number by

If are the direction cosines of the line, any second point on the line exactly units from has coordinates

While point is valid, direction numbers are not valid. For the group of direction numbers to be valid, at least one of must be non-zero.

Angle between two lines[edit | edit source]

Figure 1: Diagram illustrating calculation of where is angle between 2 lines in 3 dimensional space.

In the diagram line has direction numbers Point has coordinates

Line has direction numbers and point has coordinates

Length

Length

Length

By the cosine rule

If all values are direction cosines,

If the lines are normal.

If or the lines are parallel.

Angle between line and each axis:

Let a line have direction cosines

Let axis have direction cosines

Let be angle between line and axis.

Hence the expression direction cosine. is the cosine of the angle between line and axis.

Similarly is cosine of angle between line and axis and is cosine of angle between line and axis.

Parallel lines:

Let one line have direction numbers and a second line have

and the lines are parallel.

Similarly, if the second line has direction numbers and the lines are parallel.

To verify that two lines are not parallel, check that does not equal

If one line has direction numbers and the second line has direction numbers then:

The values 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[edit | edit source]

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

Let the 2 lines have direction numbers

Then:

and

If divisor

If divisor

Provided that all inputs are valid, then at least one of must be non-zero and at least one of or or must be valid.

From above:

Values of that satisfy this condition are:

Proof:

Angle between and

Therefore the two groups of direction numbers are normal.

Similarly it can be shown that the two groups of direction numbers and are normal.

The line normal to and has direction numbers:

Parallel input:

Let

Then

If the two groups of direction numbers are parallel,

Normal to 1 line[edit | edit source]

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[edit | edit source]

Figure 1: Diagram illustrating normal from point to line

In the diagram line and point are well defined and

Point is on line

Line is perpendicular to line

Calculate the coordinates of point and length

Initial considerations:

  • Points may be the same point in which case points are the same point and lengths
  • Point may be on line in which case lengths and length
  • line may be perpendicular to line in which case lengths and length

Calculate direction cosines of line :

Calculate direction cosines of line :

Calculate

Calculate length

Calculate length

Let point have coordinates

Then point lengthlengthlength

Calculate length

By extending line PQ with constant K[edit | edit source]

Let line be defined as ( (p,q,r), [A, B, C], 'line' ).

Let point have coordinates ( p+KA, q+KB, r+KC ).

Let point have coordinates ( s, t, u ).

Then line has direction numbers [ p+KA-s, q+KB-t, r+KC-u ].

Lines are normal. Therefore:

and

Use this value of to calculate the coordinates of point and the direction numbers of line

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 be a point on a line parallel to line

Distance between the two lines is length

Points of closest approach[edit | edit source]

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 on line1 and point on line2 so that line is normal to line2 and line is normal to line1.

It's possible that length may be zero in which case points are the same point and the lines intersect.


Let line1 be defined as point with direction numbers

Let line2 be defined as point with direction numbers

Calculate the direction numbers of the normal:


Relative to line1 point

and point

Relative to line2 point


Therefore:

or:

This is a system of three equations with three unknowns:

If are direction cosines, length


Example 1:

Figure 1: Diagram illustrating points of closest approach of 2 lines in 3 dimensions.
line1 is defined by points
line2 is defined by points
Point on line1
Point on line2
Line is normal to line2.
Line 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, and the lines intersect at point

The plane in 3 dimensions[edit | edit source]

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 have coordinates

Let point have coordinates

Distance must be non-zero.

Let point have coordinates

Then length = length

This equation has the form where:


Normal to the plane:[edit | edit source]

Line is normal to the plane and it has direction numbers or

When a plane is defined as the line normal to the plane has direction numbers

Distances:[edit | edit source]

Distance

Distance from each point to plane


Consider the expression Substitute or for

Let

Then = distance from point to plane.


Similarly, = distance from point to plane with opposite sign.


When the values are all direction cosines, the distance from point to plane 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:[edit | edit source]

Think of the normal to the plane. The normal has direction numbers 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 is parallel to both axes.

The plane is parallel to both axes.

The plane is parallel to both axes.

The plane is parallel to the axis.

The plane is parallel to the axis.

The plane is parallel to the axis.

The plane is not parallel to any axis.

Various planes in 3 dimensions[edit | edit source]

Defining the plane[edit | edit source]

By definition above[edit | edit source]

Given two points as above, the equation 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[edit | edit source]

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

The equation of the plane is where

By three points[edit | edit source]

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[edit | edit source]

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:

Let the line be defined as point and direction numbers

The point at which the line enters the plane is:

These points satisfy the equation of the plane:

The divisor is the top line of the equation for angle between two lines.

If the angle between line and normal to the plane is and line is parallel to plane.

The point of intersection is:

If the direction numbers are all direction cosines, distance from point to plane along the line is

Figure 1: Diagram illustrating point of intersection of line and plane at point

For example:

In the diagram point has coordinates

Line through has direction numbers

Point is within the plane

What are the coordinates of point ?

With as direction cosines the coefficients of the plane

As direction cosines the direction numbers of the line

Using

The point of intersection

Provided that all values are direction cosines,

length and

If the value of is desired,

Plane and point[edit | edit source]

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:

Any line normal to the plane has direction numbers

Let the point be defined as point

Let line1 be defined as the line through point with direction numbers

Ensure that the values 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

For example:

plane1 is defined as

Point has coordinates

  • At what point does the normal through enter plane1?
  • What is the distance from to ?

Convert the equation of plane1 to direction cosines:

Using

Point

Distance from to

Plane and plane[edit | edit source]

Figure 1: Diagram illustrating 2 parallel planes.
Line is normal to plane1.
Line is normal to plane2.
The 2 normals are parallel.
Therefore, the 2 planes plane1, plane2 are parallel.

If two planes are parallel:

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

The distance between two parallel planes and is provided that both planes are defined with direction cosines.

Figure 1: Diagram illustrating line of intersection of 2 planes.
Line is line of intersection of 2 planes plane1, plane2.
Line is normal to plane1.
Line is normal to plane2.
Line in plane1 is normal to line .
Line in plane2 is normal to line .
Line is normal to both normals .
Line is normal to both normals .
Therefore line is parallel to line

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 is defined as the intersection of two planes plane1 and plane2.

Using any point (the origin is convenient,) calculate the coordinates of point within plane2 and on the normal from point to plane2.

Calculate the direction numbers of line

Calculate the direction numbers of line normal to both lines

Point is the point at which line enters plane1.

Line PQ may be defined as point with direction numbers of line

Any point on line has distance from both planes plane1 and plane2.

Algebraic method:


Let a line be defined by two planes:

From derive other equations:


The line may be defined by any 2 of


To find a point on the line, let

From

From

Therefore is a point on the line and the line has direction numbers


Any point on the line has coordinates

For proof:

Substitute these values into

Substitute these values into

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

Pencil of planes:

Let a line be defined as the intersection of 2 planes,

Let a 3rd plane be defined as :

The 3 planes 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

In the block above this was proved for a special case of 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:

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

Any 2 of 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

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:

Reviewing:[edit | edit source]

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

Point and line[edit | edit source]
Figure 1: Diagram illustrating line point and line normal from to .

Line and point are given.

Calculate the coordinates of point on line so that line is normal to line

Calculate the direction numbers of line

Using and point calculate the plane normal to line and containing point plane

Point is the point at which line enters plane

Points of closest approach[edit | edit source]
Figure 1: Diagram illustrating points of closest approach of 2 skew lines

Lines are skew.

Calculate point so that distance from point to line is minimum.

Calculate direction numbers of line normal to both

Calculate direction numbers of line normal to both

Using direction numbers of line and point or point calculate plane

Point is the point at which line enters plane

Three planes[edit | edit source]

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 is the line of intersection of two planes plane1, plane2.

Line 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 is line of intersection of two planes plane1, plane2.

Point , the point of intersection of the 3 planes, is the point at which line enters plane3.

Similarly:

  • Line is common to plane1, plane3. Point is the point at which line enters plane2.
  • Line is common to plane2, plane3. Point is the point at which line enters plane1.

The sphere[edit | edit source]

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

where:


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 are (1, 1, 1).

reversing the conversion[edit | edit source]

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


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[edit | edit source]

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 is negative. Consequently the value is a complex number.

Sphere at origin:

If center of sphere is at origin,

For example, a sphere at origin with radius 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 point is inside sphere.

If distance from point to center point is on surface of sphere.

If distance from point to center 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[edit | edit source]

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:[edit | edit source]

Let center of sphere and point

Calculate coordinates of point on the line so that line is normal to the given line.

Calculate length This length is less than the radius of the sphere. The line intersects the sphere in 2 points. Let these points be

Length length

Redefine the line so that direction numbers are direction cosines: ( (4,-5,10), [], 'line' )

Point = (6, 3, -8).

Point = (5, -1, 1).

Proof:

Distance from point S to center radius.

Distance from point T to center 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[edit | edit source]

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 satisfy the equation of the sphere:

Therefore:

Expand and the result is:

This is a quadratic equation in

where:

and

# 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:[edit | edit source]

Let the sphere be defined as ( (), 'sphere' ).

Let the line be defined as the intersection of 2 planes ( (), 'plane' ) and ( (), 'plane' ).

The relevant equations are :

The point/s of intersection are the solution/s of these 3 equations for

The value/s of are the solution/s of the quadratic equation

# 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 = (
-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)*(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[edit | edit source]

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 <module>
    (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[edit | edit source]

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[edit | edit source]

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

Let center of sphere be

Let 4 points on surface of sphere be

or


Solving for is accomplished in python code below:

def centerFrom4 (input) :
    row1,row2,row3,row4 = input

    a,b,c = row1
    g,h,j = row2
    k,l,m = row3
    n,p,q = row4

    top = (
+ (a)*(a)*(c)*(h)*(m) - (a)*(a)*(c)*(h)*(q) - (a)*(a)*(c)*(j)*(l) + (a)*(a)*(c)*(j)*(p)
+ (a)*(a)*(c)*(l)*(q) - (a)*(a)*(c)*(m)*(p) - (a)*(a)*(h)*(j)*(m) + (a)*(a)*(h)*(j)*(q)
+ (a)*(a)*(j)*(j)*(l) - (a)*(a)*(j)*(j)*(p) - (a)*(a)*(j)*(l)*(q) + (a)*(a)*(j)*(m)*(p)
+ (b)*(b)*(c)*(h)*(m) - (b)*(b)*(c)*(h)*(q) - (b)*(b)*(c)*(j)*(l) + (b)*(b)*(c)*(j)*(p)
+ (b)*(b)*(c)*(l)*(q) - (b)*(b)*(c)*(m)*(p) - (b)*(b)*(h)*(j)*(m) + (b)*(b)*(h)*(j)*(q)
+ (b)*(b)*(j)*(j)*(l) - (b)*(b)*(j)*(j)*(p) - (b)*(b)*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)*(p) - (h)*(j)*(k)*(k)*(q) - (h)*(j)*(l)*(l)*(q)
- (h)*(j)*(m)*(m)*(q) + (h)*(j)*(m)*(n)*(n) + (h)*(j)*(m)*(p)*(p) + (h)*(j)*(m)*(q)*(q)
+ (j)*(j)*(j)*(l)*(q) - (j)*(j)*(j)*(m)*(p) + (j)*(j)*(k)*(k)*(p) + (j)*(j)*(l)*(l)*(p)
- (j)*(j)*(l)*(n)*(n) - (j)*(j)*(l)*(p)*(p) - (j)*(j)*(l)*(q)*(q) + (j)*(j)*(m)*(m)*(p))

    bottom = (
- (a)*(c)*(h)*(m) + (a)*(c)*(h)*(q) + (a)*(c)*(j)*(l) - (a)*(c)*(j)*(p)
- (a)*(c)*(l)*(q) + (a)*(c)*(m)*(p) + (a)*(h)*(j)*(m) - (a)*(h)*(j)*(q)
- (a)*(j)*(j)*(l) + (a)*(j)*(j)*(p) + (a)*(j)*(l)*(q) - (a)*(j)*(m)*(p)
+ (b)*(c)*(g)*(m) - (b)*(c)*(g)*(q) - (b)*(c)*(j)*(k) + (b)*(c)*(j)*(n)
+ (b)*(c)*(k)*(q) - (b)*(c)*(m)*(n) - (b)*(g)*(j)*(m) + (b)*(g)*(j)*(q)
+ (b)*(j)*(j)*(k) - (b)*(j)*(j)*(n) - (b)*(j)*(k)*(q) + (b)*(j)*(m)*(n)
- (c)*(c)*(g)*(l) + (c)*(c)*(g)*(p) + (c)*(c)*(h)*(k) - (c)*(c)*(h)*(n)
- (c)*(c)*(k)*(p) + (c)*(c)*(l)*(n) + (c)*(g)*(j)*(l) - (c)*(g)*(j)*(p)
+ (c)*(g)*(l)*(q) - (c)*(g)*(m)*(p) - (c)*(h)*(j)*(k) + (c)*(h)*(j)*(n)
- (c)*(h)*(k)*(q) + (c)*(h)*(m)*(n) + 2*(c)*(j)*(k)*(p) - 2*(c)*(j)*(l)*(n)
- (g)*(j)*(l)*(q) + (g)*(j)*(m)*(p) + (h)*(j)*(k)*(q) - (h)*(j)*(m)*(n)
- (j)*(j)*(k)*(p) + (j)*(j)*(l)*(n))

    d = -top/(2*bottom)

    print ('d = ',d)

    e = (
-(+ (a)*(a)*(j) - (a)*(a)*(q) - 2*(a)*(d)*(j) + 2*(a)*(d)*(q) + (b)*(b)*(j) - (b)*(b)*(q) + (c)*(c)*(j)
- (c)*(c)*(q) + 2*(c)*(d)*(g) - 2*(c)*(d)*(n) - (c)*(g)*(g) - (c)*(h)*(h) - (c)*(j)*(j) + (c)*(n)*(n)
+ (c)*(p)*(p) + (c)*(q)*(q) - 2*(d)*(g)*(q) + 2*(d)*(j)*(n) + (g)*(g)*(q) + (h)*(h)*(q) +  (j)*(j)*(q)
- (j)*(n)*(n) - (j)*(p)*(p) - (j)*(q)*(q))
/
(2*(- (b)*(j) + (b)*(q) + (c)*(h) - (c)*(p) - (h)*(q) + (j)*(p)))
)

    print ('e = ',e)

    f = (
-(+ (a)*(a) - 2*(a)*(d) + (b)*(b) - 2*(b)*(e) + (c)*(c) + 2*(d)*(n) + 2*(e)*(p) - (n)*(n) - (p)*(p) - (q)*(q))
/
(2*(- (c) + (q)))
)

    print ('f = ',f)
    return (d,e,f)

p1 = (16,11,29) #
p2 = (17,-5,20) # The 4 known points.
p3 = (25,3,14)  #
p4 = (10,19,13) #

d,e,f = centerFrom4 ((
p1,p2,p3,p4
))

print ([ ( (d-v[0])**2 + (e-v[1])**2 + (f-v[2])**2 )**.5  for v in (p1,p2,p3,p4) ])
d =  13.0
e =  7.0
f =  17.0
[13.0, 13.0, 13.0, 13.0] # Distance from each point to center = 13.

Calculations simplified:

By arranging the data so that certain values, a, h, m, become zero temporarily, the above calculations may be simplified.

# python code.
def centerFrom4 (input) :
    row1,row2,row3,row4 = input
    print ('input =\n ', row1,'\n ',row2,'\n ',row3,'\n ',row4)

    a,b,c = row1
    g,h,j = row2
    k,l,m = row3

    a_,h_,m_ = a,h,m

    L1 = []
    for v in input :
        # Reduce all X values by a, all Y values by h, all Z values by m.
        L1 += [(v[0]-a, v[1]-h, v[2]-m)]

    row1,row2,row3,row4 = L1
    print ('input modified =\n ', row1,'\n ',row2,'\n ',row3,'\n ',row4)
    a,b,c = row1
    g,h,j = row2
    k,l,m = row3
    n,p,q = row4


    d = (
-(- (b)*(b)*(c)*(j)*(l) + (b)*(b)*(c)*(j)*(p) + (b)*(b)*(c)*(l)*(q) + (b)*(b)*(j)*(j)*(l)
- (b)*(b)*(j)*(j)*(p) - (b)*(b)*(j)*(l)*(q) + (b)*(c)*(g)*(g)*(q) + (b)*(c)*(j)*(j)*(q)
+ (b)*(c)*(j)*(k)*(k) + (b)*(c)*(j)*(l)*(l) - (b)*(c)*(j)*(n)*(n) - (b)*(c)*(j)*(p)*(p)
- (b)*(c)*(j)*(q)*(q) - (b)*(c)*(k)*(k)*(q) - (b)*(c)*(l)*(l)*(q) - (b)*(g)*(g)*(j)*(q)
- (b)*(j)*(j)*(j)*(q) - (b)*(j)*(j)*(k)*(k) - (b)*(j)*(j)*(l)*(l) + (b)*(j)*(j)*(n)*(n)
+ (b)*(j)*(j)*(p)*(p) + (b)*(j)*(j)*(q)*(q) + (b)*(j)*(k)*(k)*(q) + (b)*(j)*(l)*(l)*(q)
- (c)*(c)*(c)*(j)*(l) + (c)*(c)*(c)*(j)*(p) + (c)*(c)*(c)*(l)*(q) + (c)*(c)*(g)*(g)*(l)
- (c)*(c)*(g)*(g)*(p) + (2)*(c)*(c)*(j)*(j)*(l) - (2)*(c)*(c)*(j)*(j)*(p) - (c)*(c)*(j)*(l)*(q)
+ (c)*(c)*(k)*(k)*(p) + (c)*(c)*(l)*(l)*(p) - (c)*(c)*(l)*(n)*(n) - (c)*(c)*(l)*(p)*(p)
- (c)*(c)*(l)*(q)*(q) - (c)*(g)*(g)*(j)*(l) + (c)*(g)*(g)*(j)*(p) - (c)*(g)*(g)*(l)*(q)
- (c)*(j)*(j)*(j)*(l) + (c)*(j)*(j)*(j)*(p) - (c)*(j)*(j)*(l)*(q) - (2)*(c)*(j)*(k)*(k)*(p)
- (2)*(c)*(j)*(l)*(l)*(p) + (2)*(c)*(j)*(l)*(n)*(n) + (2)*(c)*(j)*(l)*(p)*(p)
+ (2)*(c)*(j)*(l)*(q)*(q) + (g)*(g)*(j)*(l)*(q) + (j)*(j)*(j)*(l)*(q) + (j)*(j)*(k)*(k)*(p)
+ (j)*(j)*(l)*(l)*(p) - (j)*(j)*(l)*(n)*(n) - (j)*(j)*(l)*(p)*(p) - (j)*(j)*(l)*(q)*(q))
/
(2*(- (b)*(c)*(g)*(q) - (b)*(c)*(j)*(k) + (b)*(c)*(j)*(n) + (b)*(c)*(k)*(q)
+ (b)*(g)*(j)*(q) + (b)*(j)*(j)*(k) - (b)*(j)*(j)*(n) - (b)*(j)*(k)*(q)
- (c)*(c)*(g)*(l) + (c)*(c)*(g)*(p) - (c)*(c)*(k)*(p) + (c)*(c)*(l)*(n)
+ (c)*(g)*(j)*(l) - (c)*(g)*(j)*(p) + (c)*(g)*(l)*(q) + (2)*(c)*(j)*(k)*(p)
- (2)*(c)*(j)*(l)*(n) - (g)*(j)*(l)*(q) - (j)*(j)*(k)*(p) + (j)*(j)*(l)*(n)))
)

    e = (
-(+ (b)*(b)*(j) - (b)*(b)*(q) + (c)*(c)*(j) - (c)*(c)*(q) + (2)*(c)*(d)*(g) - (2)*(c)*(d)*(n)
- (c)*(g)*(g) - (c)*(j)*(j) + (c)*(n)*(n) + (c)*(p)*(p) + (c)*(q)*(q) - (2)*(d)*(g)*(q)
+ (2)*(d)*(j)*(n) + (g)*(g)*(q) + (j)*(j)*(q) - (j)*(n)*(n) - (j)*(p)*(p) - (j)*(q)*(q))
/
(2*(- (b)*(j) + (b)*(q) - (c)*(p) + (j)*(p)))
)


    f = (
-(+ (b)*(b) - (2)*(b)*(e) + (c)*(c) + (2)*(d)*(n) + (2)*(e)*(p) - (n)*(n) - (p)*(p) - (q)*(q))
/
(2*(- (c) + (q)))
)

# Produce correct values (x, y, z).
    d += a_
    e += h_
    f += m_

    return d,e,f

p1 = (16,11,29) #
p2 = (17,-5,20) # The 4 known points.
p3 = (25,3,14)  #
p4 = (10,19,13) #

d,e,f = centerFrom4 (
    (p1,p2,p3,p4)
)

print ('d,e,f =', d,e,f)
print ([ ( (d-v[0])**2 + (e-v[1])**2 + (f-v[2])**2 )**.5  for v in (p1,p2,p3,p4) ])
input =
  (16, 11, 29)
  (17, -5, 20)
  (25, 3, 14)
  (10, 19, 13)
input modified =
  (0, 16, 15)
  (1, 0, 6)
  (9, 8, 0)
  (-6, 24, -1)
#  ^   ^   ^
#  ^   ^   All values of z reduced by m=14.
#  ^   All values of y reduced by h=-5.
#  All values of x reduced by a=16.
d,e,f = 13.0 7.0 17.0
[13.0, 13.0, 13.0, 13.0] # Distance from each point to center = 13.
Center as intersection of 3 planes[edit | edit source]

When expanded, equation above has the form This is the equation of the plane normal to line 'line' and containing the point midway between points

# 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(poi