Re: Using an locator and Rotating 3D graphics
- To: mathgroup at smc.vnet.net
- Subject: [mg92581] Re: Using an locator and Rotating 3D graphics
- From: "David Park" <djmpark at comcast.net>
- Date: Tue, 7 Oct 2008 07:03:32 -0400 (EDT)
- References: <gccheo$s5t$1@smc.vnet.net>
Manipulate is like a set-piece dynamic display. It tries to be very versitle but for most custom dynamic presentations it becomes a pain-in-the-neck. It is better to learn how to construct your own dynamic presentations. Here is more direct code for your display: Module[ {pt1 = {1, 0}, pt2 = {0, 1}}, Row[{ Graphics[ {Dynamic@Arrow[{pt1, pt2}], Locator[Dynamic[pt1]], Locator[Dynamic[pt2]]}, PlotRange -> 2, ImageSize -> 200], Dynamic@ ParametricPlot3D[{Part[pt2 - pt1, 1] Cos[u], Part[pt2 - pt1, 2] Sin[u], u}, {u, 0, 4 Pi}, PlotRange -> {{-2, 2}, {-2, 2}}, ColorFunction -> Function[{x, y, z, u}, Hue[u]], PlotStyle -> Thick, ImageSize -> 350, BoxRatios -> {1, 1, 1}]}] ] You could use DynamicModule, but it really isn't necessary here. The Locators are confined to the lhs plot and not imposed on the entire display. In the code above I bypassed calculating the v variable you used. Let's reintroduce v. Quite often we might have a set of primary dynamic variables, such as pt1 and pt2 here, which are manipulated by the mouse or sliders or other dynamic elements, and a set of dependent dynamic variables that depend on the primary variables, such as v here. We can handle this situation as in the following code. Here we use the two argument form of Dynamic and when a primary dynamic variable is adjusted the routine calcAll is called to calculate all the dependent quantities (only v in this case). I've also made some stylistic changes to the display. Module[ {(* Primary dynamic variables *) pt1 = {1, 0}, pt2 = {0, 1}, (* Dependent dynamic variable *) v, (* Other variables *) calcAll}, calcAll[p1_, p2_] := (v = p2 - p1); (* Initialize dependent variables *) calcAll[pt1, pt2]; (* Display *) Panel[ Row[{ Graphics[ {Arrowheads[.1], Dynamic@Arrow[{pt1, pt2}], Locator[Dynamic[pt1, (pt1 = #; calcAll[pt1, pt2]) &], Graphics[{AbsolutePointSize[8], Point[{0, 0}]}, ImageSize -> 10]], Locator[Dynamic[pt2, (pt2 = #; calcAll[pt1, pt2]) &], None]}, PlotRange -> 2, ImageSize -> 200], Dynamic@ ParametricPlot3D[{v[[1]] Cos[u], v[[2]] Sin[u], u}, {u, 0, 4 Pi}, PlotRange -> {{-2, 2}, {-2, 2}}, ColorFunction -> Function[{x, y, z, u}, Hue[u]], PlotStyle -> Thick, Axes -> False, SphericalRegion -> True, RotationAction -> Clip, ImageSize -> 350, Boxed -> False, BoxRatios -> {1, 1, 1}]}], Style["Custom Dynamics", 16]] ] -- David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ "KB" <KennethLeeBaker at gmail.com> wrote in message news:gccheo$s5t$1 at smc.vnet.net... > When I try to use locators as inputs to 3D graphics, I end up not > being able to rotate 3d graphics. Clicking on the graphic moves the > nearest locator rather than the graphic. Switching to a collection of > 2D sliders works in a pinch, but does not achieve the desired effect. > Here is an example: > > Manipulate[v = pt2 - pt1; > {Graphics[Arrow[{pt1, pt2}], PlotRange -> 2], > ParametricPlot3D[{v[[1]] Cos[u], v[[2]] Sin[u], u}, {u, 0, 4 Pi}, > PlotRange -> {{-2, 2}, {-2, 2}}, > ColorFunction -> Function[{x, y, z, u}, Hue[u]], > PlotStyle -> Thick]}, {{pt1, {0, 1}}, Locator}, {{pt2, {1, 0}}, > Locator}] > > > Any ideas? >