Jump to content

Recommended Posts

Posted

Lee,

I changed the routine to also draw the points so random in the plane Z.

My question is whether the variable range is well stated.

 

(defun pointsphere (c r / a b p )

(setq a (acos (1- (* 2.0 (LM:rand))))
         b (* (LM:rand) (+ pi pi))
	  ;;p (list (* r (sin a) (cos b)) (* r (sin a) (sin b)) 0.0);;original 2d points;;
         [color="red"]p (list (* r (sin a) (cos b)) (* r (sin a) (sin b)) (fix (1+ (* (LM:rand)range))));;change to 3d points[/color]
   )
   (entmake
       (list
          '(0 . "POINT")
           (cons 010 (mapcar '+ c p))
           (cons 062 (fix (1+ (* (LM:rand) 254))))
           (cons 210 p)
       )
   )
)

;; Rand  -  Lee Mac
;; PRNG implementing a linear congruential generator with
;; parameters derived from the book 'Numerical Recipes'

(defun LM:rand ( / a c m )
   (setq m   4294967296.0
         a   1664525.0
         c   1013904223.0
         $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
   )
   (/ $xn m)
)

;; ArcCosine  -  Lee Mac
;; Args: -1 <= x <= 1

(defun acos ( x )
   (if (<= -1.0 x 1.0)
       (atan (sqrt (- 1.0 (* x x))) x)
   )
)

(defun c:cirp ( / [color="red"]range[/color] c r x )
       
(if
       (and
           (setq x (getint "\nNumber of Points: "))
           (setq c (getpoint "\nCenter: "))
           (setq r (getdist  "\nRadius: " c))
		[color="red"](setq range (getint "\nRange Z Coords : "))[/color]
       )
	 (repeat x (pointsphere (trans c 1 0) r))
   )
   (princ)
)

  • 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
I changed the routine to also draw the points so random in the plane Z.

 

The points were already 3D, represented by spherical coordinates; you can vary the radius to generate random points inside the sphere:

 

    (setq a (acos (1- (* 2.0 (LM:rand))))
         b (* (LM:rand) (+ pi pi))
[color=red]          r (* (LM:rand) r)[/color]
         p (list (* r (sin a) (cos b)) (* r (sin a) (sin b)) (* r (cos a)))
   )

Posted
The points were already 3D, represented by spherical coordinates; you can vary the radius to generate random points inside the sphere:

 

    (setq a (acos (1- (* 2.0 (LM:rand))))
         b (* (LM:rand) (+ pi pi))
[color=red]          r (* (LM:rand) r)[/color]
         p (list (* r (sin a) (cos b)) (* r (sin a) (sin b)) (* r (cos a)))
   )

 

Lee,

Ah, ok. Had not seen this possibility.

However, my change corresponds to that i need: A definition of the maximum value of Z coordinates, and that the final result is in the form of a circular slice.

 

Tanks again!

  • 6 months later...
Posted
The points were already 3D, represented by spherical coordinates; you can vary the radius to generate random points inside the sphere:

 

    (setq a (acos (1- (* 2.0 (LM:rand))))
         b (* (LM:rand) (+ pi pi))
[color=red]          r (* (LM:rand) r)[/color]
         p (list (* r (sin a) (cos b)) (* r (sin a) (sin b)) (* r (cos a)))
   )

 

Lee, greetings.

if possible, when you have availability, I would be grateful if you could integrate in this routine an option to be able to draw in a rectangular shape.

Thank you.

I'll be waiting.

Posted
an option to be able to draw in a rectangular shape.

 

Simply generate random points in all three axes:

(defun c:test ( / d n x y z )
   (if
       (and
           (setq n (getint "\nNumber of Points: "))
           (setq d (getcorner '(0.0 0.0) "\nSpecify Base Dimensions: "))
           (setq z (getdist   '(0.0 0.0) "\nSpecify Height: "))
           (setq x (abs (car  d))
                 y (abs (cadr d))
           )
       )
       (repeat n (randrect x y z))
   )
   (princ)
)

(defun randrect ( x y z )
   (entmake (list '(0 . "POINT") (list 10 (* (LM:rand) x) (* (LM:rand) y) (* (LM:rand) z))))
)

;; Rand  -  Lee Mac
;; PRNG implementing a linear congruential generator with
;; parameters derived from the book 'Numerical Recipes'

(defun LM:rand ( / a c m )
   (setq m   4294967296.0
         a   1664525.0
         c   1013904223.0
         $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
   )
   (/ $xn m)
)

 

I'm sure you could have worked this out ;)

Posted
Simply generate random points in all three axes:

(defun c:test ( / d n x y z )
   (if
       (and
           (setq n (getint "\nNumber of Points: "))
           (setq d (getcorner '(0.0 0.0) "\nSpecify Base Dimensions: "))
           (setq z (getdist   '(0.0 0.0) "\nSpecify Height: "))
           (setq x (abs (car  d))
                 y (abs (cadr d))
           )
       )
       (repeat n (randrect x y z))
   )
   (princ)
)

(defun randrect ( x y z )
   (entmake (list '(0 . "POINT") (list 10 (* (LM:rand) x) (* (LM:rand) y) (* (LM:rand) z))))
)

;; Rand  -  Lee Mac
;; PRNG implementing a linear congruential generator with
;; parameters derived from the book 'Numerical Recipes'

(defun LM:rand ( / a c m )
   (setq m   4294967296.0
         a   1664525.0
         c   1013904223.0
         $xn (rem (+ c (* a (cond ($xn) ((getvar 'date))))) m)
   )
   (/ $xn m)
)

 

I'm sure you could have worked this out ;)

 

Lee,

I am most grateful for more this.

Even tried to get a solution, but my knowledge is still basic. But slowly ....

Tanks!

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