MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: color space curve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8304] Re: [mg8220] color space curve
  • From: jpk at max.mpae.gwdg.de
  • Date: Sun, 24 Aug 1997 04:46:49 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

--b7c_7187-2458_861-3ae1_4dbb
Content-MD5: IZHn5262wbdnQQB77lQhlw==


> 
> I want to plot a three-dimensional space curve (with ParametricPlot3D)
> but in color and according to  X and Y values (not Z values),
>  to give the sense of depth.

In my (german) book about Mathematica & C (ISBN 3-540-61489-3) a DepthCue 
function is implemented.
I appen the relevant Mathematica package.

It works only for { Line[_], Line[_],..} and will not break up
lines with more than 2 points into shorter ones.

The option ColorFunction allows You to set colors with respect to the
distance from the users ViewPoint. At least You may be able to change the
code for You coloring due to x-y.

Hope that helps 

Jens
--b7c_7187-2458_861-3ae1_4dbb
Content-Description: DepthCue.m
Content-MD5: WyjO08RE977mJl3mv+MbQQ==

BeginPackage["DepthCue`"]=0D
=0D
UsersViewPoint::usage=3D=0D
"UsersViewPoint[graph3d] of a Graphics3D object returns the position=0D
 of the view point in modell coordinates rather than in world =
coordinates."=0D
=0D
DepthCuedLines::usage=3D=0D
"DepthCuedLines[graph3d] colors the lines in a Graphics3D object with=0D
 respect to the distance of the line center to the view point. The =0D
 color function used can be given by the ColorFunction option. The=0D
 default ColorFunction is GrayLevel."=0D
=0D
Begin["`Private`"]=0D
=0D
UsersViewPoint[gr_Graphics3D]:=3D=0D
  Module[{boundb,rbox,vp,scale,ctr},=0D
    boundb=3DFullOptions[gr,PlotRange];=0D
    rbox=3DFullOptions[gr,BoxRatios];=0D
    vp=3DFullOptions[gr,ViewPoint];=0D
    (* calculate the scaling *)=0D
    scale=3DMax[rbox] ((Last[#]-First[#] ) & /@ boundb)/rbox;=0D
    (* calculate the center *)=0D
    ctr=3D ((First[#] + Last[#]) & /@  boundb)/2;=0D
    vp*scale+ctr=0D
  ]=0D
=0D
Options[DepthCuedLines]:=3D{ColorFunction->(GrayLevel[1.0-#] &)}=0D
=0D
DepthCuedLines[gr_Graphics3D,opts___]:=3D=0D
  Module[{graph,uvp,lines,mind,maxd,delta,colorfun},=0D
    colorfun=3DColorFunction /. {opts} /. Options[DepthCuedLines];=0D
    (* split the lines into segments *)=0D
    graph =3D gr //. =0D
      Line[{a_,b_,c__}] :> (Sequence @@ {Line[{a,b}],Line[{b,c}]});  =0D
    uvp=3DUsersViewPoint[gr];=0D
    lines=3DSelect[Flatten[First[graph]],Head[#]=3D=3D=3DLine &];=0D
    (* get the distance range of the lines *)   =0D
    {mind,maxd}=3D{Max [#],Min[#]} & @  =0D
       Flatten[(lines /. Line[{a_,b_}] :> (d=3D((a+b)/2-uvp); =
Sqrt[d.d]))];=0D
    delta=3Dmaxd-mind;=0D
    graph /. Line[{a_,b_}] :> =0D
      (d=3D((a+b)/2-uvp); =0D
       d=3D(Sqrt[d.d]-mind)/delta;=0D
       {colorfun[d],Line[{a,b}]})=0D
  ]=0D
End[]=0D
EndPackage[]=0D
--b7c_7187-2458_861-3ae1_4dbb--


  • Prev by Date: Re: Solving
  • Next by Date: Re: ? ? ? ! ?
  • Previous by thread: color space curve
  • Next by thread: Re: color space curve