3.    3D grafika - (bez standardnih paketa)

3.1. ParametricPlot3D - prostorne krivulje

ParametricPlot3D[{4  Cos[t], 4  Sin[t], t}, {t, 0, 5  Pi}]

ParametricPlot3D[{{4  Cos[t], 4  Sin[t], t}, {5  Cos[t], 5  Sin[t], 
          t}, {6  Cos[t], 6  Sin[t], t}}, {t, 0, 5  Pi}]

Options[ParametricPlot3D]

ParametricPlot3D[{4  Cos[t], 4  Sin[t], t}, {t, 0, 5  Pi}, 
      ViewPoint -> {1.194,  -2.204,  -1.910}]

ParametricPlot3D[{4  Cos[t], 4  Sin[t], t}, {t, 0, 5  Pi}, 
      DefaultColor -> Hue[1]]

ParametricPlot3D[{4  Cos[t], 4  Sin[t], t}, {t, 0, 5  Pi}, 
      DefaultColor -> Hue[1], FaceGrids -> All]

ParametricPlot3D[{4  Cos[t], 4  Sin[t], t, AbsoluteThickness[2]}, {t, 
        0, 5  Pi}]

ParametricPlot3D[{4  Cos[t], 4  Sin[t], 
        t, {Hue[1], AbsoluteThickness[2], AbsoluteDashing[{2, 5}]}}, {t, 0, 
        5  Pi}]

zavojnica[r_, h_][t_] := {r*Cos[t], r*Sin[t], h*t}

ParametricPlot3D[
      Evaluate[zavojnica[4, 1][t]], {t, 0, 5  Pi}]

Table[zavojnica[r, 1][t], {r, 0.5, 4, 0.5}]

ParametricPlot3D[
      Evaluate[Table[zavojnica[r, 1][t], {r, 0.5, 4, 0.5}]], {t, 0, 
        5  Pi}]

Append[{a, b, c}, d]

Append[{a, b, c}, {d, e}]

ParametricPlot3D[
      Evaluate[Table[
          Append[zavojnica[r, 1][t], {Hue[r/4], 
              AbsoluteThickness[3]}], {r, 0.5, 4, 0.5}]], {t, 0, 
        11  Pi/2}]

3.2. Graphics Primitives

Show[
Graphics3D[
        Polygon[{{0, 0, 0}, {0, 0, 5}, {5, 5, 
              0}}]], 
Graphics3D[
        Polygon[{{0, 0, 3}, {0, 5, 3}, {5, 0, 
              3}}]], 

Graphics3D[
        Line[{{3, 0.5, 0}, {3, 0.5, 
              5}}]], 

Graphics3D[{AbsolutePointSize[12], Point[{3, 0.5, 0}], 
          Point[{3, 0.5, 5}]}], 
Graphics3D[
        Cuboid[{4, 4, 4}]], 
Graphics3D[
        Cuboid[{0, 4, 4}, {3, 5, 5}]]]

Show[
Graphics3D[
        Polygon[{{0, 0, 0}, {0, 0, 5}, {5, 5, 
              0}}]], 
Graphics3D[
        Polygon[{{0, 0, 3}, {0, 5, 3}, {5, 0, 
              3}}]], 

Graphics3D[
        Line[{{3, 0.5, 0}, {3, 0.5, 
              5}}]], 

Graphics3D[{AbsolutePointSize[12], Point[{3, 0.5, 0}], 
          Point[{3, 0.5, 5}]}], 
Graphics3D[
        Cuboid[{4, 4, 4}]], 
Graphics3D[
        Cuboid[{0, 4, 4}, {3, 5, 5}]], 
ColorOutput -> 
        CMYKColor]

Show[
Graphics3D[
        Polygon[{{0, 0, 0}, {0, 0, 5}, {5, 5, 
              0}}]], 
Graphics3D[
        Polygon[{{0, 0, 3}, {0, 5, 3}, {5, 0, 
              3}}]], 

Graphics3D[
        Line[{{3, 0.5, 0}, {3, 0.5, 
              5}}]], 

Graphics3D[{AbsolutePointSize[12], Point[{3, 0.5, 0}], 
          Point[{3, 0.5, 5}]}], 
Graphics3D[
        Cuboid[{4, 4, 4}]], 
Graphics3D[
        Cuboid[{0, 4, 4}, {3, 5, 5}]], 
Lighting -> 
        False]

Show[
Graphics3D[{FaceForm[Hue[0.15]], 
          EdgeForm[{Hue[0.85], AbsoluteThickness[3]}], 
          Polygon[{{0, 0, 0}, {0, 0, 5}, {5, 5, 
                0}}]}], 
Graphics3D[{FaceForm[Hue[0.35]], 
          EdgeForm[{Hue[0.75], AbsoluteThickness[3]}], 
          Polygon[{{0, 0, 3}, {0, 5, 3}, {5, 0, 
                3}}]}], 

Graphics3D[{AbsoluteThickness[3], 
          AbsoluteDashing[{2, 5}], Hue[1], 
          Line[{{3, 0.5, 0}, {3, 0.5, 
                5}}]}], 

Graphics3D[{AbsolutePointSize[12], 
          GrayLevel[0.6], Point[{3, 0.5, 0}], 
          Point[{3, 0.5, 5}]}], 
Graphics3D[{FaceForm[
            Hue[0.2]], EdgeForm[AbsoluteThickness[2]], 
          Cuboid[{4, 4, 4}]}], 
Graphics3D[{FaceForm[
            Hue[0.65], Hue[1]], 
          EdgeForm[{AbsoluteThickness[2], GrayLevel[0.5]}], 
          Cuboid[{0, 4, 4}, {3, 5, 
              5}]}], 

Lighting -> 
        False]

3.3. Primjer animacije Frenetovog trobrida

fleksija[krivulja_][
        t_] := 
Simplify[
              Factor[
Dot[
Cross[
                    D[krivulja[tt], tt], D[krivulja[tt], {tt, 2}]], 
                  Cross[D[krivulja[tt], tt], 
                    D[krivulja[tt], {tt, 2}]]]]]^(1/
                2)/
Simplify[
              Factor[
Dot[D[krivulja[tt], tt], 
                  D[krivulja[tt], tt]]]]^(3/2) /. tt -> t

torzija[krivulja_][
        t_] := 
Simplify[
            Det[{D[krivulja[tt], tt], D[krivulja[tt], {tt, 2}], 
                D[krivulja[tt], {t, 3}]}]]/
Simplify[
            Factor[
Dot[
                Cross[D[krivulja[tt], tt], D[krivulja[tt], {tt, 2}]], 
                Cross[D[krivulja[tt], tt], D[krivulja[tt], {tt, 2}]]]]] /. 
        tt -> t

tangenta[krivulja_][
        t_] := 
D[krivulja[tt], tt]/
          Simplify[
              Factor[
Dot[D[krivulja[tt], tt], 
                  D[krivulja[tt], tt]]]]^(1/2) /. tt -> t

binormala[krivulja_][
        t_] := 
Simplify[
            Cross[D[krivulja[tt], tt], 
              D[krivulja[tt], {tt, 2}]]]/
Simplify[
            Factor[
Dot[
                Cross[D[krivulja[tt], tt], D[krivulja[tt], {tt, 2}]], 
                Cross[D[krivulja[tt], tt], D[krivulja[tt], {tt, 2}]]]]] /. 
        tt -> t

normala[krivulja_][t_] := 
      Cross[binormala[krivulja][t], tangenta[krivulja][t]]

FT[krivulja_][
        t_] := 
{{Hue[0.1], AbsoluteThickness[3], 
          Line[{krivulja[t], 
              krivulja[t] + tangenta[krivulja][
                  t]}]}, 
{Hue[0.4], AbsoluteThickness[3], 
          Line[{krivulja[t], 
              krivulja[t] + normala[krivulja][
                  t]}]}, 
{Hue[0.7], AbsoluteThickness[3], 
          Line[{krivulja[t], 
              krivulja[t] + binormala[krivulja][t]}]}}

viviani[a_][
        t_] := 
a {1 + Cos[t], Sin[t], 
          2  Sin[t/2]}

ParametricPlot3D[viviani[1][t] // Evaluate, {t, -2 Pi, 
        2  Pi}]

ParametricPlot3D[
      Table[{2  Cos[u] Sin[v], 2  Sin[u] Sin[v], 2  Cos[v], 
            GrayLevel[0.6]}, {u, 0, 2  Pi, Pi/12}] // Evaluate, {v, 0, 
        Pi}]

ParametricPlot3D[
      Table[{2  Cos[u] Sin[v], 2  Sin[u] Sin[v], 2  Cos[v], 
            GrayLevel[0.6]}, {v, 0, Pi, Pi/12}] // Evaluate, {u, 0, 
        2  Pi}]

Show[%, %%]

Table[
Show[
        ParametricPlot3D[
          Append[viviani[1][t], AbsoluteThickness[3]] // 
            Evaluate, {t, -2 Pi, 2  Pi}, 
          DisplayFunction -> 
            Identity], 
Graphics3D[FT[viviani[1]][
            a]], 
Graphics3D[{AbsolutePointSize[8], Hue[1], 
            Point[viviani[1][a] // 
                Evaluate]}], 
%, 
DisplayFunction -> $DisplayFunction, 
PlotRange -> {{0, 2}, {-2, 2}, {-2, 
              2}}, 
ViewPoint -> {1,  -1,  
            0.4}, 
Boxed -> 
          False, 
AxesEdge -> {{-1, -1}, {-1, -1}, {-1, -1}}, 
Ticks -> 
          None, 
AxesLabel -> {x, y, 
            z}], 
{a, -2 Pi, 7  Pi/4, 
        Pi/8}]

3.4. Plot3D

Plot3D[Sin[2  x*y], {x, 0, 4}, {y, 0, 4}]

Options[Plot3D]

Plot3D[
      Sin[2  x*y], {x, 0, 4}, {y, 0, 
        4}, 
AxesLabel -> {x, y, z}]

Plot3D[
      Sin[2  x*y], {x, 0, 4}, {y, 0, 
        4}, 
PlotPoints -> {100, 100}]

Plot3D[
      Sin[2  x*y], {x, 0, 4}, {y, 0, 
        4}, 
PlotPoints -> {100, 100}, 
      ColorOutput -> CMYKColor]

Plot3D[
      Sin[2  x*y], {x, 0, 4}, {y, 0, 
        4}, 
PlotPoints -> {100, 100}, 
      ColorOutput -> 
        CMYKColor, 
MeshStyle -> {GrayLevel[
            0.5]}]

Plot3D[
      Sin[2  x*y], {x, 0, 4}, {y, 0, 
        4}, 
PlotPoints -> {100, 100}, 
      ColorOutput -> CMYKColor, 
Mesh -> 
        False]

Plot3D[
      Sin[2  x*y], {x, 0, 4}, {y, 0, 
        4}, 
PlotPoints -> {100, 100}, 
      ColorOutput -> CMYKColor, 
AmbientLight -> 
        Hue[0.4]]

Plot3D[
      Sin[2  x*y], {x, 0, 4}, {y, 0, 
        4}, 
PlotPoints -> {100, 
          100}, 
Lighting -> False]

Plot3D[{Sin[2  x*y], Hue[0.15]}, {x, 0, 4}, {y, 0, 
        4}, 
PlotPoints -> {50, 50}]

Plot3D[x*y, {x, -4, 4}, {y, -4, 4}]

Plot3D[
      x*y, {x, -4, 4}, {y, -4, 
        4}, 
BoxRatios -> {1, 1, 1}, 
      PlotPoints -> 30, AxesLabel -> {x, y, z}, 
      ColorOutput -> CMYKColor]

Plot3D[
      x*y, {x, -4, 4}, {y, -4, 
        4}, 
BoxRatios -> {1, 1, 1}, 
      PlotPoints -> 30, AxesLabel -> {x, y, z}, 
      ColorOutput -> 
        CMYKColor, 
ViewPoint -> {-4, -1, 
          0.6}]

Plot3D[
      x^3 - 3  x*y^2, {x, -5, 5}, {y, -4, 
        4}, 
AxesLabel -> {x, y, z}, 
      BoxRatios -> {1, 1, 1}, 
ViewPoint -> {0.7, 
          1, 0.6}, 
      PlotPoints -> 30, 
ColorOutput -> 
        CMYKColor]

Plot3D[
      x^2 + y^2, {x, -8, 8}, {y, -8, 
        8}, 
AxesLabel -> {x, y, z}, 
      BoxRatios -> {1, 1, 1}, 
      PlotPoints -> 30, 
ColorOutput -> 
        CMYKColor]

Plot3D[x - y, {x, -2, 2}, {y, -2, 2}]

Plot3D[x - y, {x, -2, 2}, {y, -2, 2}, 
      PlotPoints -> 2]

3.5. ListPlot3D

ListPlot3D[{{5, 7, -1}, {-1, 4, 2}, {-3, 10, -5}, {7, 
          10, -5}}, AxesLabel -> {x, y, z}]

Options[ListPlot3D]

ListPlot3D[{{5, 7, -1}, {-1, 4, 2}, {-3, 10, -5}, {7, 
          10, -5}}, 
{{Hue[0.1], Hue[1]}, {Hue[0.3], 
          Hue[0.8]}, {Hue[0.5], 
          Hue[0.6]}}, 
AxesLabel -> {x, y, 
          z}]

ListPlot3D[Table[Sin[2  x*y], {y, 0, 4, 4/40}, {x, 0, 3, 3/30}], 
      AxesLabel -> {x, y, z}]

ListPlot3D[
      Table[Sin[2  x*y], {y, 0, 4, 4/40}, {x, 0, 3, 
          3/30}], 
Table[
        Hue[Abs[Sin[2  x*y]]], {y, 0, 4, 4/39}, {x, 0, 3, 
          3/29}], 
AxesLabel -> {x, y, z}]

ListPlot3D[
      Table[Sin[2  x*y], {y, 0, 4, 4/40}, {x, 0, 3, 
          3/30}], 
Table[
        Hue[Abs[Sin[x/3]]], {y, 0, 4, 4/39}, {x, 0, 3, 
          3/29}], 
AxesLabel -> {x, y, z}]

3.6. ParametricPlot3D - plohe

ParametricPlot3D[{Cos[u]*Sin[v], Sin[u]*Sin[v], Cos[v]}, {u, 0, 
        2  Pi}, {v, 0, Pi}]

Options[ParametricPlot3D]

ParametricPlot3D[{Cos[u]*Sin[v], Sin[u]*Sin[v], Cos[v]}, {u, 0, 
        3  Pi/2}, {v, 0, Pi}]

ParametricPlot3D[{{Cos[u]*Sin[v], Sin[u]*Sin[v], 
          Cos[v]}, 
{2  Cos[u]*Sin[v], 2  Sin[u]*Sin[v], 
          2  Cos[v]}}, {u, 0, 3  Pi/2}, {v, 0, Pi}]

ParametricPlot3D[{{Cos[u]*Sin[v], Sin[u]*Sin[v], Cos[v], 
          Hue[0.75, 0.7, 0.9]}, 
{2  Cos[u]*Sin[v], 
          2  Sin[u]*Sin[v], 2  Cos[v], Hue[0.35, 0.7, 0.9]}}, {u, 0, 
        3  Pi/2}, {v, 0, Pi}, 
Lighting -> 
        False]

ParametricPlot3D[{{Cos[u]*Sin[v], Sin[u]*Sin[v], Cos[v], 
          FaceForm[Hue[0.15], Hue[1]]}, 
{2  Cos[u]*Sin[v], 
          2  Sin[u]*Sin[v], 2  Cos[v], FaceForm[Hue[0.5], Hue[0.7]]}}, {u, 0, 
        3  Pi/2}, {v, 0, Pi}, 
Lighting -> 
        False]

ParametricPlot3D[{{Cos[u]*Sin[v], Sin[u]*Sin[v], Cos[v], 
          FaceForm[SurfaceColor[Hue[0.15]], 
            SurfaceColor[Hue[1]]]}, 
{2  Cos[u]*Sin[v], 
          2  Sin[u]*Sin[v], 2  Cos[v], 
          FaceForm[SurfaceColor[Hue[0.3]], SurfaceColor[Hue[0.7]]]}}, {u, 0, 
        3  Pi/2}, {v, 0, Pi}]

ParametricPlot3D[
{{Cos[u]*Sin[v], Sin[u]*Sin[v], 
          Cos[v], FaceForm[SurfaceColor[RGBColor[1, 0, 1]], 
            SurfaceColor[RGBColor[0, 1, 0]]]}, 
{2  Cos[u]*
            Sin[v], 2  Sin[u]*Sin[v], 2  Cos[v], 
          FaceForm[SurfaceColor[RGBColor[1, 1, 0]], 
            SurfaceColor[RGBColor[0, 1, 1]]]}}, {u, 0, 3  Pi/2}, {v, 0, 
        Pi}]

ParametricPlot3D[
{{Cos[u]*Sin[v], Sin[u]*Sin[v], 
          Cos[v], FaceForm[SurfaceColor[CMYKColor[0.3, 0.2, 0.1, 0]], 
            SurfaceColor[CMYKColor[0, 1, 1, 0]]]}, 
{2 
             Cos[u]*Sin[v], 2  Sin[u]*Sin[v], 2  Cos[v], 
          FaceForm[SurfaceColor[CMYKColor[0, 0, 1, 0]], 
            SurfaceColor[CMYKColor[0.6, 0.7, 0, 0]]]}}, {u, 0, 3  Pi/2}, {v, 
        0, Pi}]

elipsoid[a_, b_, c_, p_, q_, r_][u_, 
        v_] := 
{a*Cos[u]*Sin[v] + p, b*Sin[u]*Sin[v] + q, 
        c*Cos[v] + r}

ParametricPlot3D[{elipsoid[3, 3, 4, 0, 0, 0][u, 
            v], elipsoid[6, 6, 3, 0, 0, 1][u, v]} // Evaluate, {u, 0, 
        3  Pi/2}, {v, 0, Pi}]