Message Boards Message Boards

Coke bottles from piecewise-defined functions

Posted 8 years ago

Coke bottles 2016, created with #Wolfram #Mathematica by my 18-years-old calculus students as the solution to the exercise in this link Coke exercise in Mathematica

Coke1 Coke 2 Coke 3 Coke 4

EDIT: I have attached the notebook of the activity. Actually Mathematica is so powerful that the code is very simple: here I will write some of it from the end of the attached notebook, where I show how to create a chess piece as a solid of revolution. After that if you want to reproduce one of the cokes from my students, you just have to change the content of the piecewise function below with one of the piecewise functions that are shown in the JPG images in my original post. First, here it is the simplest way to create a solid of revolution that looks like a chess piece:

peon[x_] := Piecewise[{
{1 - x/2, 0 < x < 1},
{1/2, 1 < x < 3},
{3/4 - (x - 7/2)^2, 3 < x < 4}
}];
RevolutionPlot3D[{peon[y], y}, {y, 0, 4}, PlotRange -> All]

Now, when doing their coke, many students like to put an image around it. In order to put an image around the chess piece, asuming that you have a file called "lenna.jpg" in the directory of your computer that you obtain from evaluating the command Directory[], and after evaluating the previous code, you can wrap the image around the chess piece with this code:

imagen = Import["lenna.jpg"];
RevolutionPlot3D[{peon[y], y}, {y, 0, 4.05}, 
PlotStyle -> Texture[imagen], Mesh -> None]

On the other hand, if you prefer to have a transparent solid of revolution, you can use the following code after evaulating the first one where the function peon was defined:

RevolutionPlot3D[{peon[y], y}, {y, 0, 4.05}, 
 PlotStyle -> Opacity[0.7], Mesh -> None]

Have fun!

Attachments:
POSTED BY: Jose Gomez
5 Replies

It might be good to make that available as a WL notebook. Much easier to use in that form.

POSTED BY: Daniel Lichtblau
Posted 8 years ago

Yes Daniel, but I give it to my students the PDF instead of a notebook on purpose, this is the reason: Since for most of them this is the very first time they use Mathematica, I want them to type everyhting (copy-paste does not work well from PDF for Mathematica code) and therefore they learn about interacting with the front-end and using the Wolfram Language. They reproduce the examples in the PDF in about one and a half hour, after that the coke is the homework, they have one week to finish it. Some of my students use several hours of that week in order to obtain a good coke.

POSTED BY: Jose Gomez

But this forum is full of programmers. What if someone would like to just play or modify your code? Or some teacher on this forum would like to use your lesson? How can I appreciate fully your nice work, if I cannot evaluate it? Is there a reason not to attach both PDF and Notebook?

POSTED BY: Sam Carrettie
Posted 8 years ago

Sam, I have attached the notebook, and also edited the original post to include the code. Have fun!

POSTED BY: Jose Gomez
Posted 8 years ago

Daniel, I have attached the notebook, and also edited the original post to include the code. Have fun!

POSTED BY: Jose Gomez
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract