Hey, I'd like to reflect a triangle over symmetry line parallel to one of the sides using just point coordinates and Mat::at()
in OpenCV. So I simply reflect Point2d P over a line that consists triangle vertices P1,P2.
The problem is that I get some weird patterns and I can't get rid of them. I used doubles to enhance precision but it didn't help.
Any ideas?
if(P1.x-P2.x) //P1P2 is not vertical
{
double a=((P2.y-P1.y)/static_cast<double>(P2.x-P1.x));
double b=P1.y-a*P1.x; //symmetry line y=ax+b
double a1=0,b1=0;
if(a)
{
a1=-1/a; // y=a1x+b1 perpendicular to y=ax+b
b1=P.y-a1*P.x;
double xc=(b1-b)/(a-a1); // ax+b=a1x+b1
P.x= 2*xc-P.x;
P.y=a1*P.x+b1;
}
else //P1P2 is horizontal
{
P.y=2.0*P1.y-P.y;
}
}
else //P1P2 is vertical
{
P.x=2*P1.x-P.x;
}