(* Plot a tilted ellipse with axes {-1,-2,-3} to {1,2,3} and {-2,1,0} to {2,-1,0} *)
ellipse=ParametricPlot3D[ r Cos[t]{1,2,3} + r Sin[t]{2,-1,0}, {r,0,1},{t,-Pi, Pi},Mesh->{3,7},PlotStyle->{Red,Opacity[0.9]}];
ellaxes=Graphics3D[{Thick,Black,Line[{{-1,-2,-3},{1,2,3}}],Line[{{-2,1,0},{2,-1,0}}]}];
Show[ellaxes,ellipse,  Boxed->True,Axes->True, AxesLabel->{x,y,z}]

Simplify[Sqrt[x^2],x>0]   (* Simplify with assumption v > 0 *)

(*  Define Frenet frame u[t],n[t],b[t] for helix curve c[t] with vertical velocity v *)
Clear[v]                   
norm[{a_,b_,c_}]=Sqrt[a^2+b^2+c^2];
c[t_]={Cos[t],Sin[t],v t};
cp[t_]=D[c[t],t];
u[t_]=Simplify[cp[t]/norm[cp[t]],v>0];
up[t_]=D[u[t],t];
n[t_]=Simplify[up[t]/norm[up[t]],v>0];
b[t_]=Simplify[Cross[u[t],n[t]]];
n[t]
b[t]

(* Draw a tube around the helix using polar coords in Frenet frame *)
r=1/2; v=1/2;  q=2;   (* r = thickness of tube, v = velocity of rise, q = number of turns drawn *)
P[t_,p_]:=c[t] + r Cos[p]{-Cos[t],-Sin[t],0}+r Sin[p]/Sqrt[1+v^2]{v Sin[t],-v Cos[t],1}
helixtube=ParametricPlot3D[P[t,p],{t,0, 2 Pi q}, {p,0,2Pi},Mesh->{24 q-1,7},Boxed->False,Axes->False]

(* Ram's horn surface, similar to noodle above *)
ParametricPlot3D[{20Cos[t]+t Cos[p]Cos[t] ,20Sin[t]+t Cos[p]Sin[t],10t+t Sin[p]}, {p,0,2 Pi}, {t,0, 5Pi},Mesh->{20,80}]

(* Draw torus *)
ParametricPlot3D[{2Cos[t]+ Cos[p]Cos[t] ,2Sin[t]+ Cos[p]Sin[t], Sin[p]}, {p,0,2.25Pi}, {t,0, 2.25Pi},Mesh->{8,8},Boxed->True]

(* Toroidal coordinates = Frenet coordinates around a unit circle c[t] *)
norm[{a_,b_,c_}]=Sqrt[a^2+b^2+c^2];
Clear[p,q]
c[t_]={Cos[t],Sin[t],0};
cp[t_]=D[c[t],t];
u[t_]=Simplify[cp[t]/norm[cp[t]],v>=0];
up[t_]=D[u[t],t];
n[t_]=Simplify[up[t]/norm[up[t]],v>=0];
b[t_]=Simplify[Cross[u[t],n[t]]];
n[t]
b[t]
toroidal[t_,p_,q_]=c[t]+p n[t]+q b[t];
toroidal[t,p,q]

(* Spherical coordinates Jacobian matrix *)
Clear[r,t,p]
spherical[r_,t_,p_]={r Sin[p]Cos[t],r Sin[p]Sin[t],r Cos[p]};
MatrixForm[D[spherical[r,t,p],{{r,t,p}}]]

(*  Bumpy globe  *)
hill[x_,y_]=Exp[-x^2-y^2]; (*  exponential bump *)
peak[x_,y_]=1/(1+Sqrt[x^2+y^2]);  (* sharp hill *)
volcano[x_,y_]=2hill[u,v]-peak[u,v];  (* bump minus sharp peak *)
fbump[x_]:=1/(1+Exp[x^2-5]);  (* flat bump with plateau top *)
ridge[x_,y_]=Exp[-y^2]fbump[x];  (* ridge along x-dir *)
crescent[x_,y_]=ridge[x,y-x^2/2];  (* ridge along graph y = x^2 *)
ParametricPlot3D[{u,v,crescent[u,v]},{u,-4,4},{v,-4,4},PlotRange->Full,AxesLabel->{u,v,z}];  (* test how it looks *)

peaks={{2,1,1},{3,2,1.5},{4,4,0.5},{0,4,1.5},{-2,2,1.5},{-3,1,0.5}}; (* list of several {x-coord, y-coord, height} *)
landscape[u_,v_]=1.5volcano[u,v]+crescent[u+1,v+5] + Sum[ peaks[[i,3]]hill[u-peaks[[i,1]],v-peaks[[i,2]]],{i,Length[peaks]} ];
smile[u_,v_]=crescent[u/2,v]+hill[u-3,v-5]+hill[u+3,v-5]; (* two bumps and a crescent *)
ParametricPlot3D[ {u,v,smile[u,v]},
{u,-6,6},{v,-1,6},PlotRange->Full,AxesLabel->{u,v,z}
];  (* try out the smile on a flat surface *)
ParametricPlot3D[ spherical[10+smile[8(u-Pi/2),8(v-Pi/2)],u-.9Pi,v],
{u,-Pi,Pi},{v,0,Pi},Mesh->{23,11},PlotRange->Full,AxesLabel->{x,y,z},Axes->False,Boxed->False
]  (* map the flat surface to the globe *)

(* US Polygon *)
Graphics[{Red,
Polygon[{{-124,49},{-90,49},{-83,42},{-70,47},{-67,45},{-82,31},{-81,25},{-84,31},{-94,31},{-98,26},{-108,32},{-117,32},{-124,40},{-124,49}}]
}]

(* More Graphics Examples *)
axes=Graphics3D[{
Thick,Black,
Arrow[{{-3,0,0},{3,0,0}}],
Arrow[{{0,-3,0},{0,3,0}}],
Arrow[{{0,0,-3},{0,0,3}}]
},Boxed->False]

Show[plane1,cyl1,AxesEdge->{{1,-1},{1,-1},{1,-1}},Boxed->False,AxesLabel->{x,y,z}, BoxRatios->{1, 1, 1}]

(* Radius Inversion Mapping *)
ParametricPlot[{2 x/(x^2+y^2), 2 y/(x^2+y^2)},{x,1,5},{y,1,5},Mesh->3,
PlotRange->{{0,1.2},{0,1.2}}]

p[x_,y_]:={2 x/(x^2+y^2), 2 y/(x^2+y^2)}
U[v_] := ParametricPlot[p[t,v],{t,-10,10},PlotStyle->Red,PlotRange->{{0,5},{0,5}}]
V[u_] := ParametricPlot[p[u,t],{t,-10,10},PlotStyle->Blue,PlotRange->{{0,5},{0,5}}]

UU=Table[U[2/i],{i,1,10}];VV=Table[V[2/i],{i,1,10}]; 
R = ParametricPlot[p[u,v],{u,1/3,1},{v,1/4,1},PlotRange->{{0,5},{0,5}}];
Show[UU,VV,R,Background->None,AxesLabel->{x,y},Frame->True,Axes->True]

(* Plot a vector field, excluding the center region where arrows are too long *)
VectorPlot[ {-y/(x^2+y^2), x/(x^2+y^2)}, 
Element[{x,y},
RegionDifference[
Rectangle[{-1,-1},{1,1}],Rectangle[{-.2,-.2},{.2,.2}]
]
], Axes->True, Frame->False]

Show[plane1,cyl1,AxesEdge->{{1,-1},{1,-1},{1,-1}},Boxed->False,AxesLabel->{x,y,z}, BoxRatios->{1, 1, 1}]

(* Adjust colors by height z *)
colors[z_]=RGBColor[1,z,0];
ContourPlot[x+3y,{x,-1.1,1.1},{y,-1.1,1.1},
ColorFunction->colors,AxesLabel->{x,y}, Axes->True]

plot1=ContourPlot[ x^4-2x^2-3(2x+1)y^2,{x,-1.3,1.3},{y,-.6,.6},AxesLabel->{x,y},Axes->True, Contours->Table[.4i,{i,-30,10}],
ColorFunction->"SolarColors"];plot2=VectorPlot[{4x^3-4x-6y^2,-6(2x+1)y} ,{x,-1.2,1.2},{y,-.2,.2},VectorPoints->{11,6}, VectorScale->Large, VectorStyle->Black];
Show[plot1,plot2, AxesLabel->{x,y},Axes->True]

Show[plot1,plot2]

Plot3D[x^4-2x^2-3(2x+1)y^2,{x,-1.5,1.7},{y,-1,1},PlotRange->{-3,2},BoxRatios->{1,1,.5},AxesLabel->{x,y,z}]