Application Center - Maplesoft

App Preview:

The Intersection of a Line and Sphere

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Ray and Object Intersections: Sphere

>


by Otto Wilke

otto_wilke@hotmail.com

I am vaguely aware that graphics is normally done with vector operations, generic

solids positioned at the origin, and transformation matrices to move rays to and fro.

I thought it would be interesting to use rectangular coordinates and objects located

anywhere in space and oriented in any direction.

This is one of four files covering the plane, the sphere, the cylinder, and the cone.

INTERSECTION OF A LINE AND A SPHERE

Given a sphere with radius r and center at (h,k,m), then its equation is:

> (x-h)^2+(y-k)^2+(z-m)^2=r^2;

(x-1)^2+(y-2)^2+(z-1)^2 = 25

Assign known values of h, k, m, and r.

> h:=1;k:=2;m:=1;r:=5;

h := 1

k := 2

m := 1

r := 5

> (x-h)^2+(y-k)^2+(z-m)^2=r^2;

(x-1)^2+(y-2)^2+(z-1)^2 = 25

If P1(x1,y1,z1) and P2(x2,y2,z2) are two points on a line L, then a=(x2-x1), b=(y2-y1), and c=(z2-z1) are

direction numbers of L.  The line L on the point P1 and with direction numbers a, b, and c has parametric equations

> x = x1 + a*t; y=y1+b*t;z=z1+c*t;

x = 3-4*t

y = 5-2*t

z = 8-6*t

Asign known values of x1, y1, z1, and a, b, c.

> x1:=3;y1:=5;z1:=8;a:=-4;b:=-2;c:=-6;

x1 := 3

y1 := 5

z1 := 8

a := -4

b := -2

c := -6

> x = x1 + a*t; y=y1+b*t;z=z1+c*t;

x = 3-4*t

y = 5-2*t

z = 8-6*t

> allvalues(solve({x = 3-4*t,y=5-2*t,z=8-6*t,(x-1)^2+(y-2)^2+(z-1)^2 = 25},{x,y,z,t}));

{t = 1+1/28*266^(1/2), z = 2-3/14*266^(1/2), y = 3-1/14*266^(1/2), x = -1-1/7*266^(1/2)}, {t = 1-1/28*266^(1/2), z = 2+3/14*266^(1/2), y = 3+1/14*266^(1/2), x = -1+1/7*266^(1/2)}

> evalf(%);

{t = 1.582482372, z = -1.494894235, y = 1.835035255, x = -3.329929491}, {t = .4175176276, z = 5.494894235, y = 4.164964745, x = 1.329929491}

> with(plots):

> p1:=implicitplot3d((x-1)^2+(y-2)^2+(z-1)^2=25, x=-6..6, y=-6..6, z=-6..6, grid=[13,13,13]):

> p2:=pointplot3d({[-3.329929491,1.835035255,-1.494894235],[1.329929491,4.164964745,5.494894235] },symbol=circle, symbolsize=20,color=red,axes=BOXED):

> display({p1,p2});

[Plot]

>