Tag Info

Hot answers tagged

157

Well, the answer seems to be YES :) Here is my implementation of Minecraft classic game in Mathematica. Let’s start with some screenshots which were taken during the construction of the final scene which will be displayed an the end of this post. Features Blocks are creatable and removable One texture per block Player automatically jumps to the ...


55

Here's one way to slice the donut. To draw one half of the sliced donut I'm using a parameterisation of a torus similar to the one on wikipedia, but with v replaced with u + v and v running from 0 to Pi instead of 2 Pi. This means that the cut is actually a double twist loop. pl = ParametricPlot3D[{{Sin[u] (2 + Cos[u + v]), Cos[u] (2 + Cos[u + v]), Sin[u + ...


45

Yes we can. The following DashedGraphics3D[ ] function is designed to convert ordinary Graphics3D object to the "line-drawing" style raster image. Clear[DashedGraphics3D] DashedGraphics3D::optx = "Invalid options for Graphics3D are omitted: `1`."; Off[OptionValue::nodef]; Options[DashedGraphics3D] = {ViewAngle -> 0.4, ViewPoint ...


43

Answer Apparently, the mesh lines generate points which are too close to the triangle vertices, and VRML is not being able to handle them correctly. To prove the theory, try the example without meshes: p = ParametricPlot3D[{(2 + Cos[v]) Sin[u], (2 + Cos[v]) Cos[u], Sin[v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}, PlotStyle -> Red, Mesh -> None]; ...


39

Solution 1: Using 3D Texture with Polygons The idea is to use Polygon with 3D texture supported by Texture, but it requires a bit of undocumented hack to make it smooth. The original data set is from Stanford Graphics Group website. The dataset that has been used is CThead, 8-bit tiffs (download). Before proceed, make sure that you have a plenty of memory ...


39

We can do this by building a regular hexagon tile and wrapping it onto a torus: hexTile[n_, m_] := With[{hex = Polygon[Table[{Cos[2 Pi k/6] + #, Sin[2 Pi k/6] + #2}, {k, 6}]] &}, Table[hex[3 i + 3 ((-1)^j + 1)/4, Sqrt[3]/2 j], {i, n}, {j, m}] /. {x_?NumericQ, y_?NumericQ} :> 2 π {x/(3 m), 2 y/(n Sqrt[3])} ] ht = ...


38

First of all let me tell you that you should wait for some great submissions from other members. Maybe @Yu-SungChang will post some FPS game here ;-). I just will give you the prototype I happen to write recently for an unrelated task. I could fly around your example too but it is too slow (and cool ;-) ) - I will demo some more fluid but simple environment. ...


37

I'm posting this as a second answer, as it's really a completely different approach. It's also been substantially expanded as of April 25, 2012. While this still doesn't specifically address the question of adding a region, it does plot the countries separately. Of course, each country could be viewed as a region in itself. Our objective is to make a ...


30

UPDATE: latest Mathematica 9 functionality This is very easy now with latest Mathematica 9 functionality. Just use Image3D or Raster3D functions: data = Developer`ToPackedArray[With[{step = .03}, ParallelTable[Exp[-(i^2 + j^2 + k^2)^4/.99], {k, -1.2, 1.2, step}, {i, -1.2, 1.2, step}, {j, -1.2, 1.2, step}]]]; Image3D[data, ColorFunction -> #, ...


28

If you want to plot a distribution that is three dimensional then first you need to form it! SmoothDensityHistogram plots a smooth kernel histogram of the values $\{x_i,y_i\}$ but as we have three dimensional data here we need the function called SmoothKernelDistribution! data = RandomReal[1, {1000, 3}]; dist = SmoothKernelDistribution[data]; Now you ...


25

Note that ViewPoint is given in specially scaled coordinates which depend on amongst things the size of the bounding box. To get better control over the positioning of the camera you could use ViewVector instead, which is given in terms of the coordinates of the plot. You could for example do something like this: rotateMeHarder1[g_, vertical_, viewpoint0_, ...


25

Yet another method: Let us calculate values of function on appropriate rectangular grids, which we will convert to textures (1 pixel = 1 value). Interpolation between pixels is built-in. f = 2 #1^2 + 2 #2^2 + #3^2 + #1 #2 &; PolyhedronData["Cube"] // N // Normal // toTriangles // texturize[f, 50, Hue, Lighting -> "Neutral", Axes -> True] ...


24

This is not a direct response to the question but rather a response to Istvan's comment to FJRA answer. As Istvan points out, the 3D globe has "artefacts like excess polygon-parts". An alternative approach is to use ParametricPlot3D together with a 2D map as a texture. Here's the result. SeedRandom[4]; countries = Table[{ColorData["DarkTerrain"][Random[]], ...


24

I doubt you can find a chart for all options, but take a look at this: For this and other insights two courses by Yu-Sung are a must (there are notebooks and videos there): Graphics Language Quick Start Visualization: Advanced 3D Graphics The above chart is from the 1st one. The one @Kuba links in the comment to your question is from the 2nd - I ...


22

One can also use MeshFunctions: Clear[f]; f = {x, y, z} \[Function] x + Sin[5 z] + y^2; cube = PolyhedronData["Cube", "RegionFunction"]; mesh = 15; RegionPlot3D[cube[x/2, y/2, z/2], {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, MeshFunctions -> {f}, Mesh -> mesh, MeshShading -> ColorData["Rainbow"] /@ Range[0, 1, 1/(mesh + 1)], PlotPoints -> 50, ...


21

I propose a small modification to the parametrization for the torus that addresses issues with conformality. Try F[t_, u_, r_] := {Cos[t] (r + Cos[u + Sin[u]/r]), Sin[t] (r + Cos[u + Sin[u]/r]), Sin[u + Sin[u]/r]} instead. Next, we wish to choose suitable values for $m, n$ for a given $r$ such that the mapping of the ...


19

One way to extrude a 3D object from a binary 2D image is to use RegionPlot3D: pts = ImageData[ColorNegate@Binarize@Import["http://i.stack.imgur.com/UWO6k.png"], "Bit"]; g = RegionPlot3D[pts[[Sequence @@ Round@{i, j}]] == 1, {i, 1, #1}, {j, 1, #2}, {z, 0, 1}, PlotPoints -> 100, Mesh -> False, Axes -> False, Boxed -> False] & @@ ...


19

The following is probably what you want. Make3d[plot_, height_, opacity_] := Module[{newplot}, newplot = First@Graphics[plot]; newplot = N@newplot /. {x_?AtomQ, y_?AtomQ} :> {x, y, height}; newplot /. GraphicsComplex[xx__] :> {Opacity[opacity], GraphicsComplex[xx]} ] Show[{Graphics3D[Make3d[twoDptsPlot, -1, .75]], ...


19

This maybe helpful if you want to convert image structure into 2D/3D line primitives, MorphologicalGraph does some astonishing things out of the box: img = Import[ "https://upload.wikimedia.org/wikipedia/commons/c/ce/Spinnennetz_\ im_Gegenlicht.jpg"]; g = MorphologicalGraph[img // MorphologicalBinarize, VertexCoordinates -> Automatic, ...


19

You can use Inset: Show[{Graphics3D[{Opacity[0.2], Sphere[], Opacity[1.0], Blue, Inset[Graphics[Text[Style["Surprise!", Green, 24]]], {0, 0, 0}]}], ParametricPlot3D[{Sin[th] Cos[ph], Sin[th] Sin[ph], Cos[th]}, {th, 0, Pi}, {ph, 0, 2 Pi}, RegionFunction -> Function[{x, y, z}, Abs[x] < .9], PlotRange -> {-1, 1}, PlotStyle -> ...


19

Here's a start: perforateaux[pts_, ratio_, indices : {__Integer}] := Module[ {vertices, center, newPts, ind}, vertices = Replace[indices, {{p_, b___, p_} :> {p, b}}]; center = Mean[pts[[vertices]]]; newPts = ratio (# - center) + center & /@ pts[[ vertices]]; ind = MapThread[Flatten[{#1, Reverse[#2]}] &, {Partition[vertices, ...


18

You could use a combination of Translate and Scale. Suppose the radii and centres of the circles are given by radii = RandomReal[{.1, .6}, 8]; centres = RandomReal[{-2, 2}, {8, 3}]; Then using the original sphere image = ExampleData[{"ColorTexture", "GiraffeFur"}]; sphere = SphericalPlot3D[1, {theta, 0, Pi}, {phi, 0, 2 Pi}, Mesh -> None, ...


18

The idea is quite simple: Since any great circle can be parametrized as $\cos(\theta)u + \sin(\theta)v$ where $u$ and $v$ are two orthonormal vectors. One can start with $u=\{1,0,0\}, v=\{0,1,0\}$ and use RotationTransform to get out of the xy plane, then use RotationTransform again to spin around the z-axis to get all great circles with desired inclination. ...


18

One possible way is to use Graphics3D with Point and color points by function value so it's like density plot 3d. For example, xyz = Flatten[ Table[{i, j, k}, {i, 1, 10, .35}, {j, 1, 10, .35}, {k, 1, 10, .35}], 2]; f[x_, y_, z_] := x^2 y Cos[z] Graphics3D[ Point[data, VertexColors -> (Hue /@ Rescale[f[##] & @@@ data])], ...


18

Here's a rather simple first attempt using RegionPlot3D to define a solid with Voronoi cell type voids. I start with a set of random void locations. The region function says that a point is in the solid if the distance to the nearest void centre is almost the same as the distance to the second nearest void centre (i.e. we are close to a Voronoi cell ...


17

The important image operation you need is called Skeletonization or Thinning. Different approaches are possible, but as far as I can see, you are interested in the medial axis of your black object. Here is one simple recipe to create a 3D tubular medial axis from your image: take the image and invert the colors, because in image processing the convention ...


17

I think the basic idea is to create two slightly different views and combine them in the red and (green + blue) channels. p = Plot3D[Sin[x y]^2, {x, -2, 2}, {y, -2, 2}]; {r, g} = ColorConvert[ Image[Show[p, ViewPoint -> {3 Sin[#], 3 Cos[#], 2} &[# Degree]], ImageSize -> {360, 275}], "Grayscale"] & /@ {141, 139}; ColorCombine[{r, g, g}] ...


17

There are some tricks ... Specifying the prism's vertices is enough (you don't need to take care of the faces) if you use some undocumented methods for finding the convex hull: v = {{2/3, 1/2, 0}, {2/3, 1/2, 1}, {2/3, 1, 0}, {2/3, 1, 1}, {3/2, 1/2, 0}, {3/2, 1, 0}}; ...


17

If you dig through Eric Weisstein notebook you can find this well parametrized version. I changed parameters and styles a bit to get closer to your shape. With[{R = 1.2, r = 1/2, a = Sqrt[2]}, ContourPlot3D[-a^2 + ((-r^2 + R^2)^2 - 2 (r^2 + R^2) ((-r - R + x)^2 + y^2) + 2 (-r^2 + R^2) z^2 + ((-r - R + x)^2 + y^2 + z^2)^2) ((-r^2 + ...


17

I would say you go for the Lighting option: Plot3D[Exp[-(x^2 + y^2)], {x, -2, 2}, {y, -2, 2}, Lighting -> {{"Ambient", White}}, PlotRange -> All, Mesh -> {20}]



Only top voted, non community-wiki answers of a minimum length are eligible