Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
1  
Or cones = Transpose[{Transpose@{ConeBases, ConeVertices}, ConeRadii}]; Graphics3D[Cone @@@ cones] –  belisarius Mar 5 '13 at 11:02
1  
Or Graphics3D[MapThread[Cone[{#1, #2}, #3] &, {ConeBases, ConeVertices, ConeRadii}]] –  einbandi Mar 5 '13 at 16:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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