MathGroup Archive 2012

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

Search the Archive

Dynamically finding distances and angles between user-specified points


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

I have posted a figure showing these points and their relation to one

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};

  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}}]}],
    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[\

where \[Theta] is the angle between pvector and qvector.  So \[Theta]

\[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: Why HoldForm[] shows this expression in red in notebook?
  • Next by Date: Re: Extensive replacement of trigonometric functions
  • Previous by thread: Re: Executing a Notebook and saving the modified Notebook - all without the GUI
  • Next by thread: Re: Dynamically finding distances and angles between user-specified points