コード例 #1
0
ファイル: NuGenVector.cs プロジェクト: carlhuth/GenXSource
 public static bool ApproxEquals(NuGenVec3D a, NuGenVec3D b)
 {
     return
         (Math.Abs(a._x[0] - b._x[0]) < NuGenVector.TINY_DOUBLE &&
          Math.Abs(a._x[1] - b._x[1]) < NuGenVector.TINY_DOUBLE &&
          Math.Abs(a._x[2] - b._x[2]) < NuGenVector.TINY_DOUBLE);
 }
コード例 #2
0
ファイル: NuGenSphere3D.cs プロジェクト: carlhuth/GenXSource
        public bool Intersect(NuGenRay3D ray, ref double t, ref NuGenVec3D normal)
        {
            NuGenVec3D l = center - ray.Point;

            double s  = NuGenVec3D.Dot(l, ray.Direction);
            double l2 = l.SquaredLength;
            double rr = radius * radius;

            if (s < 0.0 && l2 > rr)
            {
                return(false);
            }

            double m2 = l2 - s * s;

            if (m2 > rr)
            {
                return(false);
            }

            double q = Math.Sqrt(rr - m2);

            if (l2 > rr)
            {
                t = s - q;
            }

            else
            {
                t = s + q;
            }
            normal = (ray.Point + ray.Direction * t) - center;
            normal.Normalize();
            return(true);
        }
コード例 #3
0
        public bool Intersect(
            NuGenRay3D ray, ref double t, ref double u, ref double v, ref NuGenVec3D normal
            )
        {
            NuGenVec3D e1 = p1 - p0;
            NuGenVec3D e2 = p2 - p0;
            NuGenVec3D p = NuGenVec3D.Cross(ray.Direction, e2);

            double a = NuGenVec3D.Dot(e1, p);

            if (a > -NuGenVector.TINY_DOUBLE && a < NuGenVector.TINY_DOUBLE) return false;

            double f = 1.0 / a;
            NuGenVec3D s = ray.Point - p0;
            u = f * NuGenVec3D.Dot(s, p);

            if (u < 0.0 || u > 1.0) return false;
            NuGenVec3D q = NuGenVec3D.Cross(s, e1);
            v = f * NuGenVec3D.Dot(ray.Direction, q);

            if (v < 0.0 || (u + v) > 1.0) return false;
            t = f * NuGenVec3D.Dot(e2, q);
            normal = NuGenVec3D.Cross(e1, e2); normal.Normalize();
            return true;
        }
コード例 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (u_x1_3.Text == "" || u_x2_3.Text == "" || u_y1_3.Text == "" || u_y2_3.Text == "" || u_h1.Text == "" || u_h2.Text == "")
            {
                MessageBox.Show("Please Enter All The Values For Both The Vectors");
            }
            else
            {
                vector1_3 = new Genetibase.MathX.NuGenStructures.NuGenVec3D();

                vector1_3._x = new Double[3];

                vector1_3._x[0] = Double.Parse(u_x1_3.Text);
                vector1_3._x[1] = Double.Parse(u_y1_3.Text);
                vector1_3._x[2] = Double.Parse(u_h1.Text);


                vector2_3    = new Genetibase.MathX.NuGenStructures.NuGenVec3D();
                vector2_3._x = new Double[3];

                vector2_3._x[0] = double.Parse(u_x2_3.Text);
                vector2_3._x[1] = double.Parse(u_y2_3.Text);
                vector2_3._x[2] = Double.Parse(u_h2.Text);


                button_add_3.Enabled        = true;
                button_div_3.Enabled        = true;
                button_equal_3.Enabled      = true;
                button_less_equal_3.Enabled = true;
                button_mul_3.Enabled        = true;

                button_sub_3.Enabled = true;
            }
        }
コード例 #5
0
ファイル: NuGenRot3D.cs プロジェクト: carlhuth/GenXSource
        public NuGenRot3D(NuGenVec3D from, NuGenVec3D to)
        {
            from.Normalize();
            to.Normalize();

            double cost =
                NuGenVec3D.Dot(from, to) /
                Math.Sqrt(NuGenVec3D.Dot(from, to) * NuGenVec3D.Dot(to, to));

            if (cost > 0.99999)
            {
                r = 1;
                v = new NuGenVec3D(0, 0, 0);
            }

            else if (cost < -0.99999)
            {
                NuGenVec3D frm = from.Normalized;
                v = NuGenVec3D.Cross(frm, NuGenVec3D.UnitX);

                if (v.Length < 0.00001)
                {
                    v = NuGenVec3D.Cross(frm, NuGenVec3D.UnitY);
                }
                r = 0;
                v.Normalize();
            }

            else
            {
                r  = Math.Sqrt(0.5 * (1.0 + cost));
                v  = NuGenVec3D.Cross(from, to);
                v *= Math.Sqrt((0.5 * (1.0 - cost)) / NuGenVec3D.Dot(v, v));
            }
        }
コード例 #6
0
ファイル: NuGenRot3D.cs プロジェクト: xuchuansheng/GenXSource
        public NuGenRot3D(NuGenVec3D from, NuGenVec3D to)
        {
            from.Normalize();
            to.Normalize();

            double cost =
                NuGenVec3D.Dot(from, to) /
                Math.Sqrt(NuGenVec3D.Dot(from, to) * NuGenVec3D.Dot(to, to));

            if (cost > 0.99999)
            {
                r = 1;
                v = new NuGenVec3D(0, 0, 0);
            }

            else if (cost < -0.99999)
            {
                NuGenVec3D frm = from.Normalized;
                v = NuGenVec3D.Cross(frm, NuGenVec3D.UnitX);

                if (v.Length < 0.00001) v = NuGenVec3D.Cross(frm, NuGenVec3D.UnitY);
                r = 0;
                v.Normalize();
            }

            else
            {
                r = Math.Sqrt(0.5 * (1.0 + cost));
                v = NuGenVec3D.Cross(from, to);
                v *= Math.Sqrt((0.5 * (1.0 - cost)) / NuGenVec3D.Dot(v, v));
            }
        }
コード例 #7
0
 public static NuGenVec3D Max(NuGenVec3D a, NuGenVec3D b)
 {
     return(new NuGenVec3D(
                Math.Max(a._x[0], b._x[0]),
                Math.Max(a._x[1], b._x[1]),
                Math.Max(a._x[2], b._x[2])
                ));
 }
コード例 #8
0
 public static NuGenVec3D Cross(NuGenVec3D a, NuGenVec3D b)
 {
     return(new NuGenVec3D(
                a.y * b.z - a.z * b.y,
                a.z * b.x - a.x * b.z,
                a.x * b.y - a.y * b.x
                ));
 }
コード例 #9
0
        public override bool Equals(object obj)
        {
            NuGenVec3D x = (NuGenVec3D)obj;

            return(
                _x[0] == x._x[0] &&
                _x[1] == x._x[1] &&
                _x[2] == x._x[2]
                );
        }
コード例 #10
0
        public bool Intersect(NuGenRay3D ray, ref double t, ref NuGenVec3D normal)
        {
            NuGenVec3D l = center - ray.Point;

            double s = NuGenVec3D.Dot(l, ray.Direction);
            double l2 = l.SquaredLength;
            double rr = radius * radius;

            if (s < 0.0 && l2 > rr) return false;

            double m2 = l2 - s * s;

            if (m2 > rr) return false;

            double q = Math.Sqrt(rr - m2);

            if (l2 > rr) t = s - q;

            else t = s + q;
            normal = (ray.Point + ray.Direction * t) - center;
            normal.Normalize();
            return true;
        }
コード例 #11
0
        public bool Intersect(
            NuGenRay3D ray, ref double t, ref double u, ref double v, ref NuGenVec3D normal
            )
        {
            NuGenVec3D e1 = p1 - p0;
            NuGenVec3D e2 = p2 - p0;
            NuGenVec3D p  = NuGenVec3D.Cross(ray.Direction, e2);

            double a = NuGenVec3D.Dot(e1, p);

            if (a > -NuGenVector.TINY_DOUBLE && a < NuGenVector.TINY_DOUBLE)
            {
                return(false);
            }

            double     f = 1.0 / a;
            NuGenVec3D s = ray.Point - p0;

            u = f * NuGenVec3D.Dot(s, p);

            if (u < 0.0 || u > 1.0)
            {
                return(false);
            }
            NuGenVec3D q = NuGenVec3D.Cross(s, e1);

            v = f * NuGenVec3D.Dot(ray.Direction, q);

            if (v < 0.0 || (u + v) > 1.0)
            {
                return(false);
            }
            t      = f * NuGenVec3D.Dot(e2, q);
            normal = NuGenVec3D.Cross(e1, e2); normal.Normalize();
            return(true);
        }
コード例 #12
0
ファイル: NuGenVen3D.cs プロジェクト: xuchuansheng/GenXSource
 public static NuGenVec3D Max(NuGenVec3D a, NuGenVec3D b)
 {
     return new NuGenVec3D(
         Math.Max(a._x[0], b._x[0]),
         Math.Max(a._x[1], b._x[1]),
         Math.Max(a._x[2], b._x[2])
         );
 }
コード例 #13
0
ファイル: NuGenVen3D.cs プロジェクト: xuchuansheng/GenXSource
 public static NuGenVec3D Cross(NuGenVec3D a, NuGenVec3D b)
 {
     return new NuGenVec3D(
         a.y * b.z - a.z * b.y,
         a.z * b.x - a.x * b.z,
         a.x * b.y - a.y * b.x
         );
 }
コード例 #14
0
 public NuGenShift3D(double x, double y, double z)
 {
     v = new NuGenVec3D(x, y, z);
 }
コード例 #15
0
ファイル: NuGenScale3D.cs プロジェクト: carlhuth/GenXSource
 public NuGenScale3D(double x, double y, double z)
 {
     v = new NuGenVec3D(x, y, z);
 }
コード例 #16
0
 public static double Dot(NuGenVec3D u, NuGenVec3D v)
 {
     return(u[0] * v[0] + u[1] * v[1] + u[2] * v[2]);
 }
コード例 #17
0
ファイル: NuGenRay3D.cs プロジェクト: xuchuansheng/GenXSource
 public NuGenRay3D(NuGenPnt3D p, NuGenVec3D v)
 {
     this.p = p;
     this.v = v;
 }
コード例 #18
0
ファイル: NuGenRot3D.cs プロジェクト: xuchuansheng/GenXSource
 public NuGenRot3D(double radians, NuGenVec3D axis)
 {
     axis.Normalize();
     r = Math.Cos(radians / 2.0);
     v = axis.Normalized * Math.Sin(radians / 2.0);
 }
コード例 #19
0
ファイル: NuGenScale3D.cs プロジェクト: carlhuth/GenXSource
 public NuGenScale3D(NuGenVec3D shift)
 {
     v = shift;
 }
コード例 #20
0
ファイル: NuGenRay3D.cs プロジェクト: carlhuth/GenXSource
 public NuGenRay3D(NuGenPnt3D p, NuGenVec3D v)
 {
     this.p = p;
     this.v = v;
 }
コード例 #21
0
ファイル: NuGenRot3D.cs プロジェクト: carlhuth/GenXSource
 public NuGenRot3D(double radians, NuGenVec3D axis)
 {
     axis.Normalize();
     r = Math.Cos(radians / 2.0);
     v = axis.Normalized * Math.Sin(radians / 2.0);
 }
コード例 #22
0
 public NuGenScale3D(double x, double y, double z)
 {
     v = new NuGenVec3D(x, y, z);
 }
コード例 #23
0
ファイル: NuGenBox3D.cs プロジェクト: carlhuth/GenXSource
        public bool Intersect(NuGenRay3D r)
        {
            bool inside = true;

            int[] quadrant = new int[3];
            int   i;
            int   whichPlane;

            double[]   maxT           = new double[3];
            double[]   candidatePlane = new double[3];
            NuGenVec3D coord          = new NuGenVec3D(0, 0, 0);

            for (i = 0; i < 3; i++)
            {
                if (r.Point[i] < lower[i])
                {
                    quadrant[i]       = 1;
                    candidatePlane[i] = lower[i];
                    inside            = false;
                }

                else if (r.Point[i] > upper[i])
                {
                    quadrant[i]       = 0;
                    candidatePlane[i] = upper[i];
                    inside            = false;
                }

                else
                {
                    quadrant[i] = 2;
                }
            }

            if (inside)
            {
                return(true);
            }

            for (i = 0; i < 3; i++)
            {
                if (quadrant[i] != 2 && r.Direction[i] != 0.0)
                {
                    maxT[i] = (candidatePlane[i] - r.Point[i]) / r.Direction[i];
                }

                else
                {
                    maxT[i] = -1.0;
                }
            }

            whichPlane = 0;

            for (i = 1; i < 3; i++)
            {
                if (maxT[whichPlane] < maxT[i])
                {
                    whichPlane = i;
                }
            }

            if (maxT[whichPlane] < 0.0)
            {
                return(false);
            }

            for (i = 0; i < 3; i++)
            {
                if (whichPlane != i)
                {
                    coord[i] = r.Point[i] + maxT[whichPlane] * r.Direction[i];

                    if (coord[i] < lower[i] || coord[i] > upper[i])
                    {
                        return(false);
                    }
                }

                else
                {
                    coord[i] = candidatePlane[i];
                }
            }

            return(true);
        }
コード例 #24
0
        private void button2_Click(object sender, EventArgs e)
        {

            if (u_x1_3.Text == "" || u_x2_3.Text == "" || u_y1_3.Text == "" || u_y2_3.Text == "" || u_h1.Text=="" || u_h2.Text==""    )
            {
                MessageBox.Show("Please Enter All The Values For Both The Vectors");
            }
            else
            {
                vector1_3 = new Genetibase.MathX.NuGenStructures.NuGenVec3D();

                vector1_3._x = new Double[3];

                vector1_3._x[0] = Double.Parse(u_x1_3.Text);
                vector1_3._x[1] = Double.Parse(u_y1_3.Text);
                vector1_3._x[2] = Double.Parse(u_h1.Text);


                vector2_3 = new Genetibase.MathX.NuGenStructures.NuGenVec3D();
                vector2_3._x = new Double[3];

                vector2_3._x[0] = double.Parse(u_x2_3.Text);
                vector2_3._x[1] = double.Parse(u_y2_3.Text);
                vector2_3._x[2] = Double.Parse(u_h2.Text);


                button_add_3.Enabled = true;
                button_div_3.Enabled = true;
                button_equal_3.Enabled = true;
                button_less_equal_3.Enabled = true;
                button_mul_3.Enabled = true;

                button_sub_3.Enabled = true;

            }
        }
コード例 #25
0
 public NuGenShift3D(NuGenVec3D shift)
 {
     v = shift;
 }
コード例 #26
0
 public NuGenShift3D(NuGenVec3D shift)
 {
     v = shift;
 }
コード例 #27
0
 public NuGenScale3D(NuGenVec3D shift)
 {
     v = shift;
 }
コード例 #28
0
ファイル: NuGenBox3F.cs プロジェクト: xuchuansheng/GenXSource
        public bool Intersect(NuGenRay3F r)
        {
            bool inside = true;
            int[] quadrant = new int[3];
            int i;
            int whichPlane;
            float[] max = new float[3];
            float[] candidatePlane = new float[3];
            NuGenVec3D coord = new NuGenVec3D(0, 0, 0);

            for (i = 0; i < 3; i++)
            {

                if (r.Point[i] < lower[i])
                {
                    quadrant[i] = 1;
                    candidatePlane[i] = lower[i];
                    inside = false;
                }

                else if (r.Point[i] > upper[i])
                {
                    quadrant[i] = 0;
                    candidatePlane[i] = upper[i];
                    inside = false;
                }

                else
                {
                    quadrant[i] = 2;
                }
            }

            if (inside) return true;

            for (i = 0; i < 3; i++)
            {

                if (quadrant[i] != 2 && r.Direction[i] != 0.0)
                {
                    max[i] = (candidatePlane[i] - r.Point[i]) / r.Direction[i];
                }

                else
                {
                    max[i] = -1.0f;
                }
            }

            whichPlane = 0;

            for (i = 1; i < 3; i++)
            {

                if (max[whichPlane] < max[i]) whichPlane = i;
            }

            if (max[whichPlane] < 0.0) return false;

            for (i = 0; i < 3; i++)
            {

                if (whichPlane != i)
                {
                    coord[i] = r.Point[i] + max[whichPlane] * r.Direction[i];

                    if (coord[i] < lower[i] || coord[i] > upper[i])
                    {
                        return false;
                    }
                }

                else
                {
                    coord[i] = candidatePlane[i];
                }
            }

            return true;
        }
コード例 #29
0
ファイル: NuGenVen3D.cs プロジェクト: xuchuansheng/GenXSource
 public static double Dot(NuGenVec3D u, NuGenVec3D v)
 {
     return u[0] * v[0] + u[1] * v[1] + u[2] * v[2];
 }
コード例 #30
0
 public NuGenShift3D(double x, double y, double z)
 {
     v = new NuGenVec3D(x, y, z);
 }