public void SetRange(Point2d PtA, Point2d PtB) { PtLst[0] = PtA; PtLst[3] = PtB; PtLst[1] = PtA * alp + PtB * bta; PtLst[2] = PtA * bta + PtB * alp; for (int k = 0; k < 4; k++) { PtLst[k] = F.EstimatePt2Pt(PtLst[k]); } }
public Point2d IntersectionPoint(FuncApproximation F1, FuncApproximation F2, Point2d PtA, Point2d PtB, bool DispB = false) { this.F1 = F1; this.F2 = F2; Point Pt0 = (Point)((PtA + PtB) * 0.5); RegFuncUtilitySub FS1 = new RegFuncUtilitySub(F1, PtA, PtB); RegFuncUtilitySub FS2 = new RegFuncUtilitySub(F2, PtA, PtB); Point2d PtAns = new Point2d(); Mat resImg = null; try{ if (DispB) { resImg = ImgCheck.CvtColor(ColorConversionCodes.GRAY2BGR); //Gray->Color変換 for (int x = 0; x < ImgCheck.Width; x += 20) { Point P1 = new Point(x, F1.RegXY.Estimate(x)); Point P2 = P1 + (new Point(4, 4)); resImg.Rectangle(P1, P2, Scalar.Orange, 3); } for (int y = 0; y < ImgCheck.Height; y += 20) { Point P1 = new Point(F2.RegXY.Estimate(y), y); Point P2 = P1 + (new Point(4, 4)); resImg.Rectangle(P1, P2, Scalar.Blue, 3); } resImg.Circle(Pt0, 10, Scalar.Red, 5); using (new Window("IntersectionPoint", WindowMode.KeepRatio, resImg)){ Cv2.WaitKey(0); } } Point2d PtAns2 = F2.EstimatePt2Pt(Pt0), PtAns1 = Pt0; int loop = 5; while (--loop > 0) { double vAns1 = FS1.__Solve(PtAns2, ref PtAns1); if (DispB) { resImg.Circle((Point)PtAns2, 5, Scalar.Blue, 3); resImg.Circle((Point)PtAns1, 5, Scalar.Red, loop * 2); using (new Window("IntersectionPoint", WindowMode.KeepRatio, resImg)){ Cv2.WaitKey(0); } } double vAns2 = FS2.__Solve(PtAns1, ref PtAns2); if (DispB) { resImg.Circle((Point)PtAns2, 5, Scalar.Red, 3); resImg.Circle((Point)PtAns1, 5, Scalar.Blue, loop * 2); using (new Window("IntersectionPoint", WindowMode.KeepRatio, resImg)){ Cv2.WaitKey(0); } } if (vAns1 < 0.01 && vAns2 < 0.01) { break; } FS1.SetRange(PtA, PtB); FS2.SetRange(PtA, PtB); } PtAns = FS1.Estimate(PtAns2); } catch (Exception e) { WriteLine(e.Message + "\r" + e.StackTrace); } return(PtAns); }