Qt
has a class QRect
which tells whether the point is inside the rectangle or not.
Now, the problem is to find out on which outer side (out of four) of the rectangle does the point lie.
The equation that I already have is:
C++
code:
double m = (y2 - y1) / (x2 - x1);
double equationResult = (newY - y1) - ((m * newX) + (m * x1));
if (equationResult < 0)
return "in";
else
return "out";
where newX
and newY
are the points which we are supposed to check.
Assumption:
The point lies on the right hand side of the rectangle.
So, with this assumption in mind when I supplied the end points of the top of the rectangle, the result I got was "out"
.
Even with the end points of the right side, the result I got was "out"
.
So, if more than one sides are going to give the same output, how am I supposed to know the position of the point?
double
, you might just fall victim to some rounding errors. – Sep 12 '12 at 05:56