Round XYZ by decimal precision

Discussion in 'AutoCAD' started by Marc'Antonio Alessi, Jan 24, 2005.

  1. As many know, the above is a crude method to modify the Z
    coordinates for example to "flatten" objects:

    (command
    "_.MOVE" "_ALL" "" "_NONE" '(0 0 1e99) "_NONE" '(0 0 -1e99)
    "_.MOVE" "_P" "" "_NONE" '(0 0 -1e99) "_NONE" '(0 0 1e99)
    )

    I need a function to correct the value of the X Y Z coordinates
    by a decimal precision and I have found that:

    ; -------------------------------------------------------------

    Command: (setq a (entget (car (entsel))))

    Select objects: ((-1 . <Nome entità: 7eff2630>) (0 . "LINE") (330 . <Nome
    entità: 7efcac10>) (5 . "1D76") (100 . "AcDbEntity") (67 . 0) (410 .
    "Model")
    (8 . "$COM_NORM") (62 . 0) (6 . "ByBlock") (100 . "AcDbLine") (10
    5.68434e-014
    57.0 0.0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0))

    Command: (setq pt1 (cdr (assoc 10 a)))
    (5.68434e-014 57.0 0.0)

    Command: (setq pt2 (cdr (assoc 11 a)))
    (0.0 0.0 0.0)

    Command: (rtos (car pt1) 2 16)
    "0.0000000000000568"

    Command: (rtos (cadr pt1) 2 16)
    "57.00000000003609"

    Command: (rtos (car pt2) 2 16)
    "0"

    Command: (rtos (cadr pt2) 2 16)
    "0"

    Command: (command
    (_> "_.MOVE" "_ALL" ""
    (_> "_NONE" '( 1e15 1e15 1e15) "_NONE" '(-1e15 -1e15 -1e15)
    (_> "_.MOVE" "_P" ""
    (_> "_NONE" '(-1e15 -1e15 -1e15) "_NONE" '( 1e15 1e15 1e15)
    (_> )
    nil

    Command: (setq a (entget (car (entsel))))

    Select objects: ((-1 . <Nome entità: 7eff2630>) (0 . "LINE") (330 . <Nome
    entità: 7efcac10>) (5 . "1D76") (100 . "AcDbEntity") (67 . 0) (410 .
    "Model")
    (8 . "$COM_NORM") (62 . 0) (6 . "ByBlock") (100 . "AcDbLine") (10 0.0 57.0
    0.0)
    (11 0.0 0.0 0.0) (210 0.0 0.0 1.0))

    Command: (setq pt1 (cdr (assoc 10 a)))
    (0.0 57.0 0.0)

    Command: (setq pt2 (cdr (assoc 11 a)))
    (0.0 0.0 0.0)

    Command: (rtos (car pt1) 2 16)
    "0"

    Command: (rtos (cadr pt1) 2 16)
    "57"

    Command: (rtos (car pt2) 2 16)
    "0"

    Command: (rtos (cadr pt2) 2 16)
    "0"

    ; -------------------------------------------------------------

    My question:

    how can I calculate the FuzFac to correct the value of the coordinates
    by a decimal precision:

    (defun ALE_FixPrecsion (DecPrc / FuzFac)
    (setq FuzFac (* DecPrc ???)) ; <<<
    (command
    "_.MOVE" "_ALL" ""
    "_NONE" '(FuzFac FuzFac FuzFac)
    "_NONE" (list (- FuzFac) (- FuzFac) (- FuzFac))
    "_.MOVE" "_P" ""
    "_NONE" (list (- FuzFac) (- FuzFac) (- FuzFac))
    "_NONE" '( FuzFac FuzFac FuzFac)
    )
    )

    --

    Marc'Antonio Alessi
    http://xoomer.virgilio.it/alessi
    (strcat "NOT a " (substr (ver) 8 4) " guru.")

    --
     
    Marc'Antonio Alessi, Jan 24, 2005
    #1
  2. If you mean round up or down a real by a set precision value (e.g., 0.125), then
    you could use this:

    ;; Round a single real up/down to precision point
    ;; ex: (f:rnd -3.7555 0.25) => -3.75
    ;; (note: There are probably more elegant ways of doing this)
    (defun f:rnd (num prec / pos flag fixdn rem1)
    (setq pos (not (minusp num)) ;flag check to see if it's positive
    num (/ (abs num) prec) ;make it positive & divide by precision
    fixdn (float (fix num)) ;round down to nearest whole real
    rem1 (- num fixdn) ;get remainder
    )
    (if (<= 0.5 rem1) ;if remainder greater than 0.5
    (setq num (* (+ num (- 1 rem1)) prec)) ;round up
    (setq num (* fixdn prec)) ;round down
    )
    (if pos ;if original number was positive
    num ;return number
    (- num) ;otherwise return negative
    )
    )


    Then just apply it to a 3D point like this:

    ;;; Return a 3d point or number rounded off in current UCS
    ;;; Point argument can also be single real value
    ;;; Ex: (setq p (getpoint)) => (2961.36 766.296 0.0)
    ;;; (f:rndpt p 0.25) => (2961.25 766.25 0.0)
    (defun f:rndpt (pt prec / x)
    (cond ( (and pt (listp pt))
    (trans
    (mapcar
    '(lambda (x)
    (f:rnd x prec)
    )
    (trans pt 0 1) ;translate pt to current ucs
    )
    1 0 ;translate back result to world
    )
    )
    ( pt (f:rnd pt prec)) ;;if pt arg is a single num
    )
    )

    In this example I round off points relative to the current UCS, but this is up
    to you.

    Matt

     
    Matt Stachoni, Jan 24, 2005
    #2
  3. Thanks for answer.

    What I am looking for is a relationship from
    the value of the coordinate values (plus and minus),
    in the move command, and the number of decimal point
    of rounding precision of the new coordinate
    of the objects.

    This for modify objects with one shoot rather use
    entmod (or activex equivalent) for every object.

    (defun ALE_FixPrecsion (DecPrc / FuzFac)
    (setq FuzFac (* DecPrc ???)) ; <<<
    (command
    "_.MOVE" "_ALL" ""
    "_NONE" '(FuzFac FuzFac FuzFac)
    "_NONE" (list (- FuzFac) (- FuzFac) (- FuzFac))
    "_.MOVE" "_P" ""
    "_NONE" (list (- FuzFac) (- FuzFac) (- FuzFac))
    "_NONE" '( FuzFac FuzFac FuzFac)
    )
    )


    --

    Marc'Antonio Alessi
    http://xoomer.virgilio.it/alessi
    (strcat "NOT a " (substr (ver) 8 4) " guru.")

    --
     
    Marc'Antonio Alessi, Jan 24, 2005
    #3
  4. Instead of moving the objects by some "differential distance" using the MOVE
    command - which might get fuzzy, simply take the important coordinate points of
    the object in question, round up these values, and modify the object with new
    coordinates.

    For example, using (entget) methods, you would take group code 10 and 11 for a
    line entity, round off the coordinates, and (entmod) the resultant data list.
    Similarly, you could update the StartPoint and EndPoint properties using ActiveX
    methods. For arcs, you could round off the center point and radius; for INSERTs,
    roundd off the Insertion Points, and so on.

    Matt

     
    Matt Stachoni, Jan 25, 2005
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.