## ## Get a list of 3 points and calculate the angle between them ## package require PWI_Glyph 2.3 #================================Start processing============================== # Start timer set startTime [clock seconds] if { [catch {set pt1 [pw::Display selectPoint -description \ "Select first point." -connector [list]]}]} { puts "Script aborted." exit } if { [catch {set pt2 [pw::Display selectPoint -description \ "Select second point." -connector [list]]}]} { puts "Script aborted." exit } if { [catch {set pt3 [pw::Display selectPoint -description \ "Select third point." -connector [list]]}]} { puts "Script aborted." exit } set x1 [lindex $pt1 0]; set y1 [lindex $pt1 1]; set z1 [lindex $pt1 2] set x2 [lindex $pt2 0]; set y2 [lindex $pt2 1]; set z2 [lindex $pt2 2] set x3 [lindex $pt3 0]; set y3 [lindex $pt3 1]; set z3 [lindex $pt3 2] set l_asq [ expr { ($x1 - $x2)*($x1 - $x2) + ($y1 - $y2)*($y1 - $y2) + ($z1 - $z2)*($z1 - $z2) } ] set l_bsq [ expr { ($x3 - $x2)*($x3 - $x2) + ($y3 - $y2)*($y3 - $y2) + ($z3 - $z2)*($z3 - $z2) } ] set l_csq [ expr { ($x3 - $x1)*($x3 - $x1) + ($y3 - $y1)*($y3 - $y1) + ($z3 - $z1)*($z3 - $z1) } ] set l_a [ expr { sqrt($l_asq) } ] set l_b [ expr { sqrt($l_bsq) } ] puts [ format "Points selected"] puts [ format " %f %f %f" $x1 $y1 $z1 ] puts [ format " %f %f %f" $x2 $y2 $z2 ] puts [ format " %f %f %f" $x3 $y3 $z3 ] set cos_c [ expr { ($l_asq + $l_bsq - $l_csq)/(2*$l_a*$l_b) } ] set angle_c [ expr acos($cos_c) ] puts [ format "Angle (rad) %f" $angle_c] set angle_c [ expr { $angle_c*180.0/(4.0*atan(1.0)) } ] puts [ format "Angle (deg) %f" $angle_c] # End timer set endTime [clock seconds] puts "" puts "Script executed in [expr $endTime-$startTime] seconds, [clock format $startTime -format %H:%M:%S], [clock format $startTime -format %D] "