russell84 Posted August 29, 2008 Share Posted August 29, 2008 hey guys if i have 2 pts stored in lisp $P1 and $P2 how do i get the midpoint of those pts?? i have the below lisp that i'm trying to edit write to suite us..was originally written by a guy here but i want to show the details between the 2 points. I want to show a line between the two points and on that line i want to show the slope, distance and direction by use of a arrow. Would someone please be able to help me with the info part. I have got the line and cross to work so far. You will see what i mean. Thank you (defun C:EXTRA () (setq oldlay (getvar "clayer")) ; ################# Gather Info ################# ; (initget 1) (setq $P1 (getpoint "\nSTARTING POINT: ")) (initget 1) (setq $L1 (getreal " - - LEVEL: " )) (setq $P1 (reverse (cdr (reverse $P1)))) ; remove Z coordinate (if $GR (progn (setq $OGR $GR $GR nil) (setq $GR (getreal (strcat "\nGradient % <" (rtos $OGR 2) ">: " ))) (if (= $GR nil)(setq $GR $OGR)) );progn (progn (setq $GR nil) (setq $GR (getreal "\nGradient % <1>: " )) (if (= $GR nil)(setq $GR 1.0)) );progn );if (initget 1) (setq $P2 (getpoint $P1 "\nProjected Point: ")) ; ; ################# Calculation ################# ; (while $P2 (setq $D1-2 (distance $P1 $P2)) (if (= units 1000.0) (setq $DIFF (/ (* $D1-2 (/ $GR 100.0)) 1000.0)) (setq $DIFF (* $D1-2 (/ $GR 100.0))) ) (setq $LUP (+ $l1 $DIFF)) (princ (strcat "\n.. START PT RL = " (rtos $L1 2 3) "m")) (princ (strcat " ..SLOPE BETWEEN PTS = " (rtos $GR 2 3) "%")) (princ (strcat "\n.. DIST BETWEEN PTS = " (rtos $D1-2 2 3) "m")) (princ (strcat ".. HEIGHT DIFF = " (rtos $DIFF 2 3) "m")) (princ (strcat "\n.. EXTRAPOLATED RL IS = " (rtos $LUP 2 3) "m")) (setq INSRL (getstring "\nINSERT RL CROSS? Y/N <N>: ")) (if (/= INSRL "")(setq INSRL (strcase (substr INSRL 1 1)))) (if (= INSRL "Y") (PROGN (SETVAR "ATTDIA" 0) (SETVAR "INSUNITS" 0) (setq insscl (* 1 (getvar "dimscale"))) (COMMAND "-LAYER" "M" "RLCROSS" "C" 2 "" "") (COMMAND "-insert" "RLCROSS" "_S" insscl $P2 "0" (rtos $LUP 2 3)) (command "-layer" "M" "VP" "C" "6" "VP" "P" "N" "VP" "" "line" $P1 $P2 "") (setvar "clayer" oldlay) (SETVAR "ATTDIA" 1) ) ) (setq $P2 (getpoint $P1 "\nProjected Point: ")) );while (princ) ); defun EXTRA You will also need the attached DWG of the rl to be within your acad search path. Thnak guys RLCROSS.dwg Quote Link to comment Share on other sites More sharing options...
alanjt Posted August 29, 2008 Share Posted August 29, 2008 setq a new point with this sub: ;(mid3dpt pt1 pt2) (defun mid3dpt (pt1 pt2 /) (setvar "lastpoint" (mapcar '+ pt1 (mapcar '/ (mapcar '- pt2 pt1) '(2.0 2.0 2.0)) ) ) "@" ;;;; will display "@" after midpoint is calced, remove this line to display coordinates of calced midpoint ) (setq $p_mid (mid3dpt $p1 #p2)) Quote Link to comment Share on other sites More sharing options...
CAB Posted August 29, 2008 Share Posted August 29, 2008 Another method: ;; Returns the middle of two points (defun mid-pt (p1 p2) (polar p1 (angle p1 p2) (/ (distance p1 p2) 2.) ) ) 1 Quote Link to comment Share on other sites More sharing options...
russell84 Posted August 30, 2008 Author Share Posted August 30, 2008 nice couple of methods guy. thanks for your help. one quick one how do you get an offset point fom the mid point if i wanted to insert some text say 2.5 x dimscale offset from the midpoint Quote Link to comment Share on other sites More sharing options...
VovKa Posted August 30, 2008 Share Posted August 30, 2008 And another another method (defun GetMidPoint (p1 p2) (mapcar (function (lambda (e1 e2) (/ (+ e1 e2) 2.))) p1 p2) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 23, 2008 Share Posted October 23, 2008 how do you get an offset point fom the mid point if i wanted to insert some text say 2.5 x dimscale offset from the midpoint Try this maybe: (defun c:txtoff (/ offs l1 l1ent p1 p2 l1ang txt txtpt txtpt1) (setq offs (getreal "\nSpecify Offset Distance: ")) (while (/= (setq l1 (car (entsel "\nSelect Line for Text: "))) nil) (setq l1ent (entget l1)) (setq p1 (cdr (assoc 10 l1ent))) (setq p2 (cdr (assoc 11 l1ent))) (setq l1ang (angle p1 p2)) (setq txt (getstring t "\nSpecify Text: ")) (setq txtpt (polar p1 l1ang (/ (distance p1 p2) 2) ) ; end polar ) ; end setq (setq txtpt1 (polar txtpt (+ l1ang (/ pi 2)) offs ) ; end polar ) ; end setq (entmake (list '(0 . "TEXT") '(8 . "TEXT") (cons 10 txtpt1) (cons 40 (* 2.5 (getvar "DIMSCALE"))) (cons 1 txt) (cons 50 l1ang) '(7 . "STANDARD") '(71 . 0) '(72 . 1) '(73 . 2) (cons 11 txtpt1) ) ; end list ) ; end entmake ) ; end while (princ) ) ; end program Quote Link to comment Share on other sites More sharing options...
Soumen Posted July 4, 2021 Share Posted July 4, 2021 There are say, 50 points with diferrent x,y in my screen. First step : I want to indicate the points from which mid points will be measured. Second step: I need to define a search radius; a circle can be imagined from those selected points in step 1 Third: within that circle i need to idntify other points with x,y and created mid points from that selected points for each pair These mid points can be joined by a closed polygon. Can anyone help please? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.