Re: Help: how to disp. 3-D vectors
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: Help: how to disp. 3-D vectors
- From: villegas
- Date: Wed, 6 Oct 93 08:01:07 -0500
> I am trying to display three data sets, a 3-D vector (v) and > two scalars (a and b), all three given for a set of points in > 3-D space. My data looks something like: > > data = { {{x0,y0,z0}, {vx0,vy0,vz0}, a0, b0}, > {{x1,y1,z1}, {vx1,vy1,vz1}, a1, b1}, > ... > {{xi,yi,zi}, {vxi,vyi,vzi}, ai, bi}, > ... } > > I would like to have a 3-D display with an arrow at each point > {xi, yi, zi}, the arrow being parallel with vi and its length > and colour representing the values of ai and bi respectively. > I have tried using ListPlotVectorField3D which almost does the > job, but not quite. Am I missing something, or perhaps just asking > for too much? New in 2.2 is the package Graphics`Arrow`, which defines a new graphics primitive called 'Arrow' (analogous to the familiar 'Line', 'Polygon', et al) using some PostScript features introduced in 2.2. After loading the package Needs["Graphics`Arrow`"] we can look up the usage of Arrow: ? Arrow Arrow[start, finish, (opts)] is a graphics primitive representing an arrow starting at start and ending at finish. Since Arrow takes the starting and ending point of the arrow, we can apply a function across your list of arrow-specifications to produce the Arrow objects. If we use Mathematica's pure functions, then we can represent the different parts of a general arrow-specification {{xi,yi,zi}, {vxi,vyi,vzi}, ai, bi} with Slot symbols #1 through #4: #1 = {xi, yi, zi} #2 = {vxi,vyi,vzi} #3 = ai #4 = bi Using this notation, the desired Arrow object would be Arrow[#1, #1 + #3 * #2/(#2 . #2)] (* assuming #2 is not a unit vector *) and the color, as determined by element 4, bi, is put into a list with the Arrow. Say bi is a value intended for the Mathematica Hue function: { Hue[#4], Arrow[#1, #1 + #3 * #2/(#2 . #2)] } If we want, we can give options inside the Arrow to control features of the arrowhead. The options are described in the Technical Report: _Guide to Standard Mathematica Packages_, and are summarized in the usage messages for the package. Let's make a sample list of arrow-specifications and show how to form and render the Arrows. In this example, I used direction vectors, so I did not need to divide #2 by the norm (#2 . #2) as above. But your data list might need the more general form above. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vectorSpecs = Table[{{Cos[t], Sin[t]}, {Cos[t], Sin[t]}, 1/3 Sin[8 t], 1/2 + 1/3 Sin[8 t]}, {t, 0, (2Pi - Pi/50), Pi/50}]; arrows = Apply[ {GrayLevel[#4], Arrow[#1, #1 + #3 * #2, HeadLength->1/50] }&, vectorSpecs, {1} ]; Show[Graphics[arrows, Axes->True, AspectRatio->Automatic]] If you have a color screen, then here is a somewhat prettier variation: vectorSpecsColor = Table[{{Cos[t], Sin[t]}, {Cos[t], Sin[t]}, 1/3 Sin[8 t], 2/3 + 1/3 Sin[8 t]}, {t, 0, (2Pi - Pi/50), Pi/50}]; arrowsColor = Apply[ {Hue[#4], Arrow[#1, #1 + #3 * #2, HeadLength->1/50] }&, vectorSpecsColor, {1} ]; Show[Graphics[arrowsColor, Axes->True, AspectRatio->Automatic]] +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Robby Villegas