teknomatika Posted November 23, 2012 Posted November 23, 2012 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) ) Quote
Lee Mac Posted November 23, 2012 Posted November 23, 2012 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))) ) Quote
teknomatika Posted November 23, 2012 Posted November 23, 2012 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! Quote
teknomatika Posted May 23, 2013 Posted May 23, 2013 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. Quote
Lee Mac Posted May 23, 2013 Posted May 23, 2013 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 Quote
teknomatika Posted May 23, 2013 Posted May 23, 2013 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! Quote
Recommended Posts
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.