Hi, What is problem with follwoing code? I am getting very strange results. Do I missing something?
proc Dot {vec1 vec2} {
set ret [expr ([lindex $vec1 0]*[lindex $vec2 0])+([lindex $vec1 1]*[lindex $vec2 1])+([lindex $vec1 2]*[lindex $vec2 2])]
}
proc FindInterSectPoint_LineAndPlane {normalVectorPlane basePoint refPoint topoint} {
foreach {norm1 norm2 norm3} $normalVectorPlane {break}
foreach {xB yB zB} $basePoint {break}
foreach {xb yb zb} $refPoint {break}
foreach {xa ya za} $topoint {break}
set vecL1 [expr $xb-$xa]
set vecL2 [expr $yb-$ya]
set vecL3 [expr $zb-$za]
set direction [expr -($norm1*$xB)+($norm2*$yB)+($norm3*$zB)]
set d [expr -(($vecL1*$xb)+($vecL2*$yb)+($vecL3*$zb)+$direction)]
set n [Dot $normalVectorPlane [list $vecL1 $vecL2 $vecL3] ]
if {$n == 0} {
return "line on parallel to plane"; # line on plane
}
set s [expr $d/($n*1.000)]
if {$s > 0 && $s < 1} {
set ret "intersection occurs between the two end points"
} elseif {$s == 0} {
set ret "intersection falls on the first end point"
} elseif {$s == 1} {
set ret "intersection falls on the second end point"
} elseif {$s > 1} {
set ret "intersection occurs beyond second end Point"
} elseif {$s < 0} {
set ret "intersection happens before 1st end point"
} else {
set ret "error"
}
set x [expr [lindex $refPoint 0]+($s*$vecL1)]
set y [expr [lindex $refPoint 1]+($s*$vecL2)]
set z [expr [lindex $refPoint 2]+($s*$vecL3)]
lappend ret "$x $y $z n=$n d=$d s=$s"
}
Output:
%FindInterSectPoint_LineAndPlane {0 0 1} {0 0 0} {0 0 0} {1 2 3}
intersection falls on the first end point {0.0 0.0 0.0 n=-3 d=0 s=-0.0}
%FindInterSectPoint_LineAndPlane {1 0 0} {0 0 0} {0 0 1} {0 0 0}
line on parallel to plane
%FindInterSectPoint_LineAndPlane {1 0 0} {0 0 0} {0 0 1} {0 0 5}
line on parallel to plane
%FindInterSectPoint_LineAndPlane {0 0 1} {0 0 0} {1 1 1} {2 2 2}
intersection happens before 1st end point {4.0 4.0 4.0 n=-1 d=3 s=-3.0}
%FindInterSectPoint_LineAndPlane {0 0 1} {0 0 0} {-1 -1 -1} {2 2 2}
intersection occurs beyond second end Point {-10.0 -10.0 -10.0 n=-3 d=-9 s=3.0}