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 = (
- (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[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.

From above, equation of sphere is:

When are known and are unknown the above equation becomes:

With four points provided, equation may be used to construct a system of 4 simultaneous equations that, when solved, provide the values

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

Let center of sphere be

Let 4 points on surface of sphere be

or


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

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.

In the diagram:

line1 has direction cosines

line2 has direction cosines

is angle between line1 and line3.

is angle between line2 and line3.

cos1

cos2

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.

Point P may have 1 value.

Point P may have 2 values.

# 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
Length
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
Coordinates of point are direction numbers of line3.
Point 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[edit | edit source]

Given:

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

Calculate:

  • direction numbers of line2 wholly within plane1 and making angle with line1.

This is a special case of function dcOfLine3 above in which line2 makes the angle of with the normal to the plane, and angle 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θ
        angleInRadians = angleInDegrees*math.pi/180
        cosθ = math.cos(angleInRadians)

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

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 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 After 5 rotations the direction cosines match their initial values.

By algebra[edit | edit source]

Ensure that all values are direction cosines.

The relevant equations are:

= cos1

= cos2


Because may have exactly or or values, is the solution of the quadratic equation where are as defined in the python code below.


Then values may be calculated as shown below.

def dcOfLine3_byAlgebra_ (dc1, dc2, cos1, cos2) :
        '''
This function is called by function dcOfLine3_byAlgebra (dn1, dn2, cos1, cos2) below.
        '''
        a1,b1,c1 = dc1
        a2,b2,c2 = dc2

        if c1 == c2 == 0 : return None
        if (c1*b2-b1*c2 == 0) : return None
        if c1 == 0 :
            a1,b1,c1 = dc2
            a2,b2,c2 = dc1
            cos1,cos2 = cos2,cos1

        C2 = (
+ (a1)*(a1)*(b2)*(b2) + (a1)*(a1)*(c2)*(c2) - 2*(a1)*(b1)*(a2)*(b2)
- 2*(a1)*(c1)*(a2)*(c2) + (b1)*(b1)*(a2)*(a2) + (b1)*(b1)*(c2)*(c2)
- 2*(b1)*(c1)*(b2)*(c2) + (c1)*(c1)*(a2)*(a2) + (c1)*(c1)*(b2)*(b2)
)
        if C2 == 0 : return None
        C1 = (
+ 2*(a1)*(b1)*(b2)*(cos2) + 2*(a1)*(c1)*(c2)*(cos2) - 2*(a1)*(b2)*(b2)*(cos1)
- 2*(a1)*(c2)*(c2)*(cos1) - 2*(b1)*(b1)*(a2)*(cos2) + 2*(b1)*(a2)*(b2)*(cos1)
- 2*(c1)*(c1)*(a2)*(cos2) + 2*(c1)*(a2)*(c2)*(cos1)
)
        C0 = (
- (b1)*(b1)*(c2)*(c2) + (b1)*(b1)*(cos2)*(cos2) + 2*(b1)*(c1)*(b2)*(c2)
- 2*(b1)*(b2)*(cos1)*(cos2) - (c1)*(c1)*(b2)*(b2) + (c1)*(c1)*(cos2)*(cos2)
- 2*(c1)*(c2)*(cos1)*(cos2) + (b2)*(b2)*(cos1)*(cos1) + (c2)*(c2)*(cos1)*(cos1)
)
        discr = C1*C1 - 4*C2*C0
        if discr < 0 : return []
        if discr == 0 :
            values_of_a3 = [-C1 /(2*C2)]
        else :
            root = discr ** .5
            values_of_a3 = [(-C1+root) /(2*C2), (-C1-root) /(2*C2)]
        output = []
        for a3 in values_of_a3 :
            b3 = (
( + (c2)*(cos1) + (a3)*(c1)*(a2) - (a3)*(a1)*(c2) - (c1)*(cos2))
                               /
                  ( (b1)*(c2) - (c1)*(b2))
)
            c3 = (
( + (cos1) - (a3)*(a1) - b3*(b1))
                /
               c1
)
            output += [[a3,b3,c3]]
        return output

The function above simplifies to:

def dcOfLine3_byAlgebra_ (dc1, dc2, cos1, cos2) :
        '''
This function is called by function dcOfLine3_byAlgebra (dn1, dn2, cos1, cos2) below.
        '''
        a1,b1,c1 = dc1
        a2,b2,c2 = dc2

        if c1 == c2 == 0 : return None
        A3 = (b1)*(c2) - (c1)*(b2)
        if (A3 == 0) : return None
        B3 = (c1)*(a2) - (a1)*(c2)
        C3 = (a1)*(b2) - (b1)*(a2)

        C2 = (A3)**2 + (B3)**2 + (C3)**2

        C1 = 2*(
+ (a1)*(b1)*(b2)*(cos2) + (a1)*(c1)*(c2)*(cos2) - (a1)*(b2)*(b2)*(cos1)
- (a1)*(c2)*(c2)*(cos1) - (b1)*(b1)*(a2)*(cos2) + (b1)*(a2)*(b2)*(cos1)
- (c1)*(c1)*(a2)*(cos2) + (c1)*(a2)*(c2)*(cos1)
)

        C0 = (
+ ((b1)*(cos2) - (b2)*(cos1))**2
+ ((c1)*(cos2) - (c2)*(cos1))**2
- (A3)**2
)

        discr = C1*C1 - 4*C2*C0
        discr = (discr,0)[abs(discr) < 1e-15]
        if discr < 0 : return []
        if discr == 0 :
            values_of_a3 = [-C1 /(2*C2)]
        else :
            root = discr ** .5
            values_of_a3 = [(-C1+root) /(2*C2), (-C1-root) /(2*C2)]

        output = []
        for a3 in values_of_a3 :
            b3 = ( + (c2)*(cos1) + (a3)*(B3) - (c1)*(cos2)) /  A3
            if c1 : c3 = ( + (cos1) - (a3)*(a1) - (b3)*(b1)) / c1
            else :  c3 = ( + (cos2) - (a3)*(a2) - (b3)*(b2)) / c2
            output += [[a3,b3,c3]]

        return output

def dcOfLine3_byAlgebra (dn1, dn2, cos1, cos2) :
    '''
direction cosines of line 3 by algebra
output = dcOfLine3_byAlgebra ([A1,B1,C1], [A2,B2,C2], cos1, cos2)
output may be:
None
[] no solution
[[a3,b3,c3]] 1 group of direction cosines
[[a3a,b3a,c3a], [a3b,b3b,c3b]] 2 groups of direction cosines
'''
    if 1 >= cos1 >= -1 : pass
    else :
        print ('dcOfLine3_byAlgebra (dn1, dn2, cos1, cos2) : error in cos1.')
        return None
    if 1 >= cos2 >= -1 : pass
    else :
        print ('dcOfLine3_byAlgebra (dn1, dn2, cos1, cos2) : error in cos2.')
        return None

    A1,B1,C1 = dn1
    if A1 == B1 == C1 == 0 :
        print ('dcOfLine3_byAlgebra (dn1, dn2, cos1, cos2) : dn1 all zero.')
        return None
    A2,B2,C2 = dn2
    if A2 == B2 == C2 == 0 :
        print ('dcOfLine3_byAlgebra (dn1, dn2, cos1, cos2) : dn2 all zero.')
        return None

    A3 = B1*C2 - C1*B2
    if not A3 :
        B3 = C1*A2 - A1*C2
        if not B3 :
            C3 = A1*B2 - B1*A2
            if not C3 :
                print ('dcOfLine3_byAlgebra (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

    debug = 1
    output = dcOfLine3_byAlgebra_ ([a1,b1,c1], [a2,b2,c2], cos1, cos2)
    if isinstance(output,list) :
        if debug : print (1,output) # output line 1
        return output

    output = dcOfLine3_byAlgebra_ ([b1,c1,a1], [b2,c2,a2], cos1, cos2)
    if isinstance(output,list) :
        output = [ [v[2],v[0],v[1]] for v in output ]
        if debug : print (2,output) # output line 2
        return output

    output = dcOfLine3_byAlgebra_ ([c1,a1,b1], [c2,a2,b2], cos1, cos2)
    if isinstance(output,list) :
        output = [ [v[1],v[2],v[0]] for v in output ]
        if debug : print (3,output) # output line 3

    return output

Examples[edit | edit source]

Normal to 2 lines[edit | edit source]

This is the special case in which cos1 = cos2 = 0 and the calculation of becomes:

whence:

and

Normal to X,Y axes[edit | edit source]
dn1 = [1,0,0] # X axis
dn2 = [0,1,0] # Y axis
cos1 = cos2 = 0
dcOfLine3_byAlgebra (dn1, dn2, cos1, cos2)

In this case the result below was derived from "# output line 3" in the Python code above.

3 [[-0.0, 0.0, 1.0], [-0.0, 0.0, -1.0]]

Links to Related Topics[edit | edit source]

Coordinate_systems

Functions_(mathematics)/Graphs/Coordinations

Functions_(mathematics)/Graphs

Investigating_3D_geometric_algebra

Line_(Geometry)

Functions_(mathematics)/Graphs/Cartesian_Coordinate