Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 30 July 2009 - 12:47 AM
Posted 30 July 2009 - 12:55 AM
Posted 30 July 2009 - 12:57 AM
int side(vector2 p1, vector2 p2, vector2 p)
{
vector2 diff = p2 - p1;
vector2 perp(-diff.y, diff.x);
float d = dot(p - p1, perp);
return sign(d);
}
Posted 30 July 2009 - 06:46 AM
Posted 30 July 2009 - 11:46 AM
Quote:Just for the record, the techniques are exactly the same, just written differently. Here's how to get from my version to ToohrVyk's version:
I used the first technique.
diff.x = Bx - Ax
diff.y = By - Ay
perp.x = Ay - By
perp.y = Bx - Ax
dot(p - p1, perp) =
(Cx - Ax) * (Ay - By) + (Cy - Ay) * (Bx - Ax) =
(Bx - Ax) * (Cy - Ay) - (By - Ay) * (Cx - Ax)
Posted 18 August 2009 - 07:49 PM
Posted 19 August 2009 - 01:03 AM
Quote:Wait...how is that different than what ToohrVyk and I posted? (Aside from being arranged differently, that is.)
Original post by TSIROS
this is a straight approach, with simple geometry
a rectangular R=(Bx-Ax)*(By-Ay)
two rectangulars
R1=(Bx-Ax)*(Cy-Ay)
R2=(Bx-Cx)*(By-Ay)
R-R1-R2 = (Bx - Ax) * (By - Cy) - (By - Ay) * (Bx - Cx) (1)
instead of previous (Bx - Ax) * (Cy - Ay) - (By - Ay) * (Cx - Ax)
if (1) = 0 "on"
if (1) < 0 "left"
if (1) > 0 "right"
no corrections needed
Posted 19 August 2009 - 06:44 AM
Quote:Your method performs a dot product as well.
you use dot product , i use simple geometry, there is a difference.
Posted 25 July 2011 - 03:34 AM
Vector2f myFirstPoint = new Vector2f(100,100); Vector2f myDirection = new Vector2f(1,0); public boolean inside(Vector2f aPosition) { final Vector2f lineToPosition = new Vector2f(aPosition); lineToPosition.sub(myFirstPoint); float dotProduct = (myDirection.x) * (lineToPosition.y) - (myDirection.y) * (lineToPosition.x); if (dotProduct > 0) { return false; } return true; }
Posted 25 July 2011 - 03:47 AM
Posted 25 July 2011 - 04:00 AM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.