Cylinder operation

22 views
Skip to first unread message

Loïc Fejoz

unread,
Jan 24, 2015, 1:03:28 PM1/24/15
to ic...@googlegroups.com
Bonsoir,

Cylinder and cone operations are not consistent with the others. Indeed they are not centered on origin and thus need translation before rotation.

Moreover, it could be nice to enhance the language by predefining some attributes.

For instance, It would be nice to do that:

c = cylinder(2, 5)
emit(translate(c.bottom_center_to_origin) * c)


It requires:

function my_cylinder(r, h)
   c = translate(0, 0, -h/2) * cylinder(r, h)
   c.center = v(0, 0, 0)
   c.bottom_center_to_origin = v(0,0, h/2)
   c.top_center_to_origin = v(0,0, -h/2)
   c.radius = r
   c.height = h
   return c
end


More generally exploiting Lua's objects implementation can lead to a more descriptive language.
What do you think?

Cordialement,

sylefeb

unread,
Jan 24, 2015, 5:46:11 PM1/24/15
to ic...@googlegroups.com
Bonsoir Loic,

Unsure I would say they are 'inconsistent'; but cone and cylinder are indeed both defined with their base on the origin, box is centered while cornerbox has its min corner at 0,0,0.
We can very easily add other cone/cylinder primitves that would be centered, I wonder what would be a good name? ccone/ccylinder?

There are many cases where one approach (centered) is more convenient than the other (not centered) and vice-versa. We could improve naming and add primitives, but not at the cost of breaking existing scripts.

About attributes: let me think about this. I know this seems a good idea, but I like the fact that the script is only made of transforms and shapes (box/cylinder/etc.) which have no specialized types. Also, the current language prevents an object to be modified after its creation, which has advantages.


sylefeb

unread,
Jan 24, 2015, 6:03:26 PM1/24/15
to
Hmm, maybe something like:
on origin: ocone, ocylinder, obox
centered: ccone, ccylinder, cbox

and then we'd have (for backward compatibility reasons):
box = cbox
cornerbox = obox
cone = ocone
cylinder = ocylinder

(edit: we can also use cube instead of box for the new naming, and have cube=ocube, which makes all the default names be 'on origin')

Loïc Fejoz

unread,
Jan 25, 2015, 3:51:13 AM1/25/15
to ic...@googlegroups.com
Bonjour,

Well, reading again Bret Victor [1] might be interesting to decide upon. Probably, I would prefer to go this way which should be more explicit on reading but longer to write:

cylinder{r=3, h=20, centered=true}

I do agree with you, following principles from other talks of Bret Victor, that It is better to have immutable objects. Still having access to read-only attributes could be nice. I would even go further by being able to do that:

c = translate(10, 0, 0) * cylinder{r=3, h=20, centered=false}
foobar(c.top_center)

Here c.top_center would evaluate to v(10, 0, 20)!
It enables script to be more descriptive on the intent instead of the construction.

[1] http://worrydream.com/#!/LearnableProgramming


What do you think?

Cordialement,
Loïc
Reply all
Reply to author
Forward
0 new messages