Example #1
0
        public static NI2dVector refractedRay(NI2dVector i, NI2dVector ns, double n1, double n2)
        {
            NI2dVector r = new NI2dVector(0, 0);
            NI2dVector n = new NI2dVector(0, 0);

            i.Normalize();
            ns.Normalize();

            double ncheck = i.DotProduct(ns);

            if (ncheck >= 0.0)
            {
                n = ns;
            }
            if (ncheck < 0.0)
            {
                n = -1 * ns;
            }

            double delta = 1 - ((n1 / n2) * (n1 / n2) * (1 - (i.DotProduct(n) * i.DotProduct(n))));

            if (delta > 0)
            {
                r = (n1 / n2) * i + ((-1 * (i.DotProduct(n)) * (n1 / n2) + Math.Sqrt(delta)) * n);
            }
            if (delta <= 0)
            {
                r = reflectedRay(i, ns);
            }

            return(r);
        }
Example #2
0
        public static NI2dPoint divergingOvalptpt(NI2dPoint F, double n1, NI2dVector v, NI2dPoint G, double n2, double S)
        {
            NI2dPoint ovalpt = new NI2dPoint(0, 0);

            v.Normalize();
            NI2dVector v1    = new NI2dVector(F, G);
            double     C1    = n1 * S + (n2 * n2) * v1.DotProduct(v);
            double     C2    = S * S - (n2 * n2) * v1.DotProduct(v1);
            double     gamma = -1.0;
            double     sigma = 0.0;

            if (n1 > n2)
            {
                sigma = -1 * gamma;
            }
            else if (n1 < n2)
            {
                sigma = 1 * gamma;
            }

            double c1numerator   = C1 + sigma * Math.Sqrt(C2 * (n2 * n2 - n1 * n1) + C1 * C1);
            double c1denominator = n1 * n1 - n2 * n2;
            double c1            = c1numerator / c1denominator;

            ovalpt = F + c1 * v.ConverttoPoint();

            return(ovalpt);
        }
Example #3
0
        public static NI2dVector refractedNormal(NI2dVector i, NI2dVector r, double n1, double n2)
        {
            NI2dVector n = new NI2dVector(0, 0);

            i.Normalize();
            r.Normalize();

            n = ((n1 * i) - (n2 * r)) / ((i - r).Magnitude);
            return(n);
        }
Example #4
0
        public static NI2dVector reflectedRay(NI2dVector i, NI2dVector n)
        {
            NI2dVector r = new NI2dVector(0, 0);

            i.Normalize();
            n.Normalize();
            r = i - 2 * (i.DotProduct(n)) * n;

            return(r);
        }
Example #5
0
        public static NI2dPoint reflectingOvalptpt(NI2dPoint F, NI2dVector v, NI2dPoint G, double n, double S)
        {
            NI2dPoint ovalpt = new NI2dPoint(0, 0);

            v.Normalize();
            NI2dVector v1            = new NI2dVector(F, G);
            double     c1numerator   = (S / n) * (S / n) - v1.DotProduct(v1);
            double     c1denominator = 2 * ((S / n) + v1.DotProduct(v));
            double     c1            = c1numerator / c1denominator;

            ovalpt = F + c1 * v.ConverttoPoint();

            return(ovalpt);
        }