Jump to content

lisp drawing line, results are off the precision and lines are 0 length


Recommended Posts

Posted (edited)

Dear forum,

 

I have no idea why my lines have sometimes zero length. The azimuth angles in radians are correct. I belive that the size and distances are big enought and far from 0,0,0. 

still I cant figure out why they are "off". Can somebody tell me why that scripts generates unprecise lines? Thanks in advance

 

prev.thumb.JPG.377895f7262b716dae40b6220643428b.JPG

 

 

(defun round-to-precision (value precision)
  ; Rounds a value to the specified decimal precision
  (setq factor (expt 10.0 precision))
  (/ (atoi (rtos (* value factor) 2 0)) factor)
)

(defun draw-azimuth-line (azimuth length precision)
  ; Calculate endpoints for the azimuth line
  ; First point is at distance 5000 from origin
  (setq end_x (round-to-precision (* 5000.0 (cos azimuth)) precision))
  (setq end_y (round-to-precision (* 5000.0 (sin azimuth)) precision))
  
  ; Second point is at distance 5000+length from origin (in same direction)
  (setq end2_x (round-to-precision (* (+ 5000.0 length) (cos azimuth)) precision))
  (setq end2_y (round-to-precision (* (+ 5000.0 length) (sin azimuth)) precision))
  
  ; Draw the line
  (command "_line" (list end_x end_y 0) (list end2_x end2_y 0) "")
)


    ; Draw lines based on time intervals
    (cond
      ; Main azimuths (every 60 minutes) - 50 unit lines
      ((= (rem i 60) 0) 
       (draw-azimuth-line azimuth 300.0 2))
      
      ; Quarter-hour azimuths (every 15 minutes) - 25 unit lines
      ((= (rem i 15) 0) 
       (draw-azimuth-line azimuth 100.0 2))
      
      ; 5-minute azimuths - 15 unit lines
      ((= (rem i 5) 0) 
       (draw-azimuth-line azimuth 20.0 2))
    )
    

 

 

Edited by Marcin O
remove unnecessary code and attachments
Posted

Have you printed a trace of the values you're getting out of "round-to-precision"?

Posted

Hi
The first thing you should check is whether the lines with length 0 have anything to do with OSMODE: disable the object snap and run the command again to check.

  • Like 2
Posted

@CyberAngel Thank You for suggestion, i don't know how. Sometimes it just says line zero-length and x,y same point coordinate which has a precision of 4digits (0.0000). Angles (azimutes) are fine.

Posted

As Glavcvs suggests, try this:

 

(command "_line" "non" (list end_x end_y 0) "non" (list end2_x end2_y 0) "")

 

where non stops object snaps temporarily. Often a cause for error where it snaps to the wrong thing. My preference is to make entities with the entmake method - objects are placed exactly irrespective of object snaps or grid settings

 

  • Like 1
Posted

@GLAVCVS@Steven P

Thank You for suggestions. You are right , probably that's the issue. I've spent so many hours for try and error. I researched a lot where the issue might be! You've just spot the issue instantly 😱 😱 😱 😱

  • Like 2
Posted

@Marcin O

An example of using entmakex to create the line:
 

;; Change this
(command "_line" (list 10 end_x end_y 0) (list end2_x end2_y 0) "")
;; to this
(entmakex (list '(0 . "LINE") (list 10 end_x end_y 0) (list 11 end2_x end2_y 0)))

 

  • Like 3
Posted

Like others nearly all code I write has a turn off osnaps or set as required within the code . You can see the numbers for osmode by setting your osnaps then just type osmode. I use 47 a lot.

 

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

... lots of code
at end of code
(setvar 'osmode oldsnap)

want user in code to pick an end point 
(setvar 'osmode 1)

pick center of circle
(setvar 'osmode 4)

 

  • Like 1
Posted

adding to BigAl, snap number I use this - but in this case a handy little reference what numbers to use, add the values together to get the setting you want (so snap End Point + Quadrant is 1 + 16 = 17)

 

 

;;Snaps. ( * 1.. to use snap, ( * 0 to turn off snap.
    (setq snaps 0)
    (setq snaps (+ snaps (* 1 0)))	;None
    (setq snaps (+ snaps (* 1 1)))	;End Point
    (setq snaps (+ snaps (* 1 2)))	;Mid Point
    (setq snaps (+ snaps (* 1 4)))	;Centre
    (setq snaps (+ snaps (* 0 8)))	;Node
    (setq snaps (+ snaps (* 0 16)))	;Quadrant
    (setq snaps (+ snaps (* 1 32)))	;Intersection
    (setq snaps (+ snaps (* 0 64)))	;Insertion
    (setq snaps (+ snaps (* 0 128)))	;Perpendicular
    (setq snaps (+ snaps (* 1 256)))	;Tangent
    (setq snaps (+ snaps (* 0 512)))	;Nearest
    (setq snaps (+ snaps (* 0 1024)))	;Geometric Centre
    (setq snaps (+ snaps (* 1 2048)))	;Apparent Intersection
    (setq snaps (+ snaps (* 0 4096)))	;Extrnsion
    (setq snaps (+ snaps (* 0 8192)))	;Parallel
    (setq snaps (+ snaps (* 0 16348)))	;Superess all running snaps
  (setvar 'osmode snaps)

 

Posted
23 hours ago, GLAVCVS said:

Hi
The first thing you should check is whether the lines with length 0 have anything to do with OSMODE: disable the object snap and run the command again to check.

 

OMG, the object snap stays on when you draw with LISP? Well, that explains a problem I used to have.

  • Like 1
Posted
2 hours ago, SLW210 said:

You could use it as part of an error handler as shown by @Lee Mac HERE

 

Here is getting the value and restoring SysVars Saving and Restoring System Variables | AfraLISP

 

Let the Code do the work.

 

That's why I like entmake, don't need to worry about changing system variables and resetting them

Posted

On the curve (everything in the real world is a curve) that represents the advantage/disadvantage between easy and difficult, there's always a tipping point beyond which excessive ease causes more disadvantages than advantages.
Creating polylines with 'command' is an example of this.

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...