Generate a bicubic ellipsoid in mathematica - wolfram-mathematica

I need to generate a bicubic ellipsoid, for which I've tried to set up the parametric equation of an ellipsoid in mathematica like
ParametricPlot3D[{4 Sin[u] Cos[v], 3 Sin[u] Sin[v], 2 Cos[u]}, {u, 0,
Pi}, {v, 0, 2 Pi}, Mesh -> False, Background -> Black,
Boxed -> False, Axes -> False]
My problem is that since I need a bicubic surface, I want to limit this parametric plot to 16 points and I cant figure out how to make mathematica sample only the number of points I need.I'm a newbie to both mathematica and geometric modeling.

Related

Expand a curve to a circular contour plot

Context: Two sets of data, one is the radius, r, and the other is the velocity, v. v can be positive and negative. The following code
p1=ListLogLogPlot[Table[{r[[i]],v[[i]]},{i,1,number_of_data}]];
p2=ListLogLogPlot[Table[{r[[i]],-v[[i]]},{i,1,number_of_data}],PlotStyle->{Red}];
Show[p1,p2]
is used to give a curve, with positive and negative v both plotted in log-log coordinates.
Question: How to draw a circular, contour-like plot, with Log[r] as the distance to the center of the circle, and the velocities (Log[v]) shown as different, but continuously varying colors, according to v's sign and magnitude?
You may use a DensityPlot function:
v[r_] := Sin[r]*r^2
DensityPlot[v[Norm[{x, y}]], {x, -5, 5}, {y, -5, 5}]
You can deal with the tabular data in two ways. You can either interpolate and use the interpolating function as above or you may use a ListDensityPlot function:
ListDensityPlot[Table[With[{r = RandomReal[{0, 4}], t = RandomReal[{0, 2 Pi}]},
{r Cos[t], r Sin[t], v[r]}], {10^4}]]
I hope this helps.

Rendering Graphs

Is there a way to colour region bounded by edges with GRAPH in mathematica. Like if three vertices form a triangle, I want to colour the are of triangle with GRAPH option.
A one very easy way would be to use image processing:
g = RandomGraph[{10, 15}, ImageSize -> 600, EdgeStyle -> Thick]
MorphologicalComponents[Binarize#Image[g]] // Colorize
It is easy for planar graphs, but for the rest you may have some overlapping regions. I see you mentioned grid; this is how you can approach it:
g = GridGraph[{5, 5}, VertexSize -> .5, EdgeStyle -> Thick];
MorphologicalComponents[ColorNegate#Binarize#GradientFilter[Image[g], 1]] // Colorize

Covariance Matrix of Disks Pixels in Mathematica

I would like to compute the Covariance Matrix of the image below. Pixel based. That is considering each Black Pixel of the Disks as vectors.
While the units below are in centimeter, there are 32 pixels per cm on the screen I am using.
Ahead of the Covariance Matrix computation itself, I can`t figure out the way to obtain all the pixels vector.
frmXY = {{6.59, 1.59}, {33.41, 28.41}};
stim = {{10.85, 21.91, 0.97}, {16.8, 5.26, 0.97}, {11.78, 7.11, 0.97},
{12.64, 14.13, 0.97`}, {20.24, 16.16, 0.97}, {29.51, 8.06,1.53},
{22.42, 5.78, 1.53}, {27.13, 16.47, 1.53}}
Graphics[{EdgeForm[Thick],White, Rectangle ## frmXY, Black,
Disk ### (stim /. {a_, b_, c_} :> {{a, b}, c})}, ImageSize -> 300]
It is not clear from your question as to what constitutes the random variable that describes your model/system and I don't understand what it is that you're trying to take the covariance matrix of.
However, here's a simple example showing how to obtain the covariance matrix and compute the eigenvalues and eigenvectors (basically, reproduce your first plot).
list = RandomReal[
MultinormalDistribution[{0, 0}, {{6, 3}, {3, 3}}], {5000}];
sampleCov = Covariance#list;
{eigValues, eigVectors} = Eigensystem#sampleCov;
Show[ListPlot#list,
Graphics[{Red, Arrowheads[0.03],
Arrow[{{0, 0}, #}] & /# (eigValues eigVectors)}]]

ViewVector transition between two spherical coordinates on a globe

Continuing with the project I previously described I am currently building an animation showing movement between a list of cities. My current code renders a list of cities and makes a set of great circle arcs connecting the cities. The list of cities are part of a timeline so after visiting one city the animation will transition to be centered upon the next.
To my mind this means the ViewVector should be adjusted to show points between a starting city and an ending city. The resulting would probably look like an in-flight map for a long-haul flight sped up considerably. A single frame might look like the following manually produced still:
I now understand how to position the ViewVector above the most recent city but I am quite unsure about how to move the camera smoothly between two spherical coordinate points. My current code is below:
SC[{lat_, lon_}] := {Cos[lon \[Degree]] Cos[lat \[Degree]],
Sin[lon \[Degree]] Cos[lat \[Degree]], Sin[lat \[Degree]]};
GreatCircleArc[{lat1_, lon1_}, {lat2_, lon2_}] :=
Module[{u = SC[{lat1, lon1}], v = SC[{lat2, lon2}], a},
a = VectorAngle[u, v];
Table[Evaluate[RotationTransform[\[Theta], {u, v}][u]], {\[Theta],
0, a, a/Ceiling[10 a]}]]
CityGraphic[name_] := {Opacity[0.85], Black, PointSize[Medium], White,
PointSize[0.045], Point[1.01 SC[CityData[name, "Coordinates"]]]}
CityGraph[places_, age_] :=
Graphics3D[{
Opacity[0.75],
Sphere[{0, 0, 0}, 0.99 ],
Map[Line[
Map[SC,
CountryData[#, "SchematicCoordinates"], {-2}]] &,
CountryData["Countries"]],
Map[CityGraphic, places],
Text[Style[age, FontFamily -> "Helvetica"],
1.02 SC[CityData[First[places], "Coordinates"]]],
White, Line
[Apply[GreatCircleArc,
Partition[Map[CityData[#, "Coordinates"] &, places], 2, 1], {1}]]
},
ViewVector -> {
4 SC[CityData[First[places], "Coordinates"]], {0, 0, 0}},
Boxed -> False,
SphericalRegion -> True,
ImageSize -> {640, 480}
];
CityGraph[{"Tokyo", "Dublin", "Cape Town", "Seattle", "Denver"}, "04"]
In computer graphics people often use Quaternions to smoothly interpolate between various camera viewing directions. Mathematica has a Quaternion package which you could use for basic Quaternion arithmetic. A conversion between Quaternions and Euler angles is described here.
The interpolation process is described here.

Shadows in mathematica Graphics3D

If I understood the Mathematica documentation correct ( haven't found examples either ) Graphics3D does not produce shadows of 3D objects, although Graphics3D has a Lighting-> option.
Question: Have you ever tried to produce Mathematica 3D objects with shadows? If so have you solved this in Mathematica? Or have you exported the graphics to other 3D ( scene-graph ) viewers like for example J-Reality?
The shading model used by MMA, the so-called Phong shading, determines the pixel intensities based on a simple relationship between local surface orientation, light source direction(s), camera direction and diffuse and specular properties of the surface. No other aspect of the geometry is taken into account, which means that objects do not influence the pixel values of other objects even if they are between the object and the light source.
This means that the model doesn't generates shadows. It is not able to.
You could simulate shadows yourself by projecting your object's polygons on the ground plane or wall planes as applicable. That shouldn't be too difficult, but shadows on non-planar surfaces will be pretty hard.
Example:
polys = (PolyhedronData["GreatRhombicTriacontahedron", "Faces"] //
Normal // N) /. {x_, y_, z_}?VectorQ -> {x, y, z + 6};
(* raise it slightly above ground plane*)
shadow = polys /. {x_, y_, z_}?VectorQ -> {x - z, y, 0};
(* projection from a directional light source at 45 deg elevation *)
Graphics3D[{polys, EdgeForm[], FaceForm[Darker#Gray], shadow},
Lighting -> {{"Directional", White, {{1, 0, 1}, {0, 0, 0}}}},
Boxed -> False]
Of course, you need to make sure that the lighting sources (point, spot, directional...) and your shadow projection are consistent.

Resources