# Circles and Spheres

Steven Dutch, Natural and Applied Sciences, University of Wisconsin - Green Bay
First - time Visitors: Please visit Site Map and Disclaimer. Use "Back" to return here.

Circles and spheres are of major importance in geological mathematics. We live on a sphere, after all, and we conventionally represent the heavens in spherical coordinates. We define strain in terms of the deformation of a circle, plot structural and crystallographic data on spheres, and so on.

## Circles in the Plane

### Center at Origin, Radius r

• x * x + y * y = r * r
• x = sqr(r*r - y*y) or y = sqr(r*r - x*x)

### Center at Arbitrary Point (h,k), Radius r

• (x - h)*(x - h) + (y - k)*(y - k) = r*r
• x = h + sqr(r*r - (y - k)*(y - k)) or x = h - sqr(r*r - (y - k)*(y - k))
• y = k + sqr(r*r - (x - h)*(x - h)) or y = k - sqr(r*r - (x - h)*(x - h))

### General Form x*x + y*y + 2*d*x + 2*e*y + f = 0

• Center located at ( - d, - e)
• Radius: r = sqr(d*d + e*e - f)

• Center at origin:
• x = r*cos(t)
• y = r*sin(t)
• Center at (h,k):
• x = h + r*cos(t)
• y = k + r*sin(t)

This is probably the most useful form for drawing a circle. It eliminates the need to allow for both positive and negative square roots.

### Circle with a Given Line as Diameter

If the diameter of the circle is the line with endpoints (x1, y1) and (x2, y2), the equation of the circle is:

• (x - x1)*(x - x2) + (y - y1)*(y - y2) = 0 or,
• x*x + y*y - (x1 + x2)*x - (y1 + y2)*y + x1*x2 + y1*y2 = 0.

We can see that the center of the circle lies at:

• x = (x1 + x2)/2, y = (y1 + y2)/2, and its radius is:
• r = sqr((x1*x1) + (x1*x2) + (x2*x2) + (y1*y1) + (y1*y2) + (y2*y2))

### Three - point Form

A circle which passes through three points (x1,y1),(x2,y2) and (x3,y3) has the equation

```         |x*x + y*y       x    y    1|
|x1*x1 + y1*y1   x1   y1   1| = 0
|x2*x2 + y2*y2   x2   y2   1|
|x3*x3 + y3*y3   x3   y3   1|
```

The formula is complicated, and it is probably best to find the center and radius. The center (h,k) must be computed piecemeal. In programming terms:

```REM find h h = x1*x1*(y2 - y3) + x2*x2*(y3 - y1) + x3*x3*(y1 - y2) h = h - (y1 - y2)*(y2 - y3)*(y3 - y1) h = h/(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)) h = h/2 REM find k k = y1*y1*(x2 - x3) + y2*y2*(x3 - x1) + y3*y3*(x1 - x2) k = k - (x1 - x2)*(x2 - x3)*(x3 - x1) k = k/(y1*(x2 - x3) + y2*(x3 - x1) + y3*(x1 - x2)) k = k/2```

Having computed the location of the center, the easiest way to find the radius is by substituting one of the three points into the general formula for a circle. Thus:

r = sqr((x1 - h)*(x1 - h) + (y1 - k)*(y1 - k))

## Spheres

### Center at Origin, Radius r

• x * x + y * y + z * z = r * r
• x = sqr(r*r - y*y - z*z) or
• y = sqr(r*r - x*x - z*z) or
• z = sqr(r*r - x*x - y*y)

### Center at Arbitrary Point (h,k,l), Radius r

• (x - h)*(x - h) + (y - k)*(y - k) + (z - l)*(z - 1) = r*r
• x = h + sqr(r*r - (y - k)*(y - k) - (z - 1)*(z - 1))
• y = k + sqr(r*r - (x - h)*(x - h) - (z - 1)*(z - 1))

### General Form x*x + y*y + z*z + 2*d*x + 2*e*y + 2*f*z + m = 0

• Center located at ( - d, - e, - f)
• Radius: r = sqr(d*d + e*e + f*f - m)

Note: to reduce the formula to this form divide by the coefficient of the square term. If the formula can't be reduced to this form, the figure is an ellipsoid, not a sphere.

### Sphere with a Given Line as Diameter

If the diameter of the sphere is the line with endpoints (x1, y1, z1) and (x2, y2, z2), the equation of the sphere is:

• (x - x1)*(x - x2) + (y - y1)*(y - y2) + (z - z1)*(z - z2) = 0 or,
• x*x + y*y + z*z - (x1 + x2)*x - (y1 + y2)*y - (z1 + z2)*z + x1*x2 + y1*y2 + z1*z2 = 0.

From the General Form, we can see that the center of the circle lies at
x = (x1 + x2)/2, y = (y1 + y2)/2, z = (z1 + z2)/2.

r = sqr((x1*x1) + (x1*x2) + (x2*x2) + (y1*y1) + (y1*y2) + (y2*y2) + (z1*z1) + (z1*z2) + (z2*z2))

### Four - Point Form

A sphere which passes through four points (x1,y1,z1), (x2,y2,z2), (x3,y3,z3), and (x4,y4,z4) has the equation

```         |x*x + y*y + z*z         x   y   z   1|
|x1*x1 + y1*y1 + z1*z1   x1  y1  z1  1|
|x2*x2 + y2*y2 + z2*z2   x2  y2  z2  1| = 0
|x3*x3 + y3*y3 + z3*z3   x3  y3  z3  1|
|x4*x4 + y4*y4 + z4*z4   x4  y4  z4  1|
```

We can expand the determinant as follows. First, substitute r1 = x1*x1 + y1*y1 + z1*z1, and so on. We then have

```         |x*x + y*y + z*z  x  y  z  1|
|        r1      x1 y1 z1  1|
|        r2      x2 y2 z2  1| = 0
|        r3      x3 y3 z3  1|
|        r4      x4 y4 z4  1|
```

The determinant expands along the top row to:

```                              |x1   y1   z1   1|
(x*x + y*y + z*z) * |x2   y2   z2   1|
|x3   y3   z3   1|
|x4   y4   z4   1|

|r1   y1   z1   1|      |r1   x1   z1   1|
- x *|r2   y2   z2   1| + y *|r2   x2   z2   1|
|r3   y3   z3   1|      |r3   x3   z3   1|
|r4   y4   z4   1|      |r4   x4   z4   1|

|r1   x1   y1   1|     |r1   x1   y1   z1|
- z *|r2   x2   y2   1|  +  |r2   x2   y2   z2|
|r3   x3   y3   1|     |r3   x3   y3   z3|
|r4   x4   y4   1|     |r4   x4   y4   z4|
```

We now have the equation in a form similar to the General Form, and we can rewrite the above formula as follows:

x*x + y*y + z*z + (d1/d0)*x + (d2/d0)*y + (d3/d0)*z + (d4/d0) = 0

where d0...d4 represent the determinants in the expansion above in the order given.

To determine the geometry of the sphere, we need to expand the determinants according to the following routine:

```REM CALCULATE DETERMINANTS REM INITIALIZE D0 = 0:D1 = 0:D2 = 0:D3 = 0:D4 = 0 REM CALCULATE D0 D0 = (x2 - x1)*((y3 - y1)*(z4 - z1) - (y4 - y1)*(z3 - z1) D0 = D0 - (x3 - x1)*((y2 - y1)*(z4 - z1) - (y4 - y1)*(z2 - z1) D0 = D0 + (x4 - x1)*((y2 - y1)*(z3 - z1) - (y3 - y1)*(z2 - z1) REM CALCULATE D1 D1 = (R2 - R1)*((y3 - y1)*(z4 - z1) - (y4 - y1)*(z3 - z1) D1 = D1 - (R3 - R1)*((y2 - y1)*(z4 - z1) - (y4 - y1)*(z2 - z1) D1 = D1 + (R4 - R1)*((y2 - y1)*(z3 - z1) - (y3 - y1)*(z2 - z1) REM CALCULATE D2 D2 = (R2 - R1)*((x3 - x1)*(z4 - z1) - (x4 - x1)*(z3 - z1) D2 = D2 - (R3 - R1)*((x2 - x1)*(z4 - z1) - (x4 - x1)*(z2 - z1) D2 = D2 + (R4 - R1)*((x2 - x1)*(z3 - z1) - (x3 - x1)*(z2 - z1) REM CALCULATE D3 D3 = (R2 - R1)*((x3 - x1)*(y4 - y1) - (x4 - x1)*(y3 - y1) D2 = D2 - (R3 - R1)*((x2 - x1)*(y4 - y1) - (x4 - x1)*(y2 - y1) D2 = D2 + (R4 - R1)*((x2 - x1)*(y3 - y1) - (x3 - x1)*(y2 - y1) REM CALCULATE D4 D4 = R1*(x2*(y3*z4 - y4*z3) + x3*(y4*z2 - y2*z4)) D4 = D4 + R1*(x4*(y2*z3 - y3*z2)) D4 = D4 - R2*(x1*(y3*z4 - y4*z3) + x3*(y4*z1 - y1*z4)) D4 = D4 - R2*(x4*(y1*z3 - y3*z1)) D4 = D4 + R3*(x1*(y2*z4 - y4*z2) + x2*(y4*z1 - y1*z4)) D4 = D4 + R3*(x4*(y1*z2 - y2*z1)) D4 = D4 - R4*(x1*(y2*z3 - y3*z2) + x2*(y3*z1 - y1*z3)) D4 = D4 - R4*(x3*(y1*z2 - y2*z1)) REM CALCULATE RADIUS R = SQR(D1*D1 + D2*D2 + D3*D3 - 4*D4*D4))/(2*D0) REM LOCATE CENTER x = D1/(2*D0) y = D2/(2*D0) z = D3/(2*D0)```