public bool Find()
        {
            if (Result != IntersectionResult.NotComputed)
            {
                return(Result == IntersectionResult.Intersects);
            }

            // [RMS] if either line direction is not a normalized vector,
            //   results are garbage, so fail query
            if (ray.Direction.IsNormalized == false)
            {
                Type   = IntersectionType.Empty;
                Result = IntersectionResult.InvalidQuery;
                return(false);
            }

            RayParam0 = 0.0;
            RayParam1 = double.MaxValue;
            IntrLine3AxisAlignedBox3.DoClipping(ref RayParam0, ref RayParam1, ref ray.Origin, ref ray.Direction, ref box,
                                                true, ref Quantity, ref Point0, ref Point1, ref Type);

            Result = (Type != IntersectionType.Empty) ?
                     IntersectionResult.Intersects : IntersectionResult.NoIntersection;
            return(Result == IntersectionResult.Intersects);
        }
        public void GetIntersections_ValidParameters_GetIntersection(
            double x1,
            double y1,
            double x2,
            double y2,
            double x3,
            double y3,
            double x4,
            double y4,
            IntersectionType expectedIntersectionType,
            double?expectedIntersectX,
            double?expectedIntersectY)
        {
            var vector1      = new Vector(new Point(x1, y1), new Point(x2, y2));
            var vector2      = new Vector(new Point(x3, y3), new Point(x4, y4));
            var sw           = Stopwatch.StartNew();
            var intersection = Trigonometry.GetIntersection(vector1, vector2);

            Console.WriteLine(sw.Elapsed);
            Assert.Multiple(() =>
            {
                Assert.That(intersection.IntersectionType, Is.EqualTo(expectedIntersectionType));
                Assert.That(intersection.X, Is.EqualTo(expectedIntersectX));
                Assert.That(intersection.Y, Is.EqualTo(expectedIntersectY));
            });
        }
示例#3
0
        public bool Find()
        {
            if (Result != IntersectionResult.NotComputed)
            {
                return(Result == IntersectionResult.Intersects);
            }

            // [RMS] if either line direction is not a normalized vector,
            //   results are garbage, so fail query
            if (segment.Direction.IsNormalized == false)
            {
                Type   = IntersectionType.Empty;
                Result = IntersectionResult.InvalidQuery;
                return(false);
            }

            SegmentParam0 = -segment.Extent;
            SegmentParam1 = segment.Extent;
            DoClipping(ref SegmentParam0, ref SegmentParam1, segment.Center, segment.Direction, box,
                       solid, ref Quantity, ref Point0, ref Point1, ref Type);

            Result = (Type != IntersectionType.Empty) ?
                     IntersectionResult.Intersects : IntersectionResult.NoIntersection;
            return(Result == IntersectionResult.Intersects);
        }
示例#4
0
        public bool Test()
        {
            double DdN = line.Direction.Dot(plane.Normal);

            if (Math.Abs(DdN) > MathUtil.ZeroTolerance)
            {
                // The line is not parallel to the plane, so they must intersect.
                // The line parameter is *not* set, since this is a test-intersection
                // query.
                Quantity = 1;
                Type     = IntersectionType.Point;
                return(true);
            }

            // The line and plane are parallel. Determine if they are numerically
            // close enough to be coincident.
            double signedDistance = plane.DistanceTo(line.Origin);

            if (Math.Abs(signedDistance) <= MathUtil.ZeroTolerance)
            {
                Quantity = 1;
                Type     = IntersectionType.Line;
                return(true);
            }

            Result = IntersectionResult.NoIntersection;
            Type   = IntersectionType.Empty;
            return(false);
        }
        // If N0 and N1 are parallel, either the planes are parallel and separated
        // or the same plane.  In both cases, 'false' is returned.  Otherwise,
        // the intersection line is
        //   L(t) = t*Cross(N0,N1)/|Cross(N0,N1)| + c0*N0 + c1*N1
        // for some coefficients c0 and c1 and for t any real number (the line
        // parameter).  Taking dot products with the normals,
        //   d0 = Dot(N0,L) = c0*Dot(N0,N0) + c1*Dot(N0,N1) = c0 + c1*d
        //   d1 = Dot(N1,L) = c0*Dot(N0,N1) + c1*Dot(N1,N1) = c0*d + c1
        // where d = Dot(N0,N1).  These are two equations in two unknowns.  The
        // solution is
        //   c0 = (d0 - d*d1)/det
        //   c1 = (d1 - d*d0)/det
        // where det = 1 - d^2.
        public bool Find()
        {
            if (Result != IntersectionResult.NotComputed)
            {
                return(Result != IntersectionResult.NoIntersection);
            }

            double dot = plane0.Normal.Dot(plane1.Normal);

            if (Math.Abs(dot) >= 1 - MathUtil.ZeroTolerance)
            {
                double cDiff = dot >= 0 ? Plane0.Constant - Plane1.Constant : Plane0.Constant + Plane1.Constant;

                if (Math.Abs(cDiff) < MathUtil.ZeroTolerance)
                {
                    Type   = IntersectionType.Plane;
                    Result = IntersectionResult.NoIntersection;
                    Plane  = new Plane3d(plane0.Normal, plane0.Constant);
                }

                Type   = IntersectionType.Empty;
                Result = IntersectionResult.NoIntersection;
                return(false);
            }

            double invDet = 1 / (1 - dot * dot);
            double c0     = (plane0.Constant - dot * plane1.Constant) * invDet;
            double c1     = (plane1.Constant - dot * plane0.Constant) * invDet;

            Quantity = 1;
            Type     = IntersectionType.Line;
            Line     = new Line3d(c0 * plane0.Normal + c1 * plane1.Normal, plane0.Normal.UnitCross(plane1.Normal));
            return(true);
        }
示例#6
0
        bool Fix(TP tp)
        {
            Debug.Assert(!tp.IsFixed);
            if (tp.ExactBound != null)
            {
                // the exact bound will always be the result
                tp.FixedTo = tp.ExactBound;
                // check validity
                if (tp.MultipleDifferentExactBounds)
                {
                    return(false);
                }
                return(tp.LowerBounds.All(b => conversions.ImplicitConversion(b, tp.FixedTo).IsValid) &&
                       tp.UpperBounds.All(b => conversions.ImplicitConversion(tp.FixedTo, b).IsValid));
            }
            var types = CreateNestedInstance().FindTypesInBounds(tp.LowerBounds.ToArray(), tp.UpperBounds.ToArray());

            if (algorithm == TypeInferenceAlgorithm.ImprovedReturnAllResults)
            {
                tp.FixedTo = IntersectionType.Create(types);

                return(types.Count >= 1);
            }
            else
            {
                tp.FixedTo = GetFirstTypePreferNonInterfaces(types);
                return(types.Count == 1);
            }
        }
        // Find-intersection query.  The point of intersection is
        // P = origin + t*direction.
        public bool Find()
        {
            var DdN = line.Direction.Dot(plane.Normal);
            var signedDistance = plane.DistanceTo(line.Origin);
            if (Math.Abs(DdN) > MathUtil.ZeroTolerance)
            {
                // The line is not parallel to the plane, so they must intersect.
                lineParameter = -signedDistance / DdN;
                Type = IntersectionType.Point;
                Result = IntersectionResult.Intersects;
                return true;
            }

            // The Line and plane are parallel.  Determine if they are numerically
            // close enough to be coincident.
            if (Math.Abs(signedDistance) <= MathUtil.ZeroTolerance)
            {
                // The line is coincident with the plane, so choose t = 0 for the
                // parameter.
                lineParameter = 0;
                Type = IntersectionType.Line;
                Result = IntersectionResult.Intersects;
                return true;
            }

            Type = IntersectionType.Empty;
            Result = IntersectionResult.NoIntersection;
            return false;
        }
示例#8
0
        bool Fix(TP tp)
        {
            Log.WriteLine(" Trying to fix " + tp);
            Debug.Assert(!tp.IsFixed);
            if (tp.ExactBound != null)
            {
                // the exact bound will always be the result
                tp.FixedTo = tp.ExactBound;
                // check validity
                if (tp.MultipleDifferentExactBounds)
                {
                    return(false);
                }
                return(tp.LowerBounds.All(b => conversions.ImplicitConversion(b, tp.FixedTo).IsValid) &&
                       tp.UpperBounds.All(b => conversions.ImplicitConversion(tp.FixedTo, b).IsValid));
            }
            Log.Indent();
            var types = CreateNestedInstance().FindTypesInBounds(tp.LowerBounds.ToArray(), tp.UpperBounds.ToArray());

            Log.Unindent();
            if (algorithm == TypeInferenceAlgorithm.ImprovedReturnAllResults)
            {
                tp.FixedTo = IntersectionType.Create(types);
                Log.WriteLine("  T was fixed " + (types.Count >= 1 ? "successfully" : "(with errors)") + " to " + tp.FixedTo);
                return(types.Count >= 1);
            }
            else
            {
                tp.FixedTo = GetFirstTypePreferNonInterfaces(types);
                Log.WriteLine("  T was fixed " + (types.Count == 1 ? "successfully" : "(with errors)") + " to " + tp.FixedTo);
                return(types.Count == 1);
            }
        }
示例#9
0
        // TODO: turn into job
        void FindPlanePairs(IntersectionType type,
                            [NoAlias] ref BrushMeshBlob mesh,
                            [NoAlias] NativeArray <int> intersectingPlanes,
                            int intersectingPlanesLength,
                            [NoAlias] NativeArray <float4> localSpacePlanesPtr,
                            [NoAlias] ref NativeArray <int> vertexUsed,
                            float4x4 vertexTransform,
                            bool needTransform,
                            [NoAlias] ref NativeArray <PlanePair> usedPlanePairs,
                            [NoAlias] ref NativeArray <float3> usedVertices,
                            out int usedPlanePairsLength,
                            out int usedVerticesLength)
        {
            NativeCollectionHelpers.EnsureMinimumSize(ref usedVertices, mesh.localVertices.Length);
            NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref usedPlanePairs, mesh.halfEdges.Length);

            if (type != IntersectionType.Intersection)
            {
                usedPlanePairsLength = 0;
                usedVerticesLength   = mesh.localVertices.Length;
                for (int i = 0; i < mesh.localVertices.Length; i++)
                {
                    usedVertices[i] = mesh.localVertices[i];
                }
                return;
            }
            NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref vertexUsed, mesh.localVertices.Length);
            NativeCollectionHelpers.EnsureMinimumSizeAndClear(ref planeAvailable, mesh.localPlanes.Length);

            // TODO: this can be partially stored in brushmesh
            // TODO: optimize

            ref var halfEdgePolygonIndices = ref mesh.halfEdgePolygonIndices;
示例#10
0
        public void TestBBoxIntersection()
        {
            BoundingBox    targetBox               = new BoundingBox(0, 0, 0, 20, 20, 20);
            BoundingBox    intersectBox            = new BoundingBox(-10, -10, -10, 10, 10, 10);
            BoundingBox    containBox              = new BoundingBox(0, 0, 0, 20, 20, 20);
            BoundingBox    disjointBox             = new BoundingBox(-30, -30, -30, -10, -10, -10);
            BoundingSphere intersectSphere         = new BoundingSphere(new Vector3(0, 0, 0), 15);
            BoundingSphere containSphere           = new BoundingSphere(new Vector3(10, 10, 10), 3);
            BoundingSphere disjointSphere          = new BoundingSphere(new Vector3(-30, -30, -30), 5);
            BoundingBox    intersectBoxExpected    = intersectBox;
            BoundingBox    containBoxExpected      = containBox;
            BoundingBox    disjointBoxExpected     = disjointBox;
            BoundingSphere intersectSphereExpected = intersectSphere;
            BoundingSphere containSphereExpected   = containSphere;
            BoundingSphere disjointSphereExpected  = disjointSphere;

            IntersectionType intersectBoxTypeExpected = IntersectionType.Intersects;
            IntersectionType intersectBoxTypeActual;

            intersectBoxTypeActual = targetBox.Intersects(ref intersectBox);

            IntersectionType containBoxTypeExpected = IntersectionType.Contained;
            IntersectionType containBoxTypeActual;

            containBoxTypeActual = targetBox.Intersects(ref containBox);

            IntersectionType disjointBoxTypeExpected = IntersectionType.NoIntersection;
            IntersectionType disjointBoxTypeActual;

            disjointBoxTypeActual = targetBox.Intersects(ref disjointBox);

            IntersectionType intersectSphereTypeExpected = IntersectionType.Intersects;
            IntersectionType intersectSphereTypeActual;

            intersectSphereTypeActual = targetBox.Intersects(ref intersectSphere);

            IntersectionType containSphereTypeExpected = IntersectionType.Contained;
            IntersectionType containSphereTypeActual;

            containSphereTypeActual = targetBox.Intersects(ref containSphere);

            IntersectionType disjointSphereTypeExpected = IntersectionType.NoIntersection;
            IntersectionType disjointSphereTypeActual;

            disjointSphereTypeActual = targetBox.Intersects(ref disjointSphere);

            Assert.AreEqual(intersectBoxExpected, intersectBox);
            Assert.AreEqual(intersectBoxTypeExpected, intersectBoxTypeActual);
            Assert.AreEqual(containBoxExpected, containBox);
            Assert.AreEqual(containBoxTypeExpected, containBoxTypeActual);
            Assert.AreEqual(disjointBoxExpected, disjointBox);
            Assert.AreEqual(disjointBoxTypeExpected, disjointBoxTypeActual);
            Assert.AreEqual(intersectSphereExpected, intersectSphere);
            Assert.AreEqual(intersectSphereTypeExpected, intersectSphereTypeActual);
            Assert.AreEqual(containSphereExpected, containSphere);
            Assert.AreEqual(containSphereTypeExpected, containSphereTypeActual);
            Assert.AreEqual(disjointSphereExpected, disjointSphere);
            Assert.AreEqual(disjointSphereTypeExpected, disjointSphereTypeActual);
        }
示例#11
0
 /// <summary>
 /// Computes the intersection of the lines p1-p2 and p3-p4.
 /// This function computes both the bool value of the hasIntersection test
 /// and the (approximate) value of the intersection point itself (if there is one).
 /// </summary>
 public virtual void ComputeIntersection(Coordinate p1, Coordinate p2, Coordinate p3, Coordinate p4)
 {
     _inputLines[0, 0] = new Coordinate(p1);
     _inputLines[0, 1] = new Coordinate(p2);
     _inputLines[1, 0] = new Coordinate(p3);
     _inputLines[1, 1] = new Coordinate(p4);
     _result           = ComputeIntersect(p1, p2, p3, p4);
 }
 /// <summary></summary>
 public Intersection(WPoint point)
 {
     Type        = IntersectionType.Point;
     this.points = new List <WPoint>()
     {
         point
     };
 }
示例#13
0
    /// <summary>
    ///  oriented bounding box 和 frustum 是否相交
    /// </summary>
    /// <param name="planes">frustum的六个面</param>
    /// <param name="box">box.center需要是在世界坐标系统的坐标</param>
    /// <param name="right">box本地坐标的right方向值(等价于Transform.right)</param>
    /// <param name="up">box本地坐标的up方向值(等价于Transform.up)</param>
    /// <param name="forward">box本地坐标的forward方向值(等价于Transform.forward)</param>
    /// <returns>true: 相交</returns>
    public static bool IntersectsOrientedBox(Plane[] planes, ref Bounds box, ref Vector3 right, ref Vector3 up,
                                             ref Vector3 forward, float frustumPadding = 0)
    {
        IntersectionType type =
            GetOrientedBoxIntersection(planes, ref box, ref right, ref up, ref forward, frustumPadding);

        return(type != IntersectionType.Disjoint);
    }
示例#14
0
 public IntersectInfo(IntersectInfo copyInfo)
 {
     this.hitType          = copyInfo.hitType;
     this.closestHitObject = copyInfo.closestHitObject;
     this.hitPosition      = copyInfo.hitPosition;
     this.normalAtHit      = copyInfo.normalAtHit;
     this.distanceToHit    = copyInfo.distanceToHit;
 }
示例#15
0
 public RayHitInfo(RayHitInfo copyInfo)
 {
     this.HitType          = copyInfo.HitType;
     this.ClosestHitObject = copyInfo.ClosestHitObject;
     this.HitPosition      = copyInfo.HitPosition;
     this.NormalAtHit      = copyInfo.NormalAtHit;
     this.DistanceToHit    = copyInfo.DistanceToHit;
 }
示例#16
0
 /// <summary>
 /// Constructor for simple intersection with a specific sort value.
 /// </summary>
 /// <param name="xi">X-value of intersection.</param>
 /// <param name="yi">Y-value of intersection.</param>
 /// <param name="sortval">Some value to associate with the intersection</param>
 internal IntersectionData(double xi, double yi, double sortval)
 {
     m_X1        = new Position(xi, yi);
     m_X2        = null;
     m_SortValue = sortval;
     m_Context1  = 0;
     m_Context2  = 0;
 }
示例#17
0
 /// <summary>
 /// Resets this intersection so that it has undefined values.
 /// </summary>
 internal void Reset()
 {
     m_X1        = null;
     m_X2        = null;
     m_SortValue = 0.0;
     m_Context1  = 0;
     m_Context2  = 0;
 }
示例#18
0
 /// <summary>
 /// Constructor for a simple intersection (with a default sort value of 0.0)
 /// </summary>
 /// <param name="x">The position of the intersection.</param>
 internal IntersectionData(IPosition x)
 {
     m_X1        = x;
     m_X2        = null;
     m_SortValue = 0.0;
     m_Context1  = 0;
     m_Context2  = 0;
 }
示例#19
0
        public override object Exec(IntersectionType firstOperand, object arg)
        {
            foreach (TypeExpression type in firstOperand.TypeSet)
            {
                type.AcceptOperation(this, arg);
            }

            return(this.typeExpressionList);
        }
示例#20
0
        private void createSignatures(AstNode foundNode, ITextBuffer textBuffer, ITrackingSpan span, IList <ISignature> signatures)
        {
            MethodType       methodType       = null;
            IntersectionType intersectionType = null;

            if (foundNode is InvocationExpression)
            {
                InvocationExpression invocation = foundNode as InvocationExpression;
                //Not overloaded method:
                methodType = invocation.Identifier.ExpressionType as MethodType;
                //Overloaded method:
                intersectionType = invocation.Identifier.ExpressionType as IntersectionType;
            }

            else if (foundNode is NewExpression)
            {
                NewExpression newExp = foundNode as NewExpression;
                if (newExp.NewType != null)
                {
                    AccessModifier[] members   = newExp.NewType.AcceptOperation(new GetMembersOperation(), null) as AccessModifier[];
                    string[]         nameParts = newExp.NewType.FullName.Split(new char[] { '.' });
                    string           className = nameParts[nameParts.Length - 1];
                    foreach (AccessModifier mod in members)
                    {
                        if (mod.MemberIdentifier.Equals(className))
                        {
                            //Not overloaded method:
                            methodType = mod.Type as MethodType;
                            //Overloaded method:
                            intersectionType = mod.Type as IntersectionType;

                            break;
                        }
                    }
                }
            }

            //Not overloaded method:
            if (methodType != null)
            {
                signatures.Add(this.CreateSignature(textBuffer, methodType, "", span));
            }

            //Overloaded method:
            if (intersectionType != null)
            {
                foreach (TypeExpression type in intersectionType.TypeSet)
                {
                    methodType = type as MethodType;

                    if (methodType != null)
                    {
                        signatures.Add(this.CreateSignature(textBuffer, methodType, "", span));
                    }
                }
            }
        }
示例#21
0
 /// <summary>
 /// Reverses the context codes.
 /// </summary>
 internal void ReverseContext()
 {
     if (m_Context1 != m_Context2)
     {
         IntersectionType temp = m_Context1;
         m_Context1 = m_Context2;
         m_Context2 = temp;
     }
 }
 /// <summary></summary>
 public Intersection(params WPoint[] points)
 {
     if (points.Length <= 1)
     {
         throw new ArgumentException("At least 2 points expected.");
     }
     Type        = IntersectionType.Points;
     this.points = points.ToList();
 }
        public override object Exec(IntersectionType caller, object arg)
        {
            TypeExpression method = caller.overloadResolution(this.arguments, this.location);

            if (method == null)
            {
                return(null);
            }
            return(method.AcceptOperation(this, arg));
        }
示例#24
0
        protected bool IsFact(Clause goal, List <Clause> unproved_conditions)
        {
            List <Rule> goal_stack = new List <Rule>();

            foreach (Rule rule in m_rules)
            {
                Clause           consequent = rule.getConsequent();
                IntersectionType it         = consequent.MatchClause(goal);
                if (it == IntersectionType.INCLUDE)
                {
                    goal_stack.Add(rule);
                }
            }

            if (goal_stack.Count == 0)
            {
                unproved_conditions.Add(goal);
            }
            else
            {
                foreach (Rule rule in goal_stack)
                {
                    rule.FirstAntecedent();
                    bool goal_reached = true;
                    while (rule.HasNextAntecedents())
                    {
                        Clause antecedent = rule.NextAntecedent();
                        if (!m_wm.IsFact(antecedent))
                        {
                            if (m_wm.IsNotFact(antecedent))
                            {
                                goal_reached = false;
                                break;
                            }
                            else if (IsFact(antecedent, unproved_conditions))
                            {
                                m_wm.AddFact(antecedent);
                            }
                            else
                            {
                                goal_reached = false;
                                break;
                            }
                        }
                    }

                    if (goal_reached)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#25
0
            public ExpectationBuilder ToBe(IntersectionType shouldIntersect, int x, int y)
            {
                var node = new Node {
                    X = x + XSkew, Y = y + YSkew
                };

                Expectations.Add(new Expectation {
                    Point = node, ShouldIntersect = shouldIntersect
                });
                return(this);
            }
        void BroadphaseSingle(IntersectionType forType, PhysicsBodyComponent p1, float deltaTime)
        {
            broadIntersections.Clear();

            Broadphase(forType, p1, deltaTime, 0);

            // Sort the intersections by entry time, where first intersections are the first in the array.
            intersections = new Intersection[broadIntersections.Count];
            broadIntersections.CopyTo(intersections);
            Array.Sort(intersections, CompareIntersection);
        }
示例#27
0
        /// <summary>
        /// Constructor for a grazing intersection. If the supplied positions are
        /// actually closer than the coordinate resolution (1 micron), a simple
        /// intersection will be defined.
        /// </summary>
        /// <param name="p1">The 1st intersection.</param>
        /// <param name="p2">The 2nd intersection.</param>
        IntersectionData(IPointGeometry p1, IPointGeometry p2)
        {
            m_X1 = p1;
            if (!p1.IsCoincident(p2))
            {
                m_X2 = p2;
            }

            m_SortValue = 0.0;
            m_Context1  = 0;
            m_Context2  = 0;
        }
示例#28
0
 public Ray(Vector3 origin, Vector3 direction, double minDistanceToConsider = 0, double maxDistanceToConsider = double.PositiveInfinity, IntersectionType intersectionType = IntersectionType.FrontFace)
 {
     this.origin = origin;
     this.direction = direction;
     this.minDistanceToConsider = minDistanceToConsider;
     this.maxDistanceToConsider = maxDistanceToConsider;
     this.intersectionType = intersectionType;
     oneOverDirection = 1 / direction;
     sign[0] = (oneOverDirection.x < 0) ? Sign.Negative : Sign.Positive;
     sign[1] = (oneOverDirection.y < 0) ? Sign.Negative : Sign.Positive;
     sign[2] = (oneOverDirection.z < 0) ? Sign.Negative : Sign.Positive;
 }
示例#29
0
 public Ray(Vector3 origin, Vector3 direction, double minDistanceToConsider = 0, double maxDistanceToConsider = double.PositiveInfinity, IntersectionType intersectionType = IntersectionType.FrontFace)
 {
     this.origin                = origin;
     this.direction             = direction;
     this.minDistanceToConsider = minDistanceToConsider;
     this.maxDistanceToConsider = maxDistanceToConsider;
     this.intersectionType      = intersectionType;
     oneOverDirection           = 1 / direction;
     sign[0] = (oneOverDirection.x < 0) ? Sign.Negative : Sign.Positive;
     sign[1] = (oneOverDirection.y < 0) ? Sign.Negative : Sign.Positive;
     sign[2] = (oneOverDirection.z < 0) ? Sign.Negative : Sign.Positive;
 }
示例#30
0
 public void Flip()
 {
     if (type == IntersectionType.AInsideB)
     {
         type = IntersectionType.BInsideA;
     }
     else if (type == IntersectionType.BInsideA)
     {
         type = IntersectionType.AInsideB;
     }
     { var t = brushIndexOrder0; brushIndexOrder0 = brushIndexOrder1; brushIndexOrder1 = t; }
 }
示例#31
0
 public void Flip()
 {
     if (type == IntersectionType.AInsideB)
     {
         type = IntersectionType.BInsideA;
     }
     else if (type == IntersectionType.BInsideA)
     {
         type = IntersectionType.AInsideB;
     }
     { var t = brushNodeIndex0; brushNodeIndex0 = brushNodeIndex1; brushNodeIndex1 = t; }
 }
示例#32
0
 public Ray(Ray rayToCopy)
 {
     origin = rayToCopy.origin;
     direction = rayToCopy.direction;
     minDistanceToConsider = rayToCopy.minDistanceToConsider;
     maxDistanceToConsider = rayToCopy.maxDistanceToConsider;
     oneOverDirection = rayToCopy.oneOverDirection;
     isShadowRay = rayToCopy.isShadowRay;
     intersectionType = rayToCopy.intersectionType;
     sign[0] = rayToCopy.sign[0];
     sign[1] = rayToCopy.sign[1];
     sign[2] = rayToCopy.sign[2];
 }
        public void IntersectionPointTest( float ax1, float ay1, float ax2, float ay2, float bx1, float by1, float bx2, float by2, float ix, float iy, IntersectionType type )
        {
            LineSegment segA = new LineSegment( new Point( ax1, ay1 ), new Point( ax2, ay2 ) );
            LineSegment segB = new LineSegment( new Point( bx1, by1 ), new Point( bx2, by2 ) );
            Point expectedIntersection = new Point( ix, iy );

            Assert.DoesNotThrow( ( ) =>
            {
                Point? segSeg = segA.GetIntersectionWith( segB );
                Point? segLine = segA.GetIntersectionWith( (Line) segB );
                Point? lineSeg = ( (Line) segA ).GetIntersectionWith( segB );

                if ( type == IntersectionType.AllFour )
                {
                    Assert.AreEqual( expectedIntersection, segSeg );
                }
                else
                {
                    Assert.AreEqual( null, segSeg );
                }

                if ( ( type == IntersectionType.AllFour ) || ( type == IntersectionType.SegmentA ) )
                {
                    Assert.AreEqual( expectedIntersection, segLine );
                }
                else
                {
                    Assert.AreEqual( null, segLine );
                }

                if ( ( type == IntersectionType.AllFour ) || ( type == IntersectionType.SegmentB ) )
                {
                    Assert.AreEqual( expectedIntersection, lineSeg );
                }
                else
                {
                    Assert.AreEqual( null, lineSeg );
                }
            } );

            Point? lineLine = ( (Line) segA ).GetIntersectionWith( (Line) segB );

            if ( type != IntersectionType.None )
            {
                Assert.AreEqual( expectedIntersection, lineLine );
            }
            else
            {
                Assert.AreEqual( null, lineLine );
            }
        }
示例#34
0
 /// <summary>
 ///
 /// </summary>
 protected LineIntersector()
 {
     _intPt[0] = new Coordinate();
     _intPt[1] = new Coordinate();
     _result = 0;
 }
示例#35
0
		public static bool HasAnyFlag(this IntersectionType flags, IntersectionType otherFlags)
		{
			return (flags & otherFlags) != 0;
		}
示例#36
0
        /// <summary>
        /// build a quad node.
        /// </summary>
        /// <param name="vertices">vertex array</param>
        /// <param name="depthLevel">quad tree depth count</param>
        /// <returns>new quad node</returns>
        protected QuadNode BuildNode(Vector3[] vertices, int depthLevel)
        {
            QuadNode newNode = null;
            
            Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
            float centerX = 0.0f;
            float centerZ = 0.0f;

            IntersectionType[] Intersection = new IntersectionType[3];

            //  checks min and max of vertices
            for (int i = 0; i < vertices.Length; i++)
            {
                if (min.X > vertices[i].X) min.X = vertices[i].X;
                if (min.Y > vertices[i].Y) min.Y = vertices[i].Y;
                if (min.Z > vertices[i].Z) min.Z = vertices[i].Z;

                if (max.X < vertices[i].X) max.X = vertices[i].X;
                if (max.Y < vertices[i].Y) max.Y = vertices[i].Y;
                if (max.Z < vertices[i].Z) max.Z = vertices[i].Z;
            }

            centerX  = (max.X + min.X) / 2;
            centerZ  = (max.Z + min.Z) / 2;

            //  creates node
            newNode = new QuadNode(min, max);
            newNode.Depth = this.depthLevel - depthLevel;
            
            nodeCount++;            

            if (depthLevel-- > 0)
            {
                List<Vector3> upperLeftVertexList = new List<Vector3>();
                List<Vector3> upperRightVertexList = new List<Vector3>();
                List<Vector3> lowerLeftVertexList = new List<Vector3>();
                List<Vector3> lowerRightVertexList = new List<Vector3>();
                List<Vector3> medlineVertexList = new List<Vector3>();
                                
                //  vertex count
                for (int count = 0; count < vertices.Length; count += 3)
                {
                    //  Triangle
                    for (int i = 0; i < 3; i++)
                    {
                        //  inside upper left
                        if (vertices[count + i].X < centerX && 
                            vertices[count + i].Z < centerZ)
                        {
                            Intersection[i] = IntersectionType.UpperLeft;
                        }
                        //  inside upper right
                        else if (vertices[count + i].X > centerX &&
                                vertices[count + i].Z < centerZ)
                        {
                            Intersection[i] = IntersectionType.UpperRight;
                        }
                        //  inside lower left
                        else if (vertices[count + i].X < centerX &&
                                vertices[count + i].Z > centerZ)
                        {
                            Intersection[i] = IntersectionType.LowerLeft;
                        }
                        //  inside lower right
                        else if (vertices[count + i].X > centerX &&
                                vertices[count + i].Z > centerZ)
                        {
                            Intersection[i] = IntersectionType.LowerRight;
                        }
                    }

                    //  intersecting with upper left area
                    if (Intersection[0] == IntersectionType.UpperLeft &&
                        Intersection[1] == IntersectionType.UpperLeft &&
                        Intersection[2] == IntersectionType.UpperLeft)
                    {
                        upperLeftVertexList.Add(vertices[count + 0]);
                        upperLeftVertexList.Add(vertices[count + 1]);
                        upperLeftVertexList.Add(vertices[count + 2]);
                    }
                    //  intersecting with upper right area
                    else if (Intersection[0] == IntersectionType.UpperRight &&
                            Intersection[1] == IntersectionType.UpperRight &&
                            Intersection[2] == IntersectionType.UpperRight)
                    {
                        upperRightVertexList.Add(vertices[count + 0]);
                        upperRightVertexList.Add(vertices[count + 1]);
                        upperRightVertexList.Add(vertices[count + 2]);
                    }
                    //  intersecting with lower left area
                    else if (Intersection[0] == IntersectionType.LowerLeft &&
                            Intersection[1] == IntersectionType.LowerLeft &&
                            Intersection[2] == IntersectionType.LowerLeft)
                    {
                        lowerLeftVertexList.Add(vertices[count + 0]);
                        lowerLeftVertexList.Add(vertices[count + 1]);
                        lowerLeftVertexList.Add(vertices[count + 2]);
                    }
                    //  intersecting with lower right area
                    else if (Intersection[0] == IntersectionType.LowerRight &&
                            Intersection[1] == IntersectionType.LowerRight &&
                            Intersection[2] == IntersectionType.LowerRight)
                    {
                        lowerRightVertexList.Add(vertices[count + 0]);
                        lowerRightVertexList.Add(vertices[count + 1]);
                        lowerRightVertexList.Add(vertices[count + 2]);
                    }
                    //  intersecting with medline
                    else
                    {
                        medlineVertexList.Add(vertices[count + 0]);
                        medlineVertexList.Add(vertices[count + 1]);
                        medlineVertexList.Add(vertices[count + 2]);
                    }
                }

                string prefix = String.Empty;
                for (int i = 0; i < this.depthLevel - depthLevel; i++) prefix += "- ";

                //  upper left
                if (upperLeftVertexList.Count > 0)
                {
                    newNode.UpperLeftNode =
                        BuildNode(upperLeftVertexList.ToArray(), depthLevel);

                    newNode.UpperLeftNode.Parent = newNode;                  

                    newNode.UpperLeftNode.Name = "QUADTREE: " + prefix + "UL ";

                    if (newNode.UpperLeftNode.IsLeafNode )
                        newNode.UpperLeftNode.Name += "leaf";
                    else
                        newNode.UpperLeftNode.Name += "node";
                }

                //  upper right
                if (upperRightVertexList.Count > 0)
                {
                    newNode.UpperRightNode =
                        BuildNode(upperRightVertexList.ToArray(), depthLevel);

                    newNode.UpperRightNode.Parent = newNode;
                    newNode.UpperRightNode.Name = "QUADTREE: " + prefix + "UR ";

                    if (newNode.UpperRightNode.IsLeafNode )
                        newNode.UpperRightNode.Name += "leaf";
                    else
                        newNode.UpperRightNode.Name += "node";
                }

                //  lower left
                if (lowerLeftVertexList.Count > 0)
                {
                    newNode.LowerLeftNode =
                        BuildNode(lowerLeftVertexList.ToArray(), depthLevel);

                    newNode.LowerLeftNode.Parent = newNode;
                    newNode.LowerLeftNode.Name = "QUADTREE: " + prefix + "LL ";

                    if (newNode.LowerLeftNode.IsLeafNode )
                        newNode.LowerLeftNode.Name += "leaf";
                    else
                        newNode.LowerLeftNode.Name += "node";
                }

                //  lower right
                if (lowerRightVertexList.Count > 0)
                {
                    newNode.LowerRightNode =
                        BuildNode(lowerRightVertexList.ToArray(), depthLevel);

                    newNode.LowerRightNode.Parent = newNode;
                    newNode.LowerRightNode.Name = "QUADTREE: " + prefix + "LR ";

                    if (newNode.LowerRightNode.IsLeafNode )
                        newNode.LowerRightNode.Name += "leaf";
                    else
                        newNode.LowerRightNode.Name += "node";
                }

                //  intersecting with medline
                if (medlineVertexList.Count > 0)
                {
                    newNode.CreateVertices(medlineVertexList.ToArray());
                }
            }
            else
            {
                newNode.CreateVertices(vertices);
            }

            return newNode;
        }
        //public IntersectionInstance(int X, int Y, IntersectionType type, IntersectionSurface surface,
        //    LightState initialLightState, Boolean isControlledL, string ID, int numLanes, Boolean haspavement,
        //    TrafficFlowDirection direction)
        //{
        //    OutputLogging.writeOutput("Starting new Intersection Instance. ID = " + ID);
        //    OutputLogging.writeOutput(ID + " position(x,y): (" + X + ", " + Y + ")");
        //    #region Setters
        //    PositionX = X;
        //    PositionY = Y;
        //    IntersectionType = type;
        //    IntersectionSurface = surface;
        //    CurrentLightState = initialLightState;
        //    IsControlled = isControlledL;
        //    IntersectionIdentifier = ID;
        //    NumberOfLanes = numLanes;
        //    HasSideWalk = haspavement;
        //    Direction = direction;
        //    #endregion
        //    #region Events
        //    //OnClicked += OnIntersectionClicked;
        //    //OnMouseOver += OnIntersectionMouseOver;
        //    //OnLightStateChanged += OnOnLightStateChanged;
        //    #endregion
        //    EntityDict.AddEnity(this);
        //}
        public IntersectionInstance(int X, int Y, IntersectionType type, IntersectionSurface surface,
            Boolean isControlledL, string ID, Boolean haspavement, TrafficFlowDirection direction)
        {
            OutputLogging.writeOutput("Starting new Intersection Instance. ID = " + ID);
            OutputLogging.writeOutput(ID + " position(x,y): (" + X + ", " + Y + ")");

            #region Setters

            PositionX = X;
            PositionY = Y;
            IntersectionType = type;
            IntersectionSurface = surface;
            IsControlled = isControlledL;
            IntersectionIdentifier = ID;
            HasSideWalk = haspavement;
            Direction = direction;

            #endregion

            #region Events

            //OnClicked += OnIntersectionClicked;
            //OnMouseOver += OnIntersectionMouseOver;
            //OnLightStateChanged += OnOnLightStateChanged;

            #endregion

            EntityDict.AddEnity(this);
        }
示例#38
0
 /// <summary>
 /// Computes the intersection of the lines p1-p2 and p3-p4.
 /// This function computes both the bool value of the hasIntersection test
 /// and the (approximate) value of the intersection point itself (if there is one).
 /// </summary>
 public virtual void ComputeIntersection(Coordinate p1, Coordinate p2, Coordinate p3, Coordinate p4)
 {
     _inputLines[0, 0] = new Coordinate(p1);
     _inputLines[0, 1] = new Coordinate(p2);
     _inputLines[1, 0] = new Coordinate(p3);
     _inputLines[1, 1] = new Coordinate(p4);
     _result = ComputeIntersect(p1, p2, p3, p4);
 }
示例#39
0
		// segment intersection
		public Intersection2D(Segment seg)
		{
			_iType = IntersectionType.I2D_SEGMENT;
			_seg = seg;
		}
示例#40
0
		// point intersection
		public Intersection2D(Vector2D vec)
		{
			_iType = IntersectionType.I2D_POINT;
			_vec = vec;
		}
示例#41
0
		// no intersection
		public Intersection2D()
		{
			_iType = IntersectionType.I2D_NONE;
		}
示例#42
0
		private IntersectInfo FindNextIntersections(IPrimitive element, Ray ray, IntersectInfo info, IntersectionType intersectionType)
		{
			// get all the intersection for the object
			Ray currentRayCheckBackfaces = new Ray(ray);
			currentRayCheckBackfaces.intersectionType = intersectionType;
			currentRayCheckBackfaces.minDistanceToConsider = ((info.hitPosition + ray.directionNormal * Ray.sameSurfaceOffset) - ray.origin).Length;
			currentRayCheckBackfaces.maxDistanceToConsider = double.PositiveInfinity;

			return element.GetClosestIntersection(currentRayCheckBackfaces);
		}