Project() public static method

public static Project ( Vector3D, vector, Vector3D, onNormal ) : Vector3D,
vector Vector3D,
onNormal Vector3D,
return Vector3D,
Exemplo n.º 1
0
        public void Project2Test()
        {
            var v  = new Vector3D(1.5925, 1.5075, 3);
            var v2 = v.Project(new Line3D(-1.5317, 1.9230, 1.5482, 3.1248, -0.9249, -1.9787));

            // v2 is endpoint of perp line from v to projection line
            Assert.True(v2.EqualsTol(1e-4, -.3617, 1.2075, .6621));
        }
Exemplo n.º 2
0
        public void Project3Test()
        {
            var v  = new Vector3D(1, 2, 3);
            var v2 = new Vector3D(4.5106, 1.8377, 0);
            var vp = v.Project(v2);

            Assert.True(v2.Colinear(1e-4, vp));
            Assert.True(vp.EqualsTol(1e-4, 1.5565, .6341, 0));
        }
Exemplo n.º 3
0
            /// <summary>
            /// Build a perpendicular vector to this one starting from the given point p.
            /// </summary>
            public Line3D Perpendicular(double tol, Vector3D p)
            {
                if (LineContainsPoint(tol, p))
                {
                    return(null);
                }

                return(new Line3D(p, p.Project(V)));
            }
Exemplo n.º 4
0
        public void Vector3DTest_0021()
        {
            var tol = 1e-8;

            var v1 = new Vector3D("X = 7.17678145 Y = 9.61488416 Z = 3.26614373");
            var v2 = new Vector3D("X = 1.03262618 Y = 4.33930275 Z = 4.34962008");

            var p = v2.Project(v1);

            Assert.True(p.EqualsTol(tol, new Vector3D("X = 2.93993485 Y = 3.93869218 Z = 1.33796046")));
        }
Exemplo n.º 5
0
        public void Project4Test()
        {
            // Cusago, Italy : 45,448365 E, 9,034168 N ( geodetic system )
            var v = new Vector3D(9.034168, 45.448365);

            // epsg3003 : monte mario / italy zone 1 ( projected system )
            var epsg3003 = CRSCatalog.CRSList["EPSG:3003"];

            var q = v.Project(CRSCatalog.WGS84, epsg3003);

            q.EqualsTol(1e-2, 1502699.63, 5032780.63);
        }
Exemplo n.º 6
0
        public void Project1Test()
        {
            var cs = new CoordinateSystem3D(
                new Vector3D(6.1776, -6.3366, -5.7131),  // o
                new Vector3D(-2.8849, -7.6108, -1.8691), // v1
                new Vector3D(-11.7294, 5.4484, 6.7873)); // v2

            var v  = new Vector3D(1, 2, 3);
            var vp = v.Project(cs);

            Assert.True(vp.EqualsTol(1e-4, -.0151, 3.0158, .4304));
        }
Exemplo n.º 7
0
            /// <summary>
            /// build 3d circle through point p, tangent to given t line, with given radius r
            /// they can be two
            /// </summary>
            public static IEnumerable <Circle3D> CircleRTanP(double tol_len, Vector3D p, Line3D t, double r)
            {
                var pp    = p.Project(t);
                var alpha = Asin((r - pp.Distance(p)) / r);
                var beta  = PI / 2 - alpha;

                var axisz = (p - pp).CrossProduct(t.V);

                var t2 = new Line3D(p, t.V.RotateAboutAxis(axisz, beta), Line3DConstructMode.PointAndVector);

                return(CirclesTan12P(tol_len, t, t2, p).Where(w => w.Radius.EqualsTol(tol_len, r)));
            }
Exemplo n.º 8
0
            /// <summary>
            /// build 3d circle that tangent to lines t1,t2 and that intersects point p
            /// note: point p must contained in one of t1,t2
            /// circle will be inside region t1.V toward t2.V
            /// they are 4 circles
            /// </summary>
            public static IEnumerable <Circle3D> CirclesTan12P(double tol_len, Line3D t1, Line3D t2, Vector3D p)
            {
                foreach (var da in new double[] { 0, PI / 2 })
                {
                    var ip    = t1.Intersect(tol_len, t2);
                    var angle = t1.V.AngleRad(tol_len, t2.V);
                    var t3    = new Line3D(ip, t1.V.RotateAs(tol_len, t1.V, t2.V, .5, da), Line3DConstructMode.PointAndVector);

                    Line3D lp  = null;
                    Line3D lNp = null;
                    if (t1.LineContainsPoint(tol_len, p))
                    {
                        lp = t1; lNp = t2;
                    }
                    else if (t2.LineContainsPoint(tol_len, p))
                    {
                        lp = t2; lNp = t1;
                    }
                    else
                    {
                        throw new Exception($"circle 2 tan 1 point : pt must contained in one of given tan");
                    }

                    var lpp = new Line3D(p, lp.V.RotateAboutAxis(t1.V.CrossProduct(t2.V), PI / 2), Line3DConstructMode.PointAndVector);
                    var c   = lpp.Intersect(tol_len, t3);

                    var Radius = p.Distance(c);
                    var CS     = new CoordinateSystem3D(c, lpp.V, t2.V);

                    yield return(new Circle3D(tol_len, CS, Radius));

                    // mirrored addictional circle

                    var mc = c.Mirror(new Line3D(p, p.Project(lNp) - p, Line3DConstructMode.PointAndVector));

                    yield return(new Circle3D(tol_len, new CoordinateSystem3D(mc, lpp.V, t2.V), Radius));
                }
            }
Exemplo n.º 9
0
 public Triangle2D Project(int d, ColorimetryInfo colorimetry)
 {
     return(new Triangle2D(_v1.Project(d), _v2.Project(d), _v3.Project(d), ApplyColorimetry(_color, colorimetry)));
 }
Exemplo n.º 10
0
 public static Vector3D ProjectOnPlane(Vector3D vector, Vector3D planeNormal)
 {
     return(vector - Vector3D.Project(vector, planeNormal));
 }
Exemplo n.º 11
0
            /// <summary>
            /// Infinite line contains point.
            /// </summary>
            public bool LineContainsPoint(double tol, Vector3D p, bool segmentMode = false, bool excludeExtreme = false)
            {
                if (this.Length.EqualsTol(tol, 0))
                {
                    return(false);
                }

                var prj = p.Project(this);

                var dprj = p.Distance(prj);

                // check if line contains point
                if (dprj > tol)
                {
                    return(false);
                }

                if (segmentMode)
                {
                    // line contains given point if there is a scalar s
                    // for which p = From + s * V
                    var s = 0.0;

                    // to find out the scalar we need to test the first non null component

                    if (!(V.X.EqualsTol(tol, 0)))
                    {
                        s = (p.X - From.X) / V.X;
                    }
                    else if (!(V.Y.EqualsTol(tol, 0)))
                    {
                        s = (p.Y - From.Y) / V.Y;
                    }
                    else if (!(V.Z.EqualsTol(tol, 0)))
                    {
                        s = (p.Z - From.Z) / V.Z;
                    }

                    if (excludeExtreme)
                    {
                        if (p.EqualsTol(tol, From))
                        {
                            return(false);
                        }
                        if (p.EqualsTol(tol, To))
                        {
                            return(false);
                        }

                        return(s > 0 && s < 1);
                    }
                    else
                    {
                        // s is the scalar of V vector that runs From->To

                        if (s >= 0.0 && s <= 1.0)
                        {
                            return(true);
                        }

                        // point on the line but outside exact segment
                        // check with tolerance

                        if (s < 0)
                        {
                            return(p.EqualsTol(tol, From));
                        }
                        else
                        {
                            return(p.EqualsTol(tol, To));
                        }
                    }
                }

                return(true);
            }
Exemplo n.º 12
0
 public static Vector3D Exclude(Vector3D excludeThis, Vector3D fromThat)
 {
     return(fromThat - Vector3D.Project(fromThat, excludeThis));
 }