MathGroup Archive 2006

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

Search the Archive

RE: Beginner Question

  • To: mathgroup at
  • Subject: [mg66590] RE: [mg66561] Beginner Question
  • From: "David Park" <djmp at>
  • Date: Sun, 21 May 2006 00:29:38 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

First we make a handy little operator that will rotate a 2D vector counter
clockwise by 90 degrees. You can check it out on various cases.

JOperator[{dx_, dy_}] := {-dy, dx}

The idea is then to make two vectors, ab = Point B - Point A, and ac = Point
C - Point A. Then we rotate ab by 90 degrees about a.
Jab = JOperator[ab]. Then we dot the rotated vector Jab with ac. If it is
positive the point is on the left, if zero on the line, and negative on the
right. The following is a routine with a usage message.

ptCSide::usage =
    "ptCSide[ptA, ptB][ptC] will tell if ptC is on the left, on the line, or
on the right of the oriented line going from ptA to ptB.";

ptCSide[ptA : {_, _}, ptB : {_, _}][ptC : {_, _}] :=
    {ab = ptB - ptA,
      ac = ptC - ptA,
      JOperator, Jab, dotproduct},

    JOperator[{dx_, dy_}] := {-dy, dx};
    Jab = JOperator[ab];
    dotproduct =;

      dotproduct > 0, "point on left",
      dotproduct == 0, "point on line",
      dotproduct < 0, "point on right"]

Here are some cases. For fixed ptA and ptB I map the routine onto 3
different ptC points.

ptA = {0, 0};
ptB = {1, 3};

ptCSide[ptA, ptB] /@ {{1, 0}, {2, 6}, {0, 1}}
{point on right, point on line, point on left}

David Park
djmp at

From: akil [mailto:akil39 at]
To: mathgroup at


Suppose I have three 2D points A, B, C.
And two points, namely A and B form a line.

How can I determine in mathematica on which side, (so which half-plane
formed by) of the line, point C is.

So when I input three points I want to know if the third point is on the
left or right side of the half plane formed by the line (ray) A,B.

Appreciate any help.

  • Prev by Date: Re: Beginner Question
  • Next by Date: Re: Insulating data from code
  • Previous by thread: Re: Beginner Question
  • Next by thread: Importing HDF with multiple SDS