Exemplo n.º 1
0
        //
        //ptを通る直交する直線
        // A*A' = -1
        //
        public FN1D GetNormFn(PointF pt)
        {
            if (this.A == 0.0)
            {
                //当該直線は水平→垂直の直線を作成
                FN1D fn = new FN1D(double.NaN, double.NaN, pt.X);
                //fn.A = double.NaN;
                //fn.B = double.NaN;
                //fn.C = pt.X;
                return(fn);
            }
            else if (double.IsNaN(this.A))
            {
                //当該直線は垂直→水平の直線を作成
                FN1D fn = new FN1D(0, pt.Y, double.NaN);
                //fn.A = 0;
                //fn.B = pt.Y;
                //fn.C = double.NaN;
                return(fn);
            }
            else
            {
//				double A = this.A * (-1);
                double A = (-1) / this.A;
                double B = pt.Y - A * pt.X;
                return(new FN1D(A, B));
            }
        }
Exemplo n.º 2
0
        //---
        // Y = A1*X + B1
        // と
        // Y = A2*X + B2
        // 交点を求める
        // A1*X + B1 = A2*X + B2
        // A1*X - A2*X = B2 - B1
        // X(A1-A2) = B2 - B1
        // X = (B2 - B1) / (A1 - A2)
        public PointF GetCrossPt(FN1D fn)
        {
            PointF pt = new PointF();

            if (this.A == fn.A)
            {
                pt.X = pt.Y = float.NaN;
            }
            else if (this.A == fn.A)
            {
                //両直線は平行
                if (double.IsNaN(this.A))
                {
                    G.mlog("here");
                    this.A = this.A;
                }
                pt.X = pt.Y = float.NaN;
            }
            else if (double.IsNaN(this.A))
            {
                //当該直線は垂直
                if (double.IsNaN(fn.A))
                {
                    //対象直線は垂直
                    pt.X = pt.Y = float.NaN;
                }
                else if (fn.A == 0.0)
                {
                    //対象直線は水平
                    pt.X = (float)this.C;
                    pt.Y = (float)fn.B;
                }
                else
                {
                    pt.X = (float)this.C;
                    pt.Y = (float)(fn.A * pt.X + fn.B);
                }
            }
            else if (this.A == 0.0)
            {
                //当該直線は水平
                if (double.IsNaN(fn.A))
                {
                    //対象直線は垂直
                    pt.X = (float)fn.C;
                    pt.Y = (float)this.B;
                }
                else if (fn.A == 0.0)
                {
                    //対象直線は水平
                    pt.X = pt.Y = float.NaN;
                }
                else
                {
                    pt.Y = (float)this.B;
                    pt.X = (float)((pt.Y - fn.B) / fn.A);
                }
            }
            else
            {
                pt.X = (float)((fn.B - this.B) / (this.A - fn.A));
                pt.Y = (float)(this.A * pt.X + this.B);
            }
            return(pt);
        }