<?xml version="1.0" encoding="UTF-8"?>
<Worksheet><Version major="6" minor="1"/><View-Properties><Zoom percentage="100"/></View-Properties><Styles><Layout alignment="left" bullet="none" name="Normal"/><Font background="[0,0,0]" bold="true" executable="true" family="Monospaced" foreground="[255,0,0]" name="Maple Input" size="12"/><Font background="[0,0,0]" bold="false" family="Times New Roman" foreground="[0,0,0]" italic="false" name="Text" opaque="false" size="12" underline="false"/></Styles><Group><Input><Text-field alignment="centred" layout="Normal" style="Text"><Font bold="true" size="18">Ray and Object Intersections: Cylinder</Font></Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/><Text-field alignment="centred" layout="Normal" style="Text">
by Otto Wilke
otto_wilke@hotmail.com</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">I am vaguely aware that graphics is normally done with vector operations, generic</Text-field><Text-field layout="Normal" style="Text">solids positioned at the origin, and transformation matrices to move rays to and fro.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">I thought it would be interesting to use rectangular coordinates and objects located</Text-field><Text-field layout="Normal" style="Text">anywhere in space and oriented in any direction.</Text-field><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">This is one of four files covering the plane, the sphere, the cylinder, and the cone. </Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Let C be a right circular cylinder having radius r and positioned some place in space and oriented in </Text-field><Text-field layout="Normal" style="Text">some direction.  Let P1(x1,y1,z1) and P2(x2,y2,z2) be the centers of the circular ends.  Let P(x,y,z) </Text-field><Text-field layout="Normal" style="Text">be some point on the cylinder.  Let d1 be the distance from P1 to P2, d2 be the distance from P to P1, </Text-field><Text-field layout="Normal" style="Text">and d3 be the distance from P to P2.  <Font italic="false" style="Maple Input" underline="false">

restart;
d1:=sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2);
d2:=sqrt((x-x1)^2+(y-y1)^2+(z-z1)^2);
d3:=sqrt((x2-x)^2+(y2-y)^2+(z2-z)^2);</Font>
</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text"><Font executable="false">The area of the triangle P P1 P2 is </Font></Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">Area=1/2*r*d1;AreaSquared1:=expand((1/2*r*d1)^2);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Let s be the semi-perimeter of triangle P P1 P2.  By Heron's formula the area squared is also</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">s:=(d1+d2+d3)/2;AreaSquared2:=expand((d1+d2+d3)/2*(s-d1)*
(s-d2)*(s-d3));</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">sort(AreaSquared1-AreaSquared2,[x,y,z])=0;sort(4*%,[x,y,z]);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">This last equation gives a point on an infinitely long cylinder, however, the distance from the center of the cylinder to a point on the cylinder must be limited.  When P3 is on the cylinder at one end, let the distance from the midpoint of P1 and P2 to P3 be d4.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">d4:=sqrt(r^2+(x1-(x1+x2)/2)^2+(y1-(y1+y2)/2)^2+(z1-(z1+z2)/2)^2);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">The distance from the midpoint of the cylinder to any P must be less that or equal to d4.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">sqrt(r^2+(x-(x1+x2)/2)^2+(y-(y1+y2)/2)^2+(z-(z1+z2)/2)^2)&lt;=d4;</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Let L be a line on point P4(x4,y4,z4) and let L have direction numbers a, b, and c.  The parametric equations for L are</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">x=x4+a*t;y=y4+b*t;z=z4+c*t;</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Now that we have equations for points on a line and a cylinder and one inequality, we'll ask Maple to solve the simlutaneous equations and inequality.  </Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">solve({x=x4+a*t,y=y4+b*t,z=z4+c*t,</Text-field></Input><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">sqrt(r^2+(x-(x1+x2)/2)^2+(y-(y1+y2)/2)^2+(z-(z1+z2)/2)^2)&lt;=d4,
sort(AreaSquared1-AreaSquared2,[x,y,z])=0},{x,y,z,t});</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Maple fails to solve the set.  Let's pick P4 as (0,0,0) and a=1, b=2, c=1 and r=1 and 
P1 as (1,1,0) and P2 as (2,2,3).</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">x4:=0;y4:=0;z4:=0;a:=1;b:=2;c:=1;x1:=1;y1:=1;z1:=0;
x2:=2;y2:=2;z2:=3;r:=1;</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">  Try again.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">solve({x=x4+a*t,y=y4+b*t,z=z4+c*t,</Text-field></Input><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">sqrt(r^2+(x-(x1+x2)/2)^2+(y-(y1+y2)/2)^2+(z-(z1+z2)/2)^2)&lt;=d4,
sort(AreaSquared1-AreaSquared2,[x,y,z])=0},{x,y,z,t});</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">evalf(allvalues(%));</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">with(plots):</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plot1:=arrow(&lt;0,0,0&gt;, &lt;1.206622805,2.413245610,1.206622805&gt;, 
width=[0.1, relative], head_length=[0.2, relative], color=red):</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plot2:=implicitplot3d(sort(AreaSquared1-AreaSquared2,[x,y,z])=0,
x=-1..4, y=-1..4, z=-1..4, grid=[13,13,13]):</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plot3:=pointplot3d({[1.206622805,2.413245610,1.206622805] },axes=normal,symbol=box,symbolsize=50,color=red);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">display({plot1,plot2,plot3});</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text"/><Text-field layout="Normal" style="Text">Now let's consider the circular ends.  The direction numbers of the axis of the cylinder are</Text-field><Text-field layout="Normal" style="Text">A=x2-x1, B=y2-y1, and C=z2-z1.  The plane A x + B y + C z +D = 0 is normal to the</Text-field><Text-field layout="Normal" style="Text">axis of the cylinder.  P2 is on that plane.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">(x2-x1)*x2+(y2-y1)*y2+(z2-z1)*z2 +D2 = 0;</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">D2:=solve((x2-x1)*x2+(y2-y1)*y2+(z2-z1)*z2 +D2 = 0,D2);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">The equation of the plane of the circular end on which P2 lies is</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">(x2-x1)*x+(y2-y1)*y+(z2-z1)*z +D2 = 0;</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">The distance d5 from some point P on the circular end to the center of the circle must be less </Text-field><Text-field layout="Normal" style="Text">than or equal to the radius of the cylinder.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">d5:=sqrt((x-x2)^2+(y-y2)^2+(z-z2)^2);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">Now that we have the equation of the ray, the equation of the circular end at P2, and the</Text-field><Text-field layout="Normal" style="Text">necessary inequality, let's check for an intersection.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input><Input><Text-field layout="Normal" style="Text">  </Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">solve({x=x4+a*t,y=y4+b*t,z=z4+c*t,</Text-field></Input><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">d5&lt;=r,
(x2-x1)*x+(y2-y1)*y+(z2-z1)*z +D2 = 0},{x,y,z,t});</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">No answer.  Let's try the other end.</Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">D1:=solve((x2-x1)*x1+(y2-y1)*y1+(z2-z1)*z1 +D1 = 0,D1);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">(x2-x1)*x+(y2-y1)*y+(z2-z1)*z +D1 = 0;</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">d6:=sqrt((x-x1)^2+(y-y1)^2+(z-z1)^2);</Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="Text">  </Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input">solve({x=x4+a*t,y=y4+b*t,z=z4+c*t,</Text-field></Input><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">d6&lt;=r,
(x2-x1)*x+(y2-y1)*y+(z2-z1)*z +D1 = 0},{x,y,z,t});</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">plotPlane1:=implicitplot3d((x2-x1)*x+(y2-y1)*y+(z2-z1)*z +D1 = 0,
x=-1..4, y=-1..4, z=-1..4, grid=[13,13,13]):
plotPlane2:=implicitplot3d((x2-x1)*x+(y2-y1)*y+(z2-z1)*z +D2 = 0,
x=-1..4, y=-1..4, z=-1..4, grid=[13,13,13]):
plot4:=pointplot3d({[1/3.,2/3.,1/3.]},axes=normal,symbol=box,
symbolsize=50,color=red):</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input">display({plot1,plot2,plot3,plot4,plotPlane1,plotPlane2});</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Text-field/><Text-field/><Text-field/><Text-field/><Text-field/></Worksheet>