RE: Beginner Question
- To: mathgroup at smc.vnet.net
- Subject: [mg66590] RE: [mg66561] Beginner Question
- From: "David Park" <djmp at earthlink.net>
- Date: Sun, 21 May 2006 00:29:38 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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 : {_, _}] := Module[ {ab = ptB - ptA, ac = ptC - ptA, JOperator, Jab, dotproduct}, JOperator[{dx_, dy_}] := {-dy, dx}; Jab = JOperator[ab]; dotproduct = Jab.ac; Which[ 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 earthlink.net http://home.earthlink.net/~djmp/ From: akil [mailto:akil39 at gmail.com] To: mathgroup at smc.vnet.net Hi, 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.