[racket] Crowdsourcing Pict3D's design

From: Alexander D. Knauth (alexander at knauth.org)
Date: Sun Mar 15 19:38:56 EDT 2015

Does the attached file look like a good implementation of my-point-at, or would it do things I wouldn’t expect for things not on the line between the two points, or ?  I’m asking because I don’t think I completely understand point-at and what it does.  

-------------- next part --------------
A non-text attachment was scrubbed...
Name: my-point-at.rkt
Type: application/octet-stream
Size: 2469 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20150315/ffdbeb7f/attachment-0001.obj>
-------------- next part --------------

On Mar 15, 2015, at 6:29 PM, Alexander D. Knauth <alexander at knauth.org> wrote:

> Thanks!
> 
> Actually, now that I think about it something like this would be really helpful, and probably make more sense:
> Maybe a version of point-at that would let you specify which pos’s should match up where?
> 
> (my-point-at v1 v2 v3 v4 #:normalize? #f)   ; maps v1 to v3 and v2 to v4
> (my-point-at (pos 0 0 0) (pos 1 0 0) v1 v2 #:normalize? #f)   ; maps the origin to v1, and (pos 1 0 0) to v2.
> (my-point-at (pos 0 0 0) (pos 0 0 1) v1 v2)   ; equivalent to (point-at v1 v2)
> (my-point-at v1 dv1 v2 dv2)   ; equivalent to (my-point-at v1 (pos+ v1 dv1) v2 (pos+ v2 dv2))
> 
> On Mar 15, 2015, at 5:58 PM, Neil Toronto <neil.toronto at gmail.com> wrote:
> 
>> I'd generate a few different kinds of segments and then transform them into place. Don't use `rotate` for that, though - there's an easier way.
>> 
>> Transforming a shape is pretty fast. Here's an insane example, using many more segments for a cylinder than you'd normally ever need:
>> 
>> 
>> #lang racket
>> 
>> (require pict3d)
>> 
>> (define v1 (pos 1 1 1))
>> (define v2 (pos 2 3 2))
>> (define cyl
>> (time
>>  (with-color (rgba "lightblue")
>>    ;; WOO 65536 TRIANGLES YEAH
>>    (move-z (cylinder origin (dir 1/4 1/4 1/2) #:segments 16384)
>>            1/2))))
>> 
>> (define pict
>> (time
>>  (combine (sphere v1 0.2)
>>           (sphere v2 0.2)
>>           (transform cyl (point-at v1 v2 #:normalize? #f)))))
>> 
>> (time (pict3d->bitmap pict))
>> (time (pict3d->bitmap pict))
>> 
>> 
>> On my computer, creating `cyl` takes 5 seconds. Transforming it takes no measurable time. Rendering it the first time takes 1.5 seconds, and rendering it the second time takes 11 milliseconds. (Cylinders are frozen, so they'll always render faster the second time.)
>> 
>> To stretch the cylinder between two points, the program
>> 
>> 1. Creates the cylinder so that its bottom is at the origin and its
>>   top is at (pos 0 0 1).
>> 
>> 2. Uses `point-at` without normalization to move the origin to `v1` and
>>   move (pos 0 0 1) to `v2`.
>> 
>> Based on this and your other feedback, I think Pict3D needs
>> 
>> * A `rotate-around` function that rotates a shape around a given point
>>  (with the default being the center of its bounding box).
>> 
>> * A note in the docs for `rotate` et al that explain they rotate around
>>  the origin.
>> 
>> * A "How Do I" section that includes things like the above example.
>> 
>> * Notes in the docs about performance characteristics of different
>>  functions (e.g. that `cylinder` and `cone` return frozen Pict3Ds, and
>>  what that means you can expect from them).
>> 
>> I expect performance characteristics to change, though, so that last one might be late coming.
>> 
>> Neil ?
>> 
> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users


Posted on the users mailing list.