RE: a visualization problem in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg38332] RE: [mg38285] a visualization problem in Mathematica
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 12 Dec 2002 01:36:01 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Borut, Here is a routine that will generate two different random points on a unit sphere. twoPoints := With[ {phi1 = Random[Real, {0, Pi/2}], phi2 = Random[Real, {Pi/2 + 0.01, Pi}], theta1 = Random[Real, {0, 2Pi}], theta2 = Random[Real, {0, 2Pi}]}, {{Cos[theta1]Sin[phi1], Sin[theta1]Sin[phi1], Cos[phi1]}, {Cos[theta2]Sin[phi2], Sin[theta2]Sin[phi2], Cos[phi2]}} ] The following routine generates the parametrization in t for a great circle going through the two points and an interator giving the short great circle arc between the two points. greatCircleArc[{pt1_, pt2_}] := Module[{n, e1, e2, t1, t2}, n = pt1\[Cross]pt2; {e1, e2} = (NullSpace[{N[n]}]) // Chop; t1 = ArcTan @@ (pt1.# & /@ {e1, e2}); t2 = ArcTan @@ (pt2.# & /@ {e1, e2}); {t1, t2} = Sort[{t1, t2}]; {t1, t2} = Which[ t2 - t1 <= Pi, {t1, t2}, t2 - t1 > Pi, {t2, 2Pi + t1}]; {Cos[t]e1 + Sin[t]e2, {t, t1, t2}}] You can use that to plot the arc in a 3D plot. Since I want to combine a number of elements in the plot I find it much easier to use my DrawGraphics package from my web site. Here is the code for a plot that draws a wire frame sphere, the two points, the short arc and the complete great circle. Needs["DrawGraphics`DrawingMaster`"] pts = twoPoints; plotargs = greatCircleArc[pts]; Draw3DItems[ {(* Draw WireFrame sphere *) ColorMix[Cobalt, Gray][0.5], ParametricDraw3D[{Cos[t]Sin[p], Sin[t]Sin[p], Cos[p]}, {p, 0, Pi}, {t, 0, 2Pi}, PlotPoints -> {15, 31}] // UseWireFrame, (* Draw entire great circle *) PermanentGreen, ParametricDraw3D[First[plotargs] // Evaluate, {t, 0, 2Pi}], (* Draw short great circle arc *) AbsoluteThickness[2], EnglishRed, ParametricDraw3D @@ plotargs, (* Plot the two points *) AbsolutePointSize[6], Black, Point /@ pts}, BoxStyle -> LightGray, Background -> Linen, ImageSize -> 450]; David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Borut L [mailto:gollum at email.si] To: mathgroup at smc.vnet.net Hi, I have the following problem. Given two random points on a sphere, I would like to connect them with a curve that goes 'approximately' on the sufrace of the spehere. I wrote approximately, because the curve would be made of line segments. Connecting the points with a straigh line is achived by Line[{pt1,pt2}]. I am failing to get good ideas on how to approach the problem, would appreciate any hint / trick / tip. Thank you, Borut Levart Slovenia