1
$\begingroup$

I'm attempting to draw $N$ cones on a 3D object, where each cone is specified by a pair of 3D coordinates. The first coordinate is for the cone's base, the second one for the cone's apex. Here, I have two lists - ConeBases and ConeVertices - where cone $k$ is specified by the pair of coordinates at the $k$th positions of the ConeBases and ConeVertices lists (i.e. ConeBases[[k]] and ConeVertices[[k]]).

To specify a single cone of base radius (ConeRadius = 1), we can write:

ConeRadius=1;
Graphics3D[Cone[{{0, 0, 0}, {0, 0, 1}}, ConeRadius]]  

However, how could I automatically generate the $N$ cones using my lists of base and apex coordinates? What if I also had a list of base radii for the cones?

The naive solution here, which is what I've been doing, is to generate a string individually specifying each cone. Is there a better way to proceed?

$\endgroup$

1 Answer 1

2
$\begingroup$

You might try something like this:

ConeBases = RandomReal[{-1, 1}, {20, 3}];
ConeVertices = RandomReal[{-1, 1}, {20, 3}];
ConeRadii = RandomReal[{0, .3}, {20}];

cones = Transpose[{ConeBases, ConeVertices, ConeRadii}]

Graphics3D[Cone[{#[[1]], #[[2]]}, #[[3]]] & /@ cones]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Or cones = Transpose[{Transpose@{ConeBases, ConeVertices}, ConeRadii}]; Graphics3D[Cone @@@ cones] $\endgroup$ Mar 5, 2013 at 11:02
  • 1
    $\begingroup$ Or Graphics3D[MapThread[Cone[{#1, #2}, #3] &, {ConeBases, ConeVertices, ConeRadii}]] $\endgroup$
    – einbandi
    Mar 5, 2013 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.