MathGroup Archive 2012

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125147] Re: Dynamically finding distances and angles between user-specified points
  • From: Tomas Garza <tgarza10 at msn.com>
  • Date: Fri, 24 Feb 2012 00:59:20 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Try the following, which is a minor arrangement of your code. The angles are given in degrees:
Manipulate[Module[{r = 0.03, p1, p2, p3, p4,   a = 1,   b = 1, angABC, angDEF, angABE},  p1 = {a, b};  p2 = {-a, b};  p3 = {-a, -b};  p4 = {a, -b}; angABC = VectorAngle[p1 - p5, p2 - p5];   angDEF = VectorAngle[p4 - p6, p3 - p6];   angABE = VectorAngle[p1 - p5, p6];  Graphics[{{Red, Table[Disk[i, r], {i, {p1, p2, p3, p4}}]}, {Black,      Table[Disk[i, r], {i, {p5, p6}}]}, {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 = " <>         ToString[NumberForm= [180. angABC/\[Pi], {3, 0}]] <>         "\[Degree]", 14], {0.6, 0.6}, {-1, 0}],      Text[      Sty
 l!
e["\[Angle]DEF = " <>         ToString[NumberForm[180. angDEF/\[Pi], {3, 0}]] <>         "\[Degree]", 14], {0.6, 0.5}, {-1, 0}],      Text[Style[       "\[Angle]ABE = " <>         ToString[NumberForm[180. angABE/\[Pi], {3, 0}]] <>         "\[Degree]", 14], {0.6, 0.4}, {-1,0}],      Text[Style[       "AB = " <> ToString[NumberForm[Norm[p1 - p5],{4, 3}]],        14], {0.6, 0.3}, {-1, 0}],      Text[Style[       "BE = " <> ToString[NumberForm[Norm[p6 - p5], {4, 3}]],        14], {0.6, 0.2}, {-1, 0}]}}, Axes -> True,    PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}},    ImageSize -> 450]], {{p5, {0, 0.5}, "B"}, {-0.25, 0}, {0.5,    1}}, {{p6, {0, -0.5}, "E"}, {-1, -1}, {0.25, -0.25}}]
-Tomas

> Date: Thu, 23 Feb 2012 05:46:44 -0500
> From: adeyoung at andrew.cmu.edu
> Subject: Dynamically finding distances and angles between user-specified points
> To: mathgroup at smc.vnet.net
>
> 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
>


  • Prev by Date: Re: Executing a Notebook and saving the modified Notebook - all without the GUI
  • Next by Date: Re: Open nbs automatically with 150%
  • Previous by thread: Re: Dynamically finding distances and angles between user-specified points
  • Next by thread: Open nbs automatically with 150%