Jump to content

Recommended Posts

Posted

This is what i found with google, and i added random colours for points - and it doesn't work... help! What's wrong?

 



(defun randnum (/ modulus multiplier increment random)
 (if (not seed)
     (setq seed (getvar "DATE")))
 (setq modulus    65536
    multiplier    25173
     increment    13849
       seed       (rem (+ (* multiplier seed) increment) modulus)
       random     (* 1 (/ seed modulus))))




(defun rangd (/ ); = Random ANGle, Degrees
 ;; takes last 6 digits of DATE System Variable, moves last one
 ;; [which changes fastest] to front for greater randomization
 ;; at close-together calls, makes 6-digit decimal between 0 & 1
 ;; of that, multiplies x 360 degrees
 (setq digits (substr (rtos (rem (getvar 'date) 1) 2 16) 13))
 (* (atof (strcat "0." (substr digits 6) (substr digits 1 5))) 1)
); end defun


(defun C:RPS (/ cmd num rad orig); = Random Points on a Sphere
 (command "_.ucs" "_del" "RPStemp")
 (command "_.ucs" "_world")
 (setq cmd (getvar 'cmdecho))
 (setvar 'cmdecho 0)
 (command
   "_.undo" "_begin"
   "_.ucs" "_save" "RPStemp"
 ); end command
 (setq
   num (getint  "Number of points: ")
   rad (getdist "Radius of sphere: ")
   orig (getpoint "Center of sphere: ")
 ); end setq
 (command "_.ucs" "_origin" orig)
 (repeat num
   (command
     "_.ucs" "_X" (* 360 (rangd))
     "_.ucs" "_Y" (* 360 (rangd))
     "_.ucs" "_Z" (* 360 (rangd))
   ); end command
   (setq col (abs(fix (* 256 (rangd)))))       
   (command "-color" col)  
   (entmake
     (list
       '(0 . "POINT")
       (cons 10 (trans (polar (trans orig 0 1) 0 rad) 1 0))
     ); end list
   ); end entmake
 ); end repeat
 (command
   "_.ucs" "_restore" "RPStemp"
   "_.ucs" "_del" "RPStemp"
   "._undo" "_end"
 ); end command
 (setvar 'cmdecho cmd)
 (princ)
); end defun

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    9

  • pBe

    9

  • brams

    9

  • MSasu

    7

Top Posters In This Topic

Posted Images

Posted

It works on my stations - the points are equally distanced from selected center, so they lay on a sphere; also the colors seems to follow a quite random pattern.

What I suspect is that the color issue is related to the speed of your workstation; to rely on computer's clock to get random numbers on a powerful station isn't very reliable since then you will not got truly random numbers - please check the example below:

(repeat 10 (princ (strcat "\n" (rtos (rangd) 2 5))))

You may check on Forum for a better random generator (it was a similar thread not long ago) or can add a delay between point generations.

Posted

this is what i get : Invalid color number.

; error: Function cancelled

strange...

Please try with ...10000 points

Posted

perhaps change the pdmode to 3 so you can see the points brams :)

Posted

Is working a little... for few times i succeed to put 5000 points...then error

Posted

Maybe add a protection to don't get unsupported color indexes?

[color=red](setq col 0)[/color]
[color=red](while[/color] [color=red](or (= col 0) (> col 256))[/color] (setq col (abs (fix (* 256 (rangd)))))[color=red])[/color]

Posted

oh... silly me

 

 

(setq color [b][color=blue](_col rangd))[/color][/b]

 

 (defun _col (ran)
     (setq c (abs(fix (* 256 (ran)))))
       (if (< 0 c 256) c (_col ran)))

Posted

Now is working, Pbe. Why not before, with (rangd) ?

Posted

as noted by MSasu if varaible color value is not within the valid range of 1-255 (ACI) it will not recognize that value and the command color will generate an error

Posted

(rangd) has value between 0 and 1,then i multiply with 256, i use abs. and fix - how can be out of range 1- 256?

Posted

How can i make a cube instead of sphere? :)

Posted (edited)

for example when its "0" , try assigning color 0

(command "_color" 0)

 

BTW: where dd you get theat cool routine?

 

EDIT: i did not really test rangd value if it ever exceeds 255 after evaluation .. but the snippet we posted will prevent that anyway.

Edited by pBe
Posted
(rangd) has value between 0 and 1,then i multiply with 256, i use abs. and fix - how can be out of range 1- 256?

Since may generate a 0 value.

Posted
How can i make a cube instead of sphere? :)

 

Now you're pushing your luck brams :lol:

 

I would suggest you contact the original author to do just that. he probably have one by now.

 

Cheers

Posted

You may also want to take a look to a better random numbers generator - check post #6 from this thread.

Posted
How can i make a cube instead of sphere? :)

For sure that is possible to distribute the points on the faces of a cube – you should draw one face at a time, generate randomly X and Y coordinates pairs around the “center” of the face and validate their location to don’t exceed the limits of the face (should account for half of cube's edge and the cosines of the angle between “center” and current point).

(<= (distance pointCenter
             pointRandom)
   (/ (* 0.5 edgeSquare)
      (cos (angle pointCenter 
                  pointRandom))))

Posted

Did you test your theory yet MSasu? It would be intersting to see how it works. sine/cosines makes my head spin so bad i wont even try. ;)

Posted

If I will have time this evening, maybe I will try to write one. The validation should be refined to account for points located on the same vertical with the “center”:

(setq theAngle (angle pointCenter 
                          pointRandom))
(<= (distance pointCenter
             pointRandom)
   (/ (* 0.5 edgeSquare)
      (if (member theAngle (list (* 0.5 pi)
                                 (* 1.5 pi)))
       1.0
       (abs (cos theAngle)))))

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