autolisp draw pline from list of 3d poitns
This Lisp was plant at http://paulbourke.net/geometry/pointlineplane/int2.lsp and has been a great help in 3D and sometimes being off by a little scrap can be very frustrating. You tin can always us the distance command and and so look for the specific X distance or Y distance, but what if the objects are not aligned with your UCS?… That's where this tool really helps. I've tried using the Perpendicular OSNAP from i object and then tried to snap to the 2d object with perpendicular but it wont work (for me) and similar I said, what if the lines are not in a perpendicular airplane
Shown below are 3 lines that are non parallel, nevertheless I want to notice the apparent intersection with a line that represents the distance betwixt the 2 lines.
3D View of Lines
Here's how to apply INT2
INT2 [enter]
Pick two points to define the first line
Pick two points to define the 2nd line
As long as there is a possible intersection, a line will be created.
Thanks to Paul Bourke's website with many mathematical approaches to solving geometrical scenarios: http://paulbourke.net/
~relish
;;; int2.lsp ;;; http://paulbourke.net/geometry/pointlineplane/int2.lsp ;;; Finds the intersection of two non-parallel lines in 2d or 3D, OR the ;;; closest points betwixt the two non-intersecting lines in 3D. ;;; ;;; Based on Algorithm past Paul Bourke / Autolisp version by Andrew Bennett. ;;; ;;; See Paul Bourke's discussion at: ;;; http://local.wasp.uawa.edu.au/~pbourke/geometry/lineline3d/ ;;; Uses algorithm derived from the fact that the closest point betwixt two ;;; lines is a new line perpendicular to both. ;;; ;;; On the XY aeroplane of Autocad'south current UCS, two non-parallel vectors will ;;; ever intersect, therefore the various object snaps (osnap) or ;;; Autolisp'southward (inters) office are all you need. ;;; ;;; Outside the UCS plane in the 3D environment however, these intersection ;;; functions are over precise and tin can hands fail (run across Paul Bourke's ;;; discussion) leaving y'all with no further information. ;;; ;;; Int2.lsp addresses this problem by working as follows: ;;; ;;; As with Autocad/Autolisp, the program will find the intersection betoken ;;; between two (non-parallel) lines in 2D, or if it exists, in 3D. ;;; ;;; In 3D, where in that location may not be a precise intersection, it finds the ;;; closest points between the two lines and draws a new line between them. ;;; ;;; In both cases, the resultant point(south) are prepare past invoking the ;;; Autocad 'Line' control which draws a prophylactic-ring line from the last ;;; point set up to the current cursor position. This feature allows the ;;; intersection/closest bespeak(s) to be clearly visible on screen even if the ;;; point(s) have been set exterior the current drawing window. ;;; ;;; If the two lines are parallel, and so they are as well equidistant, so in that location ;;; is no intersection, and no specific closest point, and then the plan ;;; will end by giving an appropriate informative message. ( defun c:int2 ( / ; local variables used in defun acad_err ; temporary error handler oldsnap ; saved snap settings nearzero ; a very pocket-sized number currentP ; listing containing three reals checkP retn_val ; value returned after defun call getPt_msg ; message string P1 P2 P3 P4 ; xyz coordinate lists (reals) X1 X2 X3 X4 X5 X6 ; x value (real) Y1 Y2 Y3 Y4 Y5 Y6 ; y value (real) Z1 Z2 Z3 Z4 Z5 Z6 ; z value (real) RelX21 RelY21 RelZ21 ; relative ten, y, and z values of P2-P1 RelX43 RelY43 RelZ43 ; P4-P3 RelX13 RelY13 RelZ13 ; P1-P3 dot1343 dot4321 ; dot products of Relative xyz values dot1321 dot4343 dot2121 ; dot products of Relative xyz values denom numer ; denominator & numerator of equation closedist ; closest distance betwixt two lines u21 u43 ; calibration factors line21 or line43 length ) ( init_err ) ; fix temporary mistake handler and save previous organization settings ( setq transp_cmd ( getvar "cmdactive" )) ; Test value ( if ( > transp_cmd 0 ) ; if Autocad commands running ( princ "Plan cannot non be run as a transparent command" ) ;Then Terminate ( progn ; Else continue with the plan ( setvar "cmdecho" 0 ) ; Turn off control prompt ( setq nearzero 0.00001 ) ; a very small-scale number ( setq P1 ( getpt naught "\nLINE From Signal: " ) ;call getpt function P2 ( getpt P1 "\nTo Indicate: " ) P3 ( getpt nothing "\nLINE From Point: " ) P4 ( getpt P3 "\nTo Point: " ) ) ;setq ( setq oldsnap ( getvar "osmode" )) ; bank check & relieve current osnap settings ( setvar "osmode" 0 ) ; before immigration all osnaps ( setq ;; Strip xyz coordinates from lists P1, P2, P3 and P4, assign to variables X1 ( automobile P1) X2 ( car P2) X3 ( car P3) X4 ( auto P4) ; ten value Y1 ( cadr P1) Y2 ( cadr P2) Y3 ( cadr P3) Y4 ( cadr P4) ; y value Z1 ( caddr P1) Z2 ( caddr P2) Z3 ( caddr P3) Z4 ( caddr P4) ; z value ;; Calculate Relative coordinates of XYZ21, XYZ13 and XYZ43 RelX21 ( - X2 X1) RelX43 ( - X4 X3) RelX13 ( - X1 X3) ; rx value RelY21 ( - Y2 Y1) RelY43 ( - Y4 Y3) RelY13 ( - Y1 Y3) ; ry value RelZ21 ( - Z2 Z1) RelZ43 ( - Z4 Z3) RelZ13 ( - Z1 Z3) ; rz value ;; Calculate the various dot products and denominator dot1343 ( + ( * RelX13 RelX43) ( * RelY13 RelY43) ( * RelZ13 RelZ43)) dot4321 ( + ( * RelX43 RelX21) ( * RelY43 RelY21) ( * RelZ43 RelZ21)) dot1321 ( + ( * RelX13 RelX21) ( * RelY13 RelY21) ( * RelZ13 RelZ21)) dot4343 ( + ( * RelX43 RelX43) ( * RelY43 RelY43) ( * RelZ43 RelZ43)) dot2121 ( + ( * RelX21 RelX21) ( * RelY21 RelY21) ( * RelZ21 RelZ21)) denom ( - ( * dot2121 dot4343) ( * dot4321 dot4321)) ) ;setq ( if ( < ( abs denom) nearzero) ; are lines parallel? ;; Display message, exit loop, programme ends ( princ "\nLines Parallel and Equidistant, No intersection point exists" ) ( progn ( setq numer ( - ( * dot1343 dot4321) ( * dot1321 dot4343)) ;; u21 scale factor up line ane to closest betoken to line21 ;; if 0 > u21 < one closest indicate is within line section ;; if u21 < 0 closest point is beyond P1 finish ;; or u21 > 1 closest point is beyond P2 end u21 ( / numer denom) ;; u43 is the calibration factor upwards Line43 and works in the same style equally u21 u43 ( / ( + dot1343 ( * dot4321 u21)) dot4343) X5 ( + X1 ( * u21 RelX21)) Y5 ( + Y1 ( * u21 RelY21)) Z5 ( + Z1 ( * u21 RelZ21)) X6 ( + X3 ( * u43 RelX43)) Y6 ( + Y3 ( * u43 RelY43)) Z6 ( + Z3 ( * u43 RelZ43)) ; Calculate the distance between the points closedist ( distance ( list X5 Y5 Z5) ( list X6 Y6 Z6)) ) ;setq ( if ( < closedist nearzero) ; are points nearly touching? ( progn ;; intersection point found ( princ "\nIntersection, Point set" ) ; print message ( princ ) ; suppress return zippo ( command "line" ( list X5 Y5 Z5)) ; fix point ) ;progn ( progn ;; No intersection indicate constitute, ;; new line will exist drawn at closest point to both lines ; Impress message and length of line department ( princ ( strcat "\nNo intersection, Line drawn at closest signal, Length: " ( rtos closedist))) ( princ ) ; suppress render zip ( control "line" ( list X5 Y5 Z5) ( listing X6 Y6 Z6)) ; gear up a line section ) ;progn ) ;if ) ;progn ) ;if ( reset_err ) ; Restore standard handler and previous system settings ) ;progn ) ;if (Transparent control message) ( princ ) ; suppress return value ) ;defun ;; Uses (getpoint) part to go valid lists of coordinates ;; Uses (initget) role to forbid ENTER existence pressed accidently ;; ;; Syntax (getpt checkP/aught getpt_msg) ;; Parameter listing (checkP getpt_msg currentP retn_val nearzero) ;; ;; (checkP) Coincidence check with previous signal ;; (nada) No coincidence check with previous indicate ;; (getpt_msg) Bulletin to brandish at the Control prompt ;; ;; Returns retn_val to calling function equally list of reals ;; ;; case: ;; ;; (setq P1 (getpt cipher "\nPoint: ") ; returns P1, no coincidence cheque ;; P2 (getpt P1 "\nLINE From Point: ") ; returns P2, bank check with P1 ;; P3 (getpt P2 "\nTo bespeak: ")) ; returns P3, bank check with P2 ( defun getpt (checkP getpt_msg) ( setq currentP zippo) ; initialise currentP ( while ( null currentP) ; start loop ( initget ane ) ; disallows zippo input ( setq currentP ( getpoint getpt_msg)) ; Type/set a valid coordinate ( if ( null checkP) ; Practise/Don't compare with previous indicate ( setq retn_val currentP) ; render currentP to calling function ( progn ( if ( equal checkP currentP nearzero) ; compare with check point ( progn ( princ "\nPoints touch, Do again" ) ; both points set in same identify ( setq currentP nil) ; goose egg currentP to repeat loop ) ; progn ( setq retn_val currentP) ; render currentP to calling function ) ;if ; currentP nil, repeat loop ) ;progn ) ;if ) ; while ; currentP boundp, get out of loop ) ;defun ;;;************************** error trap functions **************************** ;; Role sets up temporary fault handler and saves previous system settings ( defun init_err () (setq acad_err *error*) ; save standard fault handler ( setq *fault* temp_err) ; redirect error call to temporary error handler ( setq oldsnap ( getvar "osmode" )) ; save osnaps, keep them on ( setvar "cmdecho" 0 ) ; turn off command echoing ( princ ) ) ;defun ;; Function invokes temporary fault handler ;; Restores standard handler and previous system settings ( defun temp_err (msg) ( setq transp_cmd ( getvar "cmdactive" )) ; Test value ( if ( > transp_cmd 0 ) ; if Autocad commands running ( command ) ; then cancel them ) ;if ( if ( or ( /= msg "Function cancelled" ) ; if user cancelled ( = msg "quit / get out abort" ) ; or programme aborted ) ;or ( princ ) ; then exit quietly ( princ ( strcat "\nError: " msg)) ; else report error message ) ;if ( setq *error* acad_err) ; restore standard mistake handler ( setvar "osmode" oldsnap) ; restore object snaps ( setvar "cmdecho" 1 ) ; restore control echoing ( princ ) ) ;defun ;; Function restores standard handler and previous settings ( defun reset_err () (setq *error* acad_err) ; restore standard fault handler ( setvar "osmode" oldsnap) ; restore previous osnap settings ( setvar "cmdecho" 1 ) ; restore command echoing ( princ ) ) ;defun ;*********************************************************************** ( princ "int2.lsp loaded. Type INT2 to run program" ) ( princ )
simmonsoppithatione.blogspot.com
Source: https://autocadtips1.com/2014/12/18/autolisp-make-perpendicular-line-between-two-3d-angles/
Post a Comment for "autolisp draw pline from list of 3d poitns"