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.
<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=''▼
When a=1 Then
▲ pd='x'
Say 'Plane''s definition:' pd '=' d▼
Otherwise
pd=a'*x'
End
pd=pd||mk2('y',b)||mk2('z',c)'='d
ip=0
Line 167 ⟶ 172:
z=a.3+t*v.3
ld=mk('x
Say 'Line definition:' ld
Say 'Intersection: P('||x','y','z')'
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
Line definition: x=
Intersection: P(0.6,2.4,4.2)</pre>
|