Jump to content

Recommended Posts

Posted (edited)

Hi Guys!

 

I'm struggling to make my own lisp routine which helps add heights to floor plans. The idea is to read the height difference from the 3D point cloud and present it on the 2D plan.

 

To be honest I don't have excellent skills with programming, backing to 90's I was playing with BASIC on C64 and Amiga 😉 So, please forgive me for my poor code structure..!

 

I'm stuck on the step where I need to round-up figures to 5mm. I have the idea which should resolve this problem but it doesn't work how I wish to and I'm trying to understand what is wrong with my code. I hope you can help or suggest a better solution.

 

The main idea looks simple:

 

Quote

 

(setvar "luprec" 3)

 

(setq pt1 (getpoint))

(setq pt2 (getpoint))

 

(setq z1 (nth 2 pt1))

(setq z2 (nth 2 pt2))

 

(graphscr)

 

(setq val (rtos (- z2 z1)))

 

That works fine, but I need something that will round up my figures so,

I was thinking of doing it in this way:

 

(setq dif (- z2 z1))

 

(setq ma (* dif 100))

(setq mb (* (fix ma) 10))

(setq mc (- (* ma 100) (* mb 100)))

(if (and (>= mc 25) (< mc 75)) (setq md (+ mb 5)))

(if (>= mc 75) (setq md (+ mb 10)))

(setq mat (* md 0.001))

(setvar "luprec" 4)

(setq val (rtos mat))

 

 

 

I try to explain the example step by step (height difference is known):

 

Quote

 

(setvar "luprec" 4) ; Set up the precision

 

(setq dif (- z2 z1)) ; result: dif= 2.4833 (just an example)

 

; Variables design:

     (setq ma (* dif 100)) ; result: ma= 248.33

 

     (setq mb (* (fix ma) 10)) ; result: mb= 2480

 

     (setq mc (- (* ma 100) (* mb 100))) ; result: 24833-24800=33

 

     (if (and (>= mc 25) (< mc 75)) (setq md (+ mb 5))) ; TRUE: if [25>= mc <75] then add 5 to 2480 = 2485

 

     (if (>= mc 75) (setq md (+ mb 10))) ; FALSE: if [75> mc] then add 10 to 2480 = 2490

 

(setq mat (* md 0.001)) ; finally md= 2.485

 

 

 

I'm thinking that range 0.0000-0.0025 shouldn't change the figure, 0.0025-0.0075 should round up to 0.005 and anything above 0.0075 should round up to 0.010.

 

Finally, it doesn't work well...

 

Here you can see the videos:

 

1. Video shows how it works without rounding up:

https://drive.google.com/file/d/1hwmHQWOq0ImuZVFMgEr-KGBmUdIrwwHa/view?usp=sharing

 

2. Video shows the error after implementing my Math:

https://drive.google.com/file/d/16lklDS1AUEtgmvHDnnKPpUHUlNVmVk60/view?usp=sharing

 

I also attached a zip pack with my .lsp file and required blocks.

 

I will be very thankful for any help.

 

Cheers!

 

Krys (maq)

 

 

 

LISP_GSC_hdiff_v1.3__Height difference and floor level reading [HD].zip

Edited by maq
Posted (edited)

I assume your goal is to round up to a multiple of 5. Rem is helpful in rounding up.

 

For example,

(defun c:RoundUp ( / a b  )
(setq a (getreal "\nEnter number: "))
(setq b ( + 5 (- a (rem a 5.))))
(princ "\Rounded up value = ") (princ b)
      (princ)
 )

 

Edited by lrm
  • Like 2
Posted (edited)

Hi Irm,

 

Thanks a lot for your advice, appreciated!

 

I'm going to use it in my code and see how it works together.

 

Edited by maq
Posted (edited)

I can see that your function is rounding up to 5mm in the range 0-4.9 and rounding up to 10mm from 5 to 9.9. 

I think that is not the best way to achieve good accuracy for my purpose...

 

The round-up should be split into two ranges like on the drawing I attached. 

 

What do you think...? 

 

Quote

I'm thinking that range 0.0000-0.0025 shouldn't change the figure, 0.0025-0.0075 should round up to 0.005 and anything above 0.0075 should round up to 0.010.

range2.png

Edited by maq
Posted

Hi Steven P!

 

Thanks for the link.

 

I checked that:

 

Quote

(defun LM:roundm ( n m )

    (* m (fix ((if (minusp n) - +) (/ n (float m)) 0.5)))

)

 

(setq r (LM:roundm  1.2321 0.005)) ; just an example

(princ "\Rounded up value = ") (princ r)

(princ)

 

And looks like it works well! 

 

Still need to implement it to my lisp routine and see how it works together, but for now, looks promising.

 

Thanks a lot!

 

Krys

Posted (edited)

Looks like it works well!

 

Thanks a lot guys!! 🙂 

 

heights.thumb.png.90ba1cb276ee8a3404e8afdf8757c384.png

Edited by maq

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...