Plot doesn't have parametric 3D surfaces yet because they can contain arbitrarily large, arbitrarily close, or intersecting polygons. Plot's current 3D engine sorts polygons wrongly when they're not in a grid or are too close together, and it never draws intersecting polygons right.

The upcoming release's Plot has a 3D engine that can handle anything, but we've just created a release branch, which I can't add features to. I'll add `parametric-surface3d' to the master branch soon, though, so it'll be available in the nightly builds and in the release after next.

FWIW, doing parametric surfaces well could be a little trickier than it seems. For example, when rendering a sphere, it might be desirable to sample theta more coarsely when phi is near -pi/2 or pi/2 (i.e. the poles). I'm not sure how to handle this yet, but the first thing that occurs to me is making one variable's range and sampling density a function of the value of the other. I'm open to suggestions.

It might be time to take another look at Jens Axel's ideas for adaptive sampling, now that Plot can do it in 3D without b0rking it.

Neil ⊥

On 04/11/2014 02:17 PM, Alexander D. Knauth wrote:
Is there something for plotting 3D parametric surfaces? (where there are two 
parameters instead of one)

If there is, then I would do something like this:
(define (sphere3d ctr-x ctr-y ctr-z r #:color color)
   (parametric-surface3D (lambda (theta phi) ; theta and phi are the parameters
                                          (let* ([z (* r (sin phi))]
                                                   [√x^2+y^2 (sqrt (- (sqr r) 
(sqr z)))]
                                                   [x (* √x^2+y^2 (cos theta))]
                                                   [y (* √x^2+y^2 (sin theta))])
                                             (vector x y z)))
                                        (list (list 0 (* 2 pi)) ; theta goes 
from 0 to 2pi
                                              (list (- (/ pi 2)) (/ pi 2))) ; 
phi goes from -pi/2 to pi/2
                                        #:color color))

I looked at the documentation already and didn’t find it, but is there 
something that can do that, maybe in a different place?

I saw parametric3d, but that looks like it only does one parameter, so it can 
only do lines.

If there isn’t, is there a way to define something like a parametric-surface3d?
Maybe something like this:
(define (parametric-surface3d f mins-and-maxes #:x-min [x-min #f] …)
   (match mins-and-maxes
     [(list (list u-min u-max) (list v-min v-max))
      (…
             (for*/list ([u-value (in-range u-min u-max ∆u)]
                           [v-value (in-range v-min v-max ∆v)])
                 (…
                        (f u-value v-value)
                  …))
        …)]))
Where u and v are the parameters, u-min and u-max are the min and max of u, 
v-min and v-max are the min and max of v, and the function f is applied to the 
parameters like this: (f u-value v-value), and returns a (sequence-of real?) 
just like in parametric3d.

f: (real? real? . -> . (sequence-of real?)
mins-and-maxes: (listof (list/c real? real?))

Maybe a more general version could deal with any number of parameters (thats 
why I wanted to put them in one mins-and-maxes argument instead of having 
separate arguments for each min and max.

But I have no idea how to define something like this.

On Apr 10, 2014, at 11:27 PM, Neil Toronto <[email protected]> wrote:
(define (sphere3d x0 y0 z0 r color)
  (isosurface3d (λ (x y z) (sqrt (+ (sqr (- x0 x))
                                    (sqr (- y0 y))
                                    (sqr (- z0 z)))))
                r (- x0 r) (+ x0 r) (- y0 r) (+ y0 r) (- z0 r) (+ z0 r)
                #:line-style 'transparent
                #:color color))


____________________
 Racket Users list:
 http://lists.racket-lang.org/users

Reply via email to