# Use ParametricPlot3D to plot a general circular cylinder?

Posted 8 months ago
1463 Views
|
11 Replies
|
6 Total Likes
|
 Hello everyone, How do I parametrise and use ParametricPlot3D to plot a general circular cylinder with general as axis and radius R?
11 Replies
Sort By:
Posted 8 months ago
 Are you new to Mathematica? What have you tried?
Posted 8 months ago
 Can easily be done using Graphics3D: plotCylinder[axis_, radius_] := Graphics3D[Cylinder[{{0, 0, 0}, axis}, radius]] 
Posted 8 months ago
 Given an axis vector "axis" and a radius "r". You first need to construct an orthonormal set of coordinate axes. {vz, vx, vy} = Chop@Orthogonalize[{axis, {1, 0, 0}, {0, 1, 0}}] Now, given a base point "b" and a height "h" the plot can be constructed with: Show[ParametricPlot3D[b+z*vz+r*Cos[\[Theta]]*vx+r*Sin[\[Theta]]*vy,{z,0,h},{\[Theta],0,2\[Pi]},PlotStyle->Directive[Opacity[0.7],Orange]], Graphics3D[{Blue,PointSize[0.02],Point[b],Arrow[{b,b+h*vz}], Magenta,Arrow[{b,b+r*vx}],Green,Arrow[{b,b+r*vy}]}]] This will also show the cylinder axis in blue, with the other two axes in Magenta and Green.
Posted 8 months ago
 Thank you so much John McGee. When I use the axis as {1,10,0) , the base point as {0,0,1} and h=5 I get a blank plot. What could be he reason?
Posted 15 days ago
 Are you sure you made the coordinate box big enough? I get a cylinder that's cut off by the plot boundary. But I think that John McGee's method just using Orthogonalize[ ] should work as long as the axis and the other two vectors are linearly independent. Otherwise, you'd have to choose different 2nd and 3rd vectors. Attachments:
Posted 15 days ago
 This is quick and ingenious, thanks. I wouldn't have guessed that you could pass in one 3D vector function, not a list of functions for each coordinate. A great feature!I just wish we could also use the intuitive notation or, even better, . Am I wrong, or isn't this form of term-by-term multiplication when the second vector is actually a vector of basis vectors, a quick way to map onto a new basis? I wish Mathematica always allowed straightforward matrix and vector multiplications, without behaving in a non-standard way if you have a column vector on the right, for example. I don't know what's involved in terms of lists, but it seems to me this is fundamentally important, to respect accepted notation and not give quirky objections and insist on usually unreadable tangles of lists.After all, this matrix layout evolved for both readability and intuitiveness, right? There are direct connections to projections and to mapping onto other basis vectors that come through when standard matrix layout can be used.I just used double-struck letters for the basis vectors to distinguish them from the scalars: Attachments:
Posted 8 months ago
 The problem is with my oversimplified Orthogonalize. The other two vectors should be nearly perpendicular to "axis", as in Orthogonalize[{1,10,0},{0,1,0},{0,0,1}]. 
Posted 8 months ago
 Here is a little function that will make a set of orthogonal axes where the first axis is a normalized version of the given axis. makeOrthoAxes[axis_] := Module[{wx, wy, wz}, {wx, wy, wz} = IdentityMatrix[3]; {wx, wy, wz} = Chop@N@Orthogonalize[ Prepend[Reverse@Most@SortBy[{wx, wy, wz}, Dot[#, axis] &], axis]] ] Use it as {wx,wy,wz}=makeOrthoAxes[{1,10,0}]
Posted 8 months ago
 Another variant of getting the coordinate axes: getMatrix[axis_ /; Norm[axis] != 0] := Module[ {v2, v3}, v2 = {x, y, z} /. First@FindInstance[ Dot[axis, {x, y, z}] == 0 && Norm@{x, y, z} != 0, {x, y, z}, Reals ]; v3 = Cross[axis, v2]; Normalize /@ {axis, v2, v3} ] 
 There seems to be an easier answer. ParametricPlot3D[{Cos[u], Sin[u], t}, {u, 0, 2 Pi}, {t,0,5}] (*has radius of 1*} ParametricPlot3D[{2*Cos[u], 2*Sin[u], t}, {u, 0, 2 Pi}, {t,0,5}] (*has radius of 2*} It shouldn't be to hard (I think) to figure our how to do Cylinders with different orientations.