Find the intersection of a line with a plane: Difference between revisions

Content deleted Content added
Walterpachl (talk | contribs)
m →‎{{header|REXX}}: handle the case that the line is parallel to the plane or lies within it
Walterpachl (talk | contribs)
→‎{{header|REXX}}: beautification of plane and linedefinition
Line 131:
===version 2===
handle the case that the line is parallel to the plane or lies withi it.
<br>Beautification of plane and line definitions is yet tbd.
<lang rexx>/*REXX*/
Parse Value '1 2 3' With n.1 n.2 n.3
Line 142 ⟶ 141:
c=n.3
d=n.1*p.1+n.2*p.2+n.3*p.3 /* Parameter form of the plane */
Select
pd=''
If When a<>=0 Then pd=a'*x'
If b<>0 Then pd=pd '+' b'*y'
When a=1 Then
If c<>0 Then pd=pd '+' c'*z'
pd='x'
Say 'Plane''s definition:' pd '=' d
Otherwise
pd=a'*x'
End
pd=pd||mk2('y',b)||mk2('z',c)'='d
 
Say 'Plane''s definition:' pd '=' d
 
ip=0
Line 167 ⟶ 172:
z=a.3+t*v.3
 
ld=mk('x=',a.1,v.1) ';' If mk('y',a.2,v.1<>02) Then';' ld=ldmk('+t*z',a.3,v.13)
ld=ld '; y='a.2; If v.2<>0 Then ld=ld'+t*'v.2
ld=ld '; z='a.3; If v.3<>0 Then ld=ld'+t*'v.3
Say 'Line definition:' ld
 
Say 'Intersection: P('||x','y','z')'</lang>
Exit
 
Mk: Procedure
/*---------------------------------------------------------------------
* build part of line definition
*--------------------------------------------------------------------*/
Parse Arg v,aa,vv
If aa<>0 Then
res=v'='aa
Else
res=v'='
Select
When vv=0 Then
res=res||'0'
When vv=-1 Then
res=res||'-t'
When vv<0 Then
res=res||v1'*t'
Otherwise Do
If res='x=' Then Do
If v1=1 Then
res=res||'t'
Else
res=res||vv'*t'
End
Else Do
If vv=1 Then
res=res||'+t'
Else
res=res||'+'vv'*t'
End
End
End
Return res
 
mk2: Procedure
/*---------------------------------------------------------------------
* build part of plane definition
*--------------------------------------------------------------------*/
Parse Arg v,u
Select
When u=0 Then
res=''
When u=1 Then
res=v
When u<0 Then
res=u'*'v
Otherwise Do
If pd<>'' Then
res='+'u'*'v
Else
res=u'*'v
End
End
Return res</lang>
{{out}}
<pre>Plane's definition: 1*x + 2*y + 3*z = 18
Line definition: x=0+3*t*3 ; y=2+2*t*2 ; z=4+t*1
Intersection: P(0.6,2.4,4.2)</pre>