Re: Dynamically finding distances and angles between user-specified points

*To*: mathgroup at smc.vnet.net*Subject*: [mg125140] Re: Dynamically finding distances and angles between user-specified points*From*: "djmpark" <djmpark at comcast.net>*Date*: Fri, 24 Feb 2012 00:56:53 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <20462297.102235.1329995808308.JavaMail.root@m06>

This is the way I would do it in Presentations. << Presentations` DynamicModule[ {(* Fixed points *) ptA = {1, 1}, ptD = {1, -1}, ptF = {-1, -1}, ptC = {-1, 1}, (* Dynamic points *) ptB = {0, 0.5}, ptE = {0, -0.5}, (* Secondary Dynamic variables *) angleABC, angleDEF, angleABE, lengthAB, lengthBE, calcAll}, (* Routine to calculate secondary variables *) calcAll[b_, e_] := (angleABC = VectorAngle[ptA - ptB, ptC - ptB]; angleDEF = VectorAngle[ptD - ptE, ptF - ptE]; lengthAB = Norm[ptA - ptB]; lengthBE = Norm[ptB - ptE];); (* Initialize *) calcAll[ptB, ptE]; (* Display *) panelpage[ phrase[ (* Diagram *) Draw2D[ {Dynamic@ {Line[{ptA, ptB, ptC}], Line[{ptD, ptE, ptF}], AbsoluteThickness[2], Line[{ptB, ptE}], MapThread[ Text[#1, (Norm[#2] + 0.07) Normalize[#2]] &, {{"B", "E"}, {ptB, ptE}}]}, MapThread[ Text[#1, 1.07 #2] &, {{"A", "C", "D", "F"}, {ptA, ptC, ptD, ptF}}], CirclePoint[#, 3, Black, Red] & /@ {ptA, ptC, ptD, ptF}, Locator[Dynamic[ptB, (ptB = #; calcAll[ptB, ptE]) &], CirclePointLocator[3, Blue]], Locator[Dynamic[ptE, (ptE = #; calcAll[ptB, ptE]) &], CirclePointLocator[3, Blue]] }, PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}}, Frame -> True, ImageSize -> 300], Spacer[10], (* Geometric values *) Dynamic@ pagelet[ phrase["B: ", NumberForm[ptB, {5, 3}]], phrase["E: ", NumberForm[ptE, {5, 3}]], "", phrase["\[Angle]ABC: ", angleABC/Degree, "\[Degree]"], phrase["\[Angle]DEF: ", angleDEF/Degree, "\[Degree]"], phrase["|AB|: ", lengthAB], phrase["|BE|: ", lengthBE] ] ](* phrase *), Style["Presentation for Andrew DeYoung", 16], paneWidth -> 470 ](* panelpage *) ] CirclePoints make better locators for geometric diagrams than the Wolfram gun-sight. VectorAngle is a convenient method to obtain the angle between two vectors. But it always returns the smaller of the two angles. Presentations has a vectorSign routine that helps you distinguish if that's important. A Frame is better than an Axis (which stomps all over the diagram). I wouldn't use a Slider here. The idea of combining a diagram with metric numerical values, as you have done, is a very effective technique for conveying information and tying geometry to analysis. In this dynamic presentation, ptB and ptE are primary dynamic variables set by the locators, angleABC, angleDEF, lengthAB and lengthBE are secondary dynamic variables that are calculated by the calcAll routine, which in turn is called in the second argument to Dynamic in the Locators. It would be nice if Delimiter could be used in Column to provide a width filling separater line. David Park djmpark at comcast.net http://home.comcast.net/~djmpark/index.html From: Andrew DeYoung [mailto:adeyoung at andrew.cmu.edu] Hi, I wish to create a simple Manipulate-type interactive "applet" in which the user can control the (x,y) coordinates of two points, which I will call points B and E. (Suppose that B has coordinates (xB,yB) and E has coordinates (xE,yE).) Now suppose there are points A, C, D, and F which are fixed in space. A and B, B and C, B and E, D and E, and E and F are connected by line segments. I would like to write a Manipulate-type dynamic "applet" that prints the values of various line segments (for example, of line segments AB and BE) and of various angles (for example, of angles ABC, DEF, and ABE), preferably updated dynamically. I have posted a figure showing these points and their relation to one another: http://www.andrew.cmu.edu/user/adeyoung/feb22/figure.gif I made the above posted figure with the following commands: (* Begin code *) r = 0.03; a = 1; b = 1; p1 = {a, b}; p2 = {-a, b}; p3 = {-a, -b}; p4 = {a, -b}; p5 = {0, 0.5}; p6 = {0, -0.5}; Show[{ Graphics[{Red, Table[Disk[i, r], {i, {p1, p2, p3, p4}}]}, Axes -> True, AxesLabel -> {"x", "y"}, AspectRatio -> 1], Graphics[{Black, Table[Disk[i, r], {i, {p5, p6}}]}], Graphics[{ Text[Style["(xB, yB)", 18], p5, {-1.2, 0}], Text[Style["(xE, yE)", 18], p6, {-1.2, 0}], Text[Style["A", Red, 18], p1, {-1.8, 0}], Text[Style["C", Red, 18], p2, {1.8, 0}], Text[Style["F", Red, 18], p3, {1.8, 0}], Text[Style["D", Red, 18], p4, {-1.8, 0}], Text[Style["B", 18], p5, {-1, -1}], Text[Style["E", 18], p6, {-1, 1.5}], Line[{p1, p5, p2}], Line[{p3, p6, p4}], {Thickness[0.01], Line[{p5, p6}]}, Text[Style["\[Angle]ABC = ?", 14], {0.6, 0.6}, {-1, 0}], Text[Style["\[Angle]DEF = ?", 14], {0.6, 0.5}, {-1, 0}], Text[Style["\[Angle]ABE = ?", 14], {0.6, 0.4}, {-1, 0}], Text[Style["AB = ?", 14], {0.6, 0.3}, {-1, 0}], Text[Style["BE = ?", 14], {0.6, 0.2}, {-1, 0}] }] }] (* End code *) My question is, do you have any advice for computing the distances and angles dynamically? Do you recommend that I use a Locator or a Slider2D control object? Also, do you think that I can compute the angles dynamically using the following vector relation? pvector (dot product) qvector = Norm[pvector]*Norm[qvector]*Cos[\ [Theta]] where \[Theta] is the angle between pvector and qvector. So \[Theta] is: \[Theta] = ArcCos[Dot[pvector, qvector]/(Norm[pvector]*Norm[qvector])] If, for example, I want to find the angle ABC, then pvector is the vector from A to B (or from B to A) and qvector is the vector from B to C (or from C to B). Thanks so much for your time. Andrew DeYoung Carnegie Mellon University

**Open nbs automatically with 150%**

**Re: Reading Single and Double reals in Little-endian and Big-endian**

**Dynamically finding distances and angles between user-specified points**

**Re: Dynamically finding distances and angles between user-specified points**