0
|
8268 Views
|
9 Replies
|
5 Total Likes
View groups...
Share

# How do I map a texture onto a plotted surface?

Posted 9 years ago
 Here's an equation for a half-ellipsoid in Cartesian coordinates, with the result limited to real numbers. . a := 3 b := 2 c := 3 rest := x^2/a^2 + y^2/b^2 f[x_, y_] := Re [c*(1 - rest )^0.5] g[x_, y_] := If[f [x, y] < 0, 0, f[x, y]] Plot3D[g[x, y], {x, 4, -4}, {y, 4, -4}]  I need to place a texture on that ellipse and plane using a local .jpg file (rectangular .jpg image). The file is: c:/kah320x480.jpg. No luck so far. I want the rectangular image file to map on the ellipse as well as out over the plane.
9 Replies
Sort By:
Posted 9 years ago
 Ok, I found out where to put my jpg. photos. and how to import them. But when I copy the Texture code from the documentation tp Plot3D, nothing happens. The photo file I'm trying to map is attached...  a := 3 b := 2 c := 3 rest := x^2/a^2 + y^2/b^2 f[x_, y_] := Re [c*(1 - rest )^0.5] g[x_, y_] := If[f [x, y] < 0, 0, f[x, y]] Import ["kah320x480.jpg"] Plot3D[g[x, y], {x, 4, -4}, {y, 4, -4}, SphericalRegion -> True, Mesh -> None, Plot Style -> Texture[ExampleData[{Import["kah320x480.jpg"}]]], Plot3D::nonopt: Options expected (instead of Plot Style->Texture[Import[kah320x480.jpg]]) beyond position 3 in Plot3D[g[x,y],{x,4,-4},{y,4,-4},SphericalRegion->True,Mesh->None,Plot Style->Texture[Import[kah320x480.jpg]],Lighting->Neutral "]. An option must be a rule or a list of rules. \!$$\*ButtonBox[\">>\", Appearance->{Automatic, None}, BaseStyle->\"Link\", ButtonData:>\"paclet:ref/message/General/nonopt\", ButtonNote->\"Plot3D::nonopt\"]$$" Attachments:
Posted 9 years ago
 Hi,your code nearly works. There is a small change requited. ExampleData is not needed. Substitute the plot function by: Plot3D[g[x, y], {x, 4, -4}, {y, 4, -4}, SphericalRegion -> True, Mesh -> None, PlotStyle -> Texture[Import["~/Desktop/kah320x480.jpg"]]] where you might wish to adapt the path to the file. Cheers,Marco
Posted 9 years ago
 Sorry, I forgot to format the code. Here's the corrected post.. a := 3 b := 2 c := 3 rest := x^2/a^2 + y^2/b^2 f[x_, y_] := Re [c*(1 - rest )^0.5] g[x_, y_] := If[f [x, y] < 0, 0, f[x, y]] Plot3D[g[x, y], {x, 4, -4}, {y, 4, -4}, SphericalRegion -> True, Mesh -> None, Plot Style -> Texture[{"kah320x480"}], Lighting -> "Neutral"] error listing: lot3D::nonopt: Options expected (instead of Plot Style->Texture[{kah320x480 }]) beyond position 3 in Plot3D[g[x,y],{x,4,-4},{y,4,-4},SphericalRegion->True,Mesh->None,Plot Style->Texture[{kah320x480 }],Lighting->Neutral "]. An option must be a rule or a list of rules. \!$$\*ButtonBox[\">>\", Appearance->{Automatic, None}, BaseStyle->\"Link\", ButtonData:>\"paclet:ref/message/General/nonopt\", ButtonNote->\"Plot3D::nonopt\"]$$" I read the tutorial on how to import .jpegs. However, those instructions didn't have any information on where to initially put the .jpeg in my file system, in order to import it, or where it went after it was imported, or how to get it mapped to the surface. The Texture function docs didn't have any examples of how to apply a texture on a Plot3D.
Posted 9 years ago
 Then perhaps this will be useful: Insert a File Path. BTW the Texture function docs does have many examples of Plot3D usage (for example) - are you opening all collapsed sections?
Posted 9 years ago
 Very nice! I have a .jpg photograph that I want to map to the ellipse/plane surface. The name of the file is "kah320x480". In what folder do I put the texture file, and how do I get it to map? I have tried several different options... a := 3 b := 2 c := 3 rest := x^2/a^2 + y^2/b^2 f[x, y] := Re [c*(1 - rest )^0.5] g[x, y] := If[f [x, y] < 0, 0, f[x, y]]Plot3D[g[x, y], {x, 4, -4}, {y, 4, -4}, SphericalRegion -> True, Mesh -> None, Plot Style -> Texture[{"kah320x480"}], Lighting -> "Neutral"] <<<>>> error listing: lot3D::nonopt: Options expected (instead of Plot Style->Texture[{kah320x480 }]) beyond position 3 in Plot3D[g[x,y],{x,4,-4},{y,4,-4},SphericalRegion->True,Mesh->None,Plot Style->Texture[{kah320x480 }],Lighting->Neutral "]. An option must be a rule or a list of rules. \!(*ButtonBox[\">>\", Appearance->{Automatic, None}, BaseStyle->\"Link\", ButtonData:>\"paclet:ref/message/General/nonopt\", ButtonNote->\"Plot3D::nonopt\"])"
Posted 9 years ago
 Skip, do you notice your code looks different than Marco's and Vitaliy's ? You should use code-blocks for formatting code, it is hard to read and copy code in your posts. This tutorial tells you how.Also you should read up on how to import images into Mathematica, for example: JPEG.
Posted 9 years ago
 Did you go through Texture examples in documentation? I do not see in your code any attempt to use Texture function. a := 3 b := 2 c := 3 rest := x^2/a^2 + y^2/b^2 f[x_, y_] := Re[c*(1 - rest)^0.5] g[x_, y_] := If[f[x, y] < 0, 0, f[x, y]] Plot3D[g[x, y], {x, 4, -4}, {y, 4, -4}, SphericalRegion -> True, Mesh -> None, PlotStyle -> Texture[ExampleData[{"TestImage", "Lena"}]], Lighting -> "Neutral"] Posted 9 years ago
 Hi Vitaliy,very nice. If you swap the parameters $a$ and $b$ and animate, you actually get the nice effect of the "rotating mask illusion":https://www.youtube.com/watch?v=sKa0eaKsdA0 frames = Table[ Plot3D[g[x, y], {x, 4, -4}, {y, 4, -4}, SphericalRegion -> True, Mesh -> None, PlotStyle -> Texture[ExampleData[{"TestImage", "Lena"}]], Lighting -> "Neutral", ViewPoint -> {2, 2, -1}, ViewVector -> {20 Sin[theta], 0, 20 Cos[theta]}, ViewCenter -> Automatic, Axes ->False, AxesLabel -> {"x", "y", "z"}, Boxed -> False, ViewVertical -> {0, 1, 0}], {theta, Pi, 3 Pi, 0.1}]; for a better effect I just repeat the first frame several times: framelist = Join[Table[frames[], {k, 0, 10}], frames]; This results in: Cheers and thanks,Marco
Posted 9 years ago
 Ha, awesome observation Marco, thanks!