polygon - Point inside rotated 2D rectangle (not using translation, trig functions, or dot product) -


i wondering if following algorithm check if point inside rectangle valid. i've developed using own intuition (no strong trig/math basis support it), i'd love hear more experience in matter.

context:

  • the rectangle defined 4 points. rotated.
  • coordinates positive.
  • by definition, point considered inside rectangle if intersects it.

hypothesis:

  • use distance between point , rectangle vertices (first diagram below).
  • the maximum possible total distance when point in 1 vertex (second diagram).
  • if point outside rectangle, distance greater (third diagram).

diagram link: http://i45.tinypic.com/id6o35.png

algorithm (java):

static boolean pointinsiderectangle(point[] rect, point point) {     double maxdistance = distance(rect[0], rect[1]);     maxdistance += distance(rect[0], rect[2]);     maxdistance += distance(rect[0], rect[3]);      double distance = 0;     (point rectpoint : rect) {                   distance += distance(rectpoint, point);         if (distance > maxdistance) return false;     }     return true; } 

questions: correct?

short answer: no :p (don´t fell bad it)

long answer: intersecction areas 4 circles mention (max distance between opposite vertex) not produce rectangle.common area of 4 circles of radius equal rectangle´s diagonal center in each corner since i´m bit rusty in geometry can´t give full mathematical explanation (time constrain part), give pseudocode of procedure constrains ask (no fancy formulae), valid rectangle wikipeida or geometry book can fill gaps.

  • find n,e,s,w vertex (the uppermost, rightmost, lowest , leftmost vertex) trivially easy rectangle axis aligned can produce oddly assignation of vertex (see images examples) enter image description here
  • find ne, se, sw , nw border, line equation in wikipedia or link, again should easy, axis aligned border should analized because generate type of ecuation/restriction.
  • check if point on "right side" of border see inequality mathematical term, point inside rectangle satisfy 4 restrictions can see in image attached. for each "border" green area present valid place point

  • my apologies if have overlook command of java.geom can accomplish task

i hope endevour


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -