コード例 #1
0
        public void CanKeepEpsilonAtReasonableLevel()
        {
            var result = new List <Pnt3D>();

            // points spaced by a few 100m
            result.Add(new Pnt3D {
                X = 2723729.625, Y = 1251631.61625, Z = 601.388749999984
            });
            result.Add(new Pnt3D {
                X = 2723531.44625, Y = 1251727.94, Z = 615.443749999991
            });
            result.Add(new Pnt3D {
                X = 2723633.2675, Y = 1251824.26375, Z = 661.388749999984
            });

            result.Add(result[0]);

            Plane3D plane1 = Plane3D.FitPlane(result, true);

            result.Reverse();

            Plane3D plane2 = Plane3D.FitPlane(result, true);

            Assert.Less(plane1.Epsilon, 0.5);

            Assert.True(plane1.IsParallel(plane2));

            // opposite directon normal:
            Assert.False(plane1.Equals(plane2));

            Assert.True(plane1.IsCoincident(plane2));
        }
コード例 #2
0
        public void CanGetDistanceToVerticalPlane3D()
        {
            List <Pnt3D> points = GetVerticalTrianglePoints();

            Plane3D plane = Plane3D.FitPlane(points);

            Console.WriteLine(@"A: " + plane.A);
            Console.WriteLine(@"B: " + plane.B);
            Console.WriteLine(@"C: " + plane.C);
            Console.WriteLine(@"D: " + plane.D);

            Assert.AreEqual(0, plane.C, plane.Epsilon);             // vertical
            Assert.AreEqual(1, plane.GetUnitNormal().LengthSquared);

            Assert.AreEqual(0.89606641473951276, plane.GetUnitNormal().X, plane.Epsilon);
            Assert.AreEqual(0.44392001574143475, plane.GetUnitNormal().Y, plane.Epsilon);

            foreach (Pnt3D point in points)
            {
                double distance = plane.GetDistanceAbs(point.X, point.Y, point.Z);
                Console.WriteLine(@"{0}: {1}", point, distance);
                Assert.AreEqual(0, distance, plane.Epsilon);
            }

            Assert.Catch <InvalidOperationException>(() => plane.GetZ(100, 100));
        }
コード例 #3
0
        public void CanDetermineInclinedPlaneCoincidenceMirroredAt0()
        {
            var result = new List <Pnt3D>();

            result.Add(new Pnt3D {
                X = 2723729.625, Y = 1251631.61625, Z = 601.388749999984
            });
            result.Add(new Pnt3D {
                X = 2723531.44625, Y = 1251727.94, Z = 615.443749999991
            });
            result.Add(new Pnt3D {
                X = 2723633.2675, Y = 1251824.26375, Z = 661.388749999984
            });

            result.Add(result[0]);

            Plane3D plane1 = Plane3D.FitPlane(result, true);

            for (var i = 0; i < result.Count; i++)
            {
                result[i] = result[i] * -1;
            }

            result.Reverse();

            Plane3D plane2 = Plane3D.FitPlane(result, true);

            Assert.False(plane1.Equals(plane2));
            Assert.True(plane1.IsParallel(plane2));
            Assert.False(plane1.IsCoincident(plane2));
        }
コード例 #4
0
ファイル: Plane3DTest.cs プロジェクト: Hengle/UnityUtils-3
    public void TestPlaneRayCast()
    {
        Random.InitState(123);
        for (int i = 0; i < 1000; i++)
        {
            Vector3  direction  = Random.onUnitSphere;
            float    dist       = Random.Range(-999, 999);
            Vector3D directionD = new Vector3D(direction);
            Plane3D  planeD     = new Plane3D(directionD, dist);
            Plane    plane      = new Plane(direction, dist);
            for (int j = 0; j < 10; j++)
            {
                Vector3  pos     = Random.insideUnitSphere * 999;
                Vector3  rayDir  = Random.onUnitSphere;
                Vector3D posD    = new Vector3D(pos);
                Vector3D rayDirD = new Vector3D(rayDir);
                Ray      r       = new Ray(pos, rayDir);
                RayD     rd      = new RayD(posD, rayDirD);

                float  enter;
                double enterD;
                bool   res  = plane.Raycast(r, out enter);
                bool   resD = planeD.Raycast(rd, out enterD);
                Assert.AreEqual(res, resD, "Raycast Res " + plane + " ray " + r);
                if (enterD < 1e7)
                {
                    Assert.AreEqual((double)enter, enterD, Mathf.Abs(enter) / 1000,
                                    "GetDistanceToPoint " + plane + " ray " + r);
                }
            }
        }
    }
コード例 #5
0
        public void CanGetZOfNearlyHorizontalPlane3D()
        {
            var points = new List <Pnt3D>();

            points.Add(new Pnt3D {
                X = 2723729.625, Y = 1251631.61625, Z = 601
            });
            points.Add(new Pnt3D {
                X = 2723531.44625, Y = 1251727.94, Z = 601
            });
            points.Add(new Pnt3D {
                X = 2723633.2675, Y = 1251824.26375, Z = 601
            });

            points[0].Z += 0.001;

            points.Add(points[0]);

            Plane3D plane = Plane3D.FitPlane(points, true);

            foreach (Pnt3D point in points)
            {
                double z = plane.GetZ(point.X, point.Y);
                Console.WriteLine(@"{0}: {1}", point, z);
                Assert.AreEqual(point.Z, z, plane.Epsilon);
            }

            const double farAwayX = -1000000.12345;
            const double farAwayY = -1000000.6789;
            double       z0       = plane.GetZ(farAwayX, farAwayY);

            Assert.AreEqual(0, plane.GetDistanceSigned(farAwayX, farAwayY, z0), plane.Epsilon);
        }
コード例 #6
0
ファイル: Plane3DTest.cs プロジェクト: Hengle/UnityUtils-3
    public void TestPlaneDistanceSimple()
    {
        Plane3D planeD = new Plane3D(new Vector3D(0, 1, 0), 10);

        Assert.AreEqual(0, planeD.GetDistanceToPoint(new Vector3D(0, -10, 0)));
        Assert.AreEqual(20, planeD.GetDistanceToPoint(new Vector3D(0, 10, 0)));
    }
コード例 #7
0
ファイル: Camera.cs プロジェクト: bhouston/ExoEngine3D
        protected void  SyncFrustumPlanes()
        {
            if (_bFrustumPlanesDirty == false)
            {
                return;
            }

            Vector3D nearClipTranslation = _translation + _forwardAxis * _nearClipDistance;
            Vector3D farClipTranslation  = _translation + _forwardAxis * _nearClipDistance;

            _topPlane = Plane3D.FromNormalAndPoint(_forwardAxis, _translation + nearClipTranslation);
            _farPlane = Plane3D.FromNormalAndPoint(_forwardAxis, _translation + farClipTranslation);

            Vector3D viewportUpTranslation    = _upAxis * _viewportHeight / 2;
            Vector3D viewportRightTranslation = _rightAxis * _viewportWidth / 2;

            Vector3D topNormal = Vector3D.Cross(_rightAxis, nearClipTranslation + viewportUpTranslation).GetUnit();

            _topPlane = Plane3D.FromNormalAndPoint(topNormal, _translation + farClipTranslation);

            Vector3D bottomNormal = Vector3D.Cross(-_rightAxis, nearClipTranslation - viewportUpTranslation).GetUnit();

            _bottomPlane = Plane3D.FromNormalAndPoint(bottomNormal, _translation + farClipTranslation);

            Vector3D rightNormal = Vector3D.Cross(-_upAxis, nearClipTranslation + viewportRightTranslation).GetUnit();

            _rightPlane = Plane3D.FromNormalAndPoint(rightNormal, _translation + farClipTranslation);

            Vector3D leftNormal = Vector3D.Cross(_upAxis, nearClipTranslation - viewportRightTranslation).GetUnit();

            _leftPlane = Plane3D.FromNormalAndPoint(leftNormal, _translation + farClipTranslation);

            _bFrustumPlanesDirty = false;
        }
コード例 #8
0
 public static Plane3D CreatePlane3D([NotNull] IEnumerable <SegmentProxy> ringSegments)
 {
     return(Plane3D.FitPlane(
                GetPoints(ringSegments, false)
                .Select(p => new Pnt3D(p.X, p.Y, p[2]))
                .ToList(), true));
 }
コード例 #9
0
        /// <summary>
        /// Returns mininum distance between regions
        /// </summary>
        /// <param name="inner"></param>
        /// <param name="outer"></param>
        /// <returns></returns>
        public static double GetDistanceBetweenPolylines3D(IPolyLine3D inner, IPolyLine3D outer)
        {
            IList <IPoint3D>   innerPoints   = inner.Segments.Select(s => s.StartPoint).ToList();
            IList <ISegment3D> outerSegments = outer.Segments.ToList();

            double  minDistance  = double.MaxValue;
            Point3D intersection = new Point3D();

            foreach (var innerPoint in innerPoints)
            {
                Plane3D tempPlane = new Plane3D
                {
                    PointOnPlane = new WM.Point3D(innerPoint.X, innerPoint.Y, 0)
                };

                foreach (var outerSegment in outerSegments)
                {
                    tempPlane.NormalVector = outerSegment.GetDirection();

                    if (outerSegment is ILineSegment3D)
                    {
                        intersection = new Point3D(tempPlane.GetIntersection(outerSegment as ILineSegment3D));
                    }

                    var vect     = intersection - (innerPoint as Point3D);
                    var tempDist = vect.Magnitude;

                    minDistance = Math.Min(minDistance, tempDist);
                }
            }

            return(minDistance);
        }
コード例 #10
0
        //Find the line of intersection between two planes.
        //The inputs are two game objects which represent the planes.
        //The outputs are a point on the line and a vector which indicates it's direction.
        internal static bool PlanesIntersection(Plane3D plane1, Plane3D plane2, out StraightLine intersection)
        {
            var linePoint = new WM.Point3D();
            var lineVec   = new WM.Vector3D();

            //Get the normals of the planes.
            var plane1Normal = plane1.NormalVector;
            var plane2Normal = plane2.NormalVector;

            //We can get the direction of the line of intersection of the two planes by calculating the
            //cross product of the normals of the two planes. Note that this is just a direction and the line
            //is not fixed in space yet.
            lineVec = WM.Vector3D.CrossProduct(plane1Normal, plane2Normal);

            //Next is to calculate a point on the line to fix it's position. This is done by finding a vector from
            //the plane2 location, moving parallel to it's plane, and intersecting plane1. To prevent rounding
            //errors, this vector also has to be perpendicular to lineDirection. To get this vector, calculate
            //the cross product of the normal of plane2 and the lineDirection.
            var ldir = WM.Vector3D.CrossProduct(plane2Normal, lineVec);

            var numerator = WM.Vector3D.DotProduct(plane1Normal, ldir);

            //Prevent divide by zero.
            if (Math.Abs(numerator) > 0.000001)
            {
                var plane1ToPlane2 = plane1.PointOnPlane - plane2.PointOnPlane;
                var t = WM.Vector3D.DotProduct(plane1Normal, plane1ToPlane2) / numerator;
                linePoint    = plane2.PointOnPlane + t * ldir;
                intersection = new StraightLine(ref linePoint, ref lineVec);
                return(true);
            }

            intersection = default(StraightLine);
            return(false);
        }
コード例 #11
0
ファイル: Face.cs プロジェクト: bhouston/ExoEngine3D
        public bool     IsContained(Vector3D pt)
        {
            //		Debug2.Push( "IsContained( " + pt + " )" );
            if (this.SidePlanes == null || this.SidePlanes.Count != this.Points.Count)
            {
                // recreate side planes for Face
                Vector3D ptNormal = this.GetNormal();
                int      count    = this.Points.Count;
                this.SidePlanes.Clear();
                for (int i = 0; i < count; i++)
                {
                    Vector3D a = this.Points[(i + count - 1) % count];
                    Vector3D b = this.Points[i];
                    Vector3D c = b + ptNormal;
                    this.SidePlanes.Add(Plane3D.FromCoplanarPoints(a, b, c));
                }
            }

            Debug.Assert(this.SidePlanes.Count == this.Points.Count);
            bool bInside = true;

            foreach (Plane3D plane in this.SidePlanes)
            {
//				Debug.WriteLine( "plane " + plane + " sign " + plane.GetSign( pt ) );
                if (plane.GetSign(pt) > 0)
                {
                    bInside = false;
//					Debug.WriteLine( "  outside!" );
                    break;
                }
            }

//			Debug2.Pop();
            return(bInside);
        }
コード例 #12
0
        public BSPTreeNode right; // smaller than splitting plane

        public BSPTreeNode(Triangle3D tri, T val)
        {
            triangles = new List <BSPTriangle>();
            triangles.Add(new BSPTriangle(tri, val));
            plane = new Plane3D();
            plane.Set3Points(tri[0], tri[1], tri[2]);
        }
コード例 #13
0
        private static void EnsureCutResult(IList <IGeometry> results,
                                            IPolygon originalPoly,
                                            Plane3D plane,
                                            int expectedResultPartCount)
        {
            double areaSum   = 0;
            var    partCount = 0;

            foreach (IGeometry result in results)
            {
                Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result));

                areaSum +=
                    GeometryUtils.GetParts((IGeometryCollection)result)
                    .Sum(part => ((IArea)part).Area);

                partCount += GeometryUtils.GetParts((IGeometryCollection)result).Count();

                if (plane != null)
                {
                    foreach (IPoint point in GeometryUtils.GetPoints(
                                 (IPointCollection)result))
                    {
                        Assert.AreEqual(plane.GetZ(point.X, point.Y), point.Z, 0.001);
                    }
                }
            }

            Assert.AreEqual(expectedResultPartCount, partCount);
            Assert.IsTrue(
                MathUtils.AreEqual(((IArea)originalPoly).Area, areaSum));
        }
コード例 #14
0
        public void CanDeterminePlaneCoincidenceMirroredAt0()
        {
            var x = new double[] { 0, 0, 1, 1, 0 };
            var y = new double[] { 0, 1, 1, 0, 0 };
            var z = new double[] { 10, 10, 10, 10, 10 };

            Plane3D plane1 = FitPlane3D(x, y, z, true);

            x = new double[] { 0, 0, 1, 1, 0 };
            y = new double[] { 0, 1, 1, 0, 0 };
            z = new double[] { 10, 10, 10, 10, 10 };

            for (var i = 0; i < z.Length; i++)
            {
                z[i] = z[i] * -1;
            }

            x = x.Reverse().ToArray();
            y = y.Reverse().ToArray();

            Plane3D plane2 = FitPlane3D(x, y, z, true);

            Assert.False(plane1.Equals(plane2));
            Assert.False(plane1.IsCoincident(plane2));
        }
コード例 #15
0
        protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta)
        {
            Vector3D normal = this.CalculateTransformationForSpotLightAdorner().Transform(new Vector3D(0.0, 0.0, 1.0));

            normal.Normalize();
            Plane3D          plane3D            = new Plane3D(normal, this.centerOfCone);
            Viewport3DVisual adorningViewport3D = this.ActiveView.AdornerLayer.GetAdornerSet3DContainer(this.ActiveAdorner.Element.Viewport).ShadowAdorningViewport3D;
            Ray3D            ray = CameraRayHelpers.RayFromViewportPoint(adorningViewport3D.Viewport.Size, adorningViewport3D.Camera, this.LastMousePosition + mousePositionDelta);
            double           t;

            if (!plane3D.IntersectWithRay(ray, out t))
            {
                return;
            }
            double    num1      = Math.Atan((ray.Evaluate(t) - this.centerOfCone).Length / 1.0) / Math.PI * 180.0;
            SpotLight spotLight = (SpotLight)this.Selected3DElement.ViewObject.PlatformSpecificObject;

            if (this.ActiveAdorner.TypeOfConeAngle == SpotLightAdornerBehavior3D.TypeOfConeAngle.InnerConeAngle)
            {
                double num2 = spotLight.OuterConeAngle - spotLight.InnerConeAngle;
                this.Selected3DElement.SetValue(SpotLightElement.InnerConeAngleProperty, (object)num1);
                this.Selected3DElement.SetValue(SpotLightElement.OuterConeAngleProperty, (object)(num1 + num2));
            }
            else
            {
                this.Selected3DElement.SetValue(SpotLightElement.OuterConeAngleProperty, (object)num1);
            }
            this.ActiveAdorner.PositionAndOrientGeometry();
        }
コード例 #16
0
        public static Plane3D GetSourcePlane([NotNull] IList <Pnt3D> pntList,
                                             double coplanarityTolerance,
                                             bool warnIfNotPlanar = true)
        {
            Plane3D sourcePlane = Plane3D.TryFitPlane(pntList);

            if (sourcePlane == null)
            {
                return(null);
            }

            double maxDeviation;
            string message;

            bool?coplanar = AreCoplanar(
                pntList, sourcePlane, coplanarityTolerance, out maxDeviation,
                out message);

            if (coplanar == null || !coplanar.Value)
            {
                if (warnIfNotPlanar)
                {
                    _msg.WarnFormat(
                        "Input geometry contains non-coplanar points. The result will not be co-planar either.");
                }

                _msg.DebugFormat(
                    "Input points are not planar w.r.t. tolerance {0}: {1}",
                    coplanarityTolerance, StringUtils.Concatenate(pntList, ", "));
            }

            return(sourcePlane);
        }
コード例 #17
0
        protected Point3D ProjectViewDirectionOnPlane(Plane3D plane, Point3D point)
        {
            var sndPoint = point + uiState.SketchPlane.Normal;
            var t        = plane.IntersectLine(point, sndPoint);

            return(MathUtils3D.Lerp(point, sndPoint, t));
        }
コード例 #18
0
        protected Face CreateFace(Vector3D axis, Vector3D x, Vector3D y, Textures textures, string textureFileName)
        {
            Face face = new Face();

            // create verticies and texture coordinates
            face.Points.Add(axis + x + y);
            face.TextureCoords.Add(new Vector3D(255f / 256, 255f / 256, 1f / 256));
            face.Points.Add(axis - x + y);
            face.TextureCoords.Add(new Vector3D(255f / 256, 1f / 256, 1f / 256));
            face.Points.Add(axis - x - y);
            face.TextureCoords.Add(new Vector3D(1f / 256, 1f / 256, 1f / 256));
            face.Points.Add(axis + x - y);
            face.TextureCoords.Add(new Vector3D(1f / 256, 255f / 256, 1f / 256));

            face.Points.Reverse();
            face.TextureCoords.Reverse();

            face.Plane               = Plane3D.FromNormalAndPoint(-axis, axis);
            face.Texture             = textures.RequestTexture(textureFileName);
            face.Texture.Clamp       = true;
            face.Texture.InternalUse = true;
            //if( face.Texture.IsLoaded == false ) {
            //	face.Texture.Load();
            //	Debug.Assert( face.Texture.IsLoaded == true, "can not load texture: " + face.Texture.FileName );
            //}

            return(face);
        }
コード例 #19
0
 private void Kl_FloorPlaneAvailable(Plane3D p)
 {
     if (_squatCompoundBodyAnalyzer != null)
     {
         _squatCompoundBodyAnalyzer.FloorPlane3D = p;
     }
 }
コード例 #20
0
        private static Position3D GetPosition(Axis3D moveRay, Plane3D axisPlane)
        {
            var(success, position) = axisPlane.Intersect(moveRay);
            var result = success ? position : moveRay.Offset;

            return(result);
        }
コード例 #21
0
        public static bool?AreCoplanar([NotNull] IList <Pnt3D> points,
                                       [NotNull] Plane3D plane,
                                       double tolerance,
                                       out double maxDeviationFromPlane,
                                       out string message)
        {
            message = null;

            if (!plane.IsDefined)
            {
                message =
                    $"The plane is not sufficiently defined by the input points {StringUtils.Concatenate(points, ", ")}.";
                maxDeviationFromPlane = double.NaN;
                return(null);
            }

            if (MathUtils.AreEqual(
                    0, GeomUtils.GetArea3D(points, new Pnt3D(plane.Normal))))
            {
                // Technically, the plane could be defined, but it is quite random
                message =
                    $"The ring is degenerate without 3D area {StringUtils.Concatenate(points, ", ")}.";
                maxDeviationFromPlane = double.NaN;
                return(null);
            }

            var coplanar = true;

            double maxDistance      = 0;
            Pnt3D  maxDistancePoint = null;

            foreach (Pnt3D pnt3D in points)
            {
                double d = plane.GetDistanceSigned(pnt3D);

                if (!MathUtils.AreEqual(d, 0, tolerance))
                {
                    if (Math.Abs(d) > Math.Abs(maxDistance))
                    {
                        maxDistance      = d;
                        maxDistancePoint = pnt3D;
                    }

                    coplanar = false;
                }
            }

            if (!coplanar)
            {
                _msg.VerboseDebug(
                    $"Coplanarity of point {maxDistancePoint} with plane {plane} is violated: {maxDistance}m");
                message =
                    $"Coplanarity of the plane is violated by {maxDistance} at point {maxDistancePoint}";
            }

            maxDeviationFromPlane = Math.Abs(maxDistance);

            return(coplanar);
        }
コード例 #22
0
        public void TestPlane3D2()
        {
            var v  = new Vector3D(1, 0, 0);
            var po = new Vector3D(0, 0, 0);
            var p  = new Plane3D(v, po);

            Assert.AreEqual(new Vector3D(1, 0, 0), p.Normal());
        }
コード例 #23
0
            private int InitPlaneOffsets(bool reportErrors,
                                         [CanBeNull] IFeature involvedFeature)
            {
                const int noError = 0;

                if (_minOffset <= 0 && _maxOffset >= 0)
                {
                    return(noError);
                }

                Plane3D plane      = Plane;
                var     unitNormal = UnitNormal;

                // double nf = plane.Nf;

                _minOffset = 0;
                _maxOffset = 0;
                var segmentsCount = 0;

                foreach (SegmentProxy segment in SegmentsPlane.Segments)
                {
                    segmentsCount++;
                    IPnt point = segment.GetStart(true);
                    // double f = normal.X * point.X + normal.Y * point.Y + normal.Z * point[2] + nf;
                    double distanceSigned =
                        plane.GetDistanceSigned(point.X, point.Y, point[2]);
                    double offset = Math.Abs(distanceSigned);

                    if (distanceSigned > 0 == unitNormal[2] > 0
                        )                 // oriented same as normal
                    {
                        _maxOffset = Math.Max(offset, _maxOffset);
                    }
                    else
                    {
                        _minOffset = Math.Min(-offset, _minOffset);
                    }
                }

                var coplanarityTolerance = GeomUtils.AdjustCoplanarityTolerance(
                    plane, _parent.CoplanarityTolerance,
                    _parent._zSrTolerance, _parent._xySrTolerance);

                double maxOffset = Math.Max(Math.Abs(_maxOffset), Math.Abs(_minOffset));

                _coplanar = maxOffset < coplanarityTolerance;

                if (_coplanar || !reportErrors || involvedFeature == null)
                {
                    return(noError);
                }

                IMultiPatch errorGeometry =
                    SegmentUtils.CreateMultiPatch(SegmentsPlane.Segments);

                return(_parent.ReportNonCoplanarFace(segmentsCount, maxOffset,
                                                     errorGeometry, involvedFeature));
            }
コード例 #24
0
        protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta)
        {
            Camera   camera    = (Camera)selected3DElement.Viewport.Camera.ViewObject.PlatformSpecificObject;
            Matrix3D matrix3D1 = Helper3D.CameraRotationMatrix(camera);
            Matrix3D matrix3D2 = camera.Transform.Value;

            if (matrix3D2.HasInverse)
            {
                matrix3D2.Invert();
                matrix3D1 *= matrix3D2;
            }
            Vector3D      vector1       = new Vector3D(matrix3D1.M11, matrix3D1.M21, matrix3D1.M31);
            Vector3D      vector2_1     = new Vector3D(matrix3D1.M12, matrix3D1.M22, matrix3D1.M32);
            Vector3D      vector2_2     = new Vector3D(matrix3D1.M13, matrix3D1.M23, matrix3D1.M33);
            Base3DElement base3Delement = selected3DElement.Parent as Base3DElement;
            Matrix3D      matrix3D3     = Matrix3D.Identity;

            if (base3Delement != null)
            {
                matrix3D3 = base3Delement.GetComputedTransformFromRoot3DElementToElement();
                matrix3D3.Invert();
            }
            if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.Rotate)
            {
                mousePositionDelta /= 2.0;
                Vector3D axisOfRotation = Vector3D.CrossProduct(new Vector3D(-mousePositionDelta.X, mousePositionDelta.Y, 0.0), vector2_2);
                double   length         = axisOfRotation.Length;
                if (length <= 0.0)
                {
                    return;
                }
                Vector3D vector3D = Helper3D.EulerAnglesFromQuaternion(new Quaternion(axisOfRotation, length) * Helper3D.QuaternionFromEulerAngles(selected3DElement.CanonicalRotationAngles));
                vector3D = new Vector3D(RoundingHelper.RoundAngle(vector3D.X), RoundingHelper.RoundAngle(vector3D.Y), RoundingHelper.RoundAngle(vector3D.Z));
                selected3DElement.CanonicalRotationAngles = vector3D;
            }
            else
            {
                Vector3D vector3D1         = new Vector3D(selected3DElement.CanonicalTranslationX, selected3DElement.CanonicalTranslationY, selected3DElement.CanonicalTranslationZ);
                Point    lastMousePosition = this.LastMousePosition;
                Point    endPoint          = lastMousePosition + mousePositionDelta;
                Vector3D vector3D2;
                if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.TranslateXY)
                {
                    Plane3D  plane     = new Plane3D(Vector3D.CrossProduct(vector1, vector2_1), this.hitPoint);
                    Vector3D vector    = Helper3D.VectorBetweenPointsOnPlane((Viewport3D)selected3DElement.Viewport.ViewObject.PlatformSpecificObject, plane, lastMousePosition, endPoint);
                    Vector3D vector3D3 = matrix3D3.Transform(vector);
                    vector3D2 = vector3D1 + vector3D3;
                }
                else
                {
                    double scale = this.Scale;
                    vector3D2 = vector3D1 + scale * -mousePositionDelta.Y * vector2_2;
                }
                selected3DElement.CanonicalTranslationX = RoundingHelper.RoundLength(vector3D2.X);
                selected3DElement.CanonicalTranslationY = RoundingHelper.RoundLength(vector3D2.Y);
                selected3DElement.CanonicalTranslationZ = RoundingHelper.RoundLength(vector3D2.Z);
            }
        }
コード例 #25
0
        public void TestPlane3D3()
        {
            var v1 = new Vector3D(1, 0, 0);
            var v2 = new Vector3D(0, 1, 0);
            var p0 = new Vector3D(0) as IPoint3D;
            var p  = new Plane3D(v1, v2, p0);

            Assert.AreEqual(new Vector3D(0, 0, 1), p.Normal());
        }
コード例 #26
0
 public void ConstructPlanes(List <PointSettingViewModel> pointSettings)
 {
     foreach (var planeName in PlaneNames)
     {
         IEnumerable <PointSettingViewModel> planeData = GrabPointsThatStartWith(pointSettings, planeName);
         Planes[planeName] = Plane3D.leastSquareAdaptFlatSurface(planeData.Select(d => d.X).ToArray(),
                                                                 planeData.Select(d => d.Y).ToArray(), planeData.Select(d => d.Value).ToArray());
     }
 }
コード例 #27
0
        public void TestPlane3D4()
        {
            var p1 = new Vector3D(1, 0, 0) as IPoint3D;
            var p2 = new Vector3D(0, 1, 0) as IPoint3D;
            var p0 = new Vector3D(0) as IPoint3D;
            var p  = new Plane3D(p0, p1, p2);

            Assert.AreEqual(new Vector3D(0, 0, 1), p.Normal());
        }
コード例 #28
0
        private static IList <RingGroup> CutRingGroupPlanar(
            [NotNull] RingGroup ringGroup,
            [NotNull] IPolyline cutLine,
            double tolerance,
            ChangeAlongZSource zSource,
            double zTolerance)
        {
            cutLine = GeometryFactory.Clone(cutLine);

            if (GeometryUtils.IsZAware(cutLine) &&
                zSource != ChangeAlongZSource.Target)
            {
                ((IZAware)cutLine).DropZs();
            }

            Plane3D plane = null;

            if (zSource == ChangeAlongZSource.SourcePlane)
            {
                plane = ChangeAlongZUtils.GetSourcePlane(
                    ringGroup.ExteriorRing.GetPoints().ToList(), zTolerance);
            }

            GeometryUtils.Simplify(cutLine, true, true);

            MultiPolycurve cutLinestrings = new MultiPolycurve(
                GeometryUtils.GetPaths(cutLine).Select(
                    cutPath => GeometryConversionUtils.CreateLinestring(cutPath)));

            IList <RingGroup> resultGroups =
                GeomTopoOpUtils.CutPlanar(ringGroup, cutLinestrings, tolerance);

            foreach (RingGroup resultPoly in resultGroups)
            {
                resultPoly.Id = ringGroup.Id;

                if (plane != null)
                {
                    resultPoly.AssignUndefinedZs(plane);
                }
                else
                {
                    resultPoly.InterpolateUndefinedZs();
                }
            }

            Marshal.ReleaseComObject(cutLine);

            if (resultGroups.Count == 0)
            {
                // Return uncut original
                resultGroups.Add(ringGroup);
            }

            return(resultGroups);
        }
コード例 #29
0
ファイル: PositionProjector.cs プロジェクト: zkrzhangdb/UniKh
        public static Vector3 CameraViewportPositionToScenePosition(
            Camera camScene,
            Vector2 viewportPos, // form 0 to 1
            Plane3D plane
            )
        {
            var ray = camScene.ViewportPointToRay(viewportPos);

            return(plane.IntersectWithRay(ray));
        }
コード例 #30
0
ファイル: SceneData.cs プロジェクト: MaximPr/RayTracer
        public SceneData()
        {
            IMaterial lightMaterial = new LightMaterial {
                Color = new Vector(50, 80, 100)
            };                                                                               //небо

            lights.Add(new DirectionLight
            {
                Color      = new Vector(500, 400, 100),
                Direction  = new Vector(.6f, .6f, 1).Normal(),
                Material   = lightMaterial,
                randomCoef = 0.2f
            });
            var roomMaterial = new DifuseMaterial()
            {
                Color = new Vector(0.2f, 0.2f, 0.2f)
            };

            //objects.Add(
            //    new Box3D { LowerLeft = new Vector(-14f, 1f, -4f), UpperRight = new Vector(-6f, 9f, 4f) }
            //    .Substract( new Sphere3D()
            //        {
            //            Radius = 5,
            //            Center = new Vector(-10, 5, 0)
            //        })
            //    .SetMaterial(roomMaterial)//new MirrorMaterial() { Color = new Vector(1, 1, 1) })
            //);

            //objects.Add(new Sphere3D()
            //{
            //    Radius = 3,
            //    Center = new Vector(-10, 5, 0)
            //}.SetMaterial(new MirrorMaterial() { Color = new Vector(1f, 0.1f, 0.1f) }));

            objects.Add(new Text3D("PIXAR").SetMaterial(new MirrorMaterial()));
            //Room
            objects.Add(new InvertOp()
            {
                Objects = new List <IFigure3D> {
                    new Box3D {
                        LowerLeft = new Vector(-30, -.5f, -30), UpperRight = new Vector(30, 18, 30)
                    },                                                                                        //LowerRoom
                    new Box3D {
                        LowerLeft = new Vector(-25, 17, -25), UpperRight = new Vector(25, 20, 25)
                    },                                                                                      //UpperRoom
                }
            }.SetMaterial(roomMaterial));
            objects.Add(new Box3D()
            {
                LowerLeft = new Vector(1.5f, 18.5f, -25), UpperRight = new Vector(6.5f, 20, 25)
            }
                        .RepeatX(8)
                        .SetMaterial(roomMaterial));
            objects.Add(Plane3D.YMinus(19.9).SetMaterial(lightMaterial));
        }
コード例 #31
0
ファイル: Plane3D.cs プロジェクト: tgjones/nexus
        public static Plane3D Transform(Plane3D plane, Matrix3D matrix)
        {
            Matrix3D matrix2 = Matrix3D.Invert(matrix);
            float x = plane.Normal.X;
            float y = plane.Normal.Y;
            float z = plane.Normal.Z;
            float d = plane.D;

            Plane3D plane2;
            plane2.Normal.X = (((x * matrix2.M11) + (y * matrix2.M12)) + (z * matrix2.M13)) + (d * matrix2.M14);
            plane2.Normal.Y = (((x * matrix2.M21) + (y * matrix2.M22)) + (z * matrix2.M23)) + (d * matrix2.M24);
            plane2.Normal.Z = (((x * matrix2.M31) + (y * matrix2.M32)) + (z * matrix2.M33)) + (d * matrix2.M34);
            plane2.D = (((x * matrix2.M41) + (y * matrix2.M42)) + (z * matrix2.M43)) + (d * matrix2.M44);
            return plane2;
        }
コード例 #32
0
ファイル: Plane3D.cs プロジェクト: tgjones/nexus
 public static Plane3D Normalize(Plane3D value)
 {
     Plane3D plane;
     float num2 = ((value.Normal.X * value.Normal.X) + (value.Normal.Y * value.Normal.Y)) + (value.Normal.Z * value.Normal.Z);
     if (System.Math.Abs((float)(num2 - 1f)) < 1.192093E-07f)
     {
         plane.Normal = value.Normal;
         plane.D = value.D;
         return plane;
     }
     float num = 1f / ((float)System.Math.Sqrt((double)num2));
     plane.Normal.X = value.Normal.X * num;
     plane.Normal.Y = value.Normal.Y * num;
     plane.Normal.Z = value.Normal.Z * num;
     plane.D = value.D * num;
     return plane;
 }
コード例 #33
0
 private void AddContours(Visual3D model1, int o, int m, int n)
 {
     var bounds = Visual3DHelper.FindBounds(model1, Transform3D.Identity);
     for (int i = 1; i < n; i++)
     {
         this.ContourPlane = new Plane3D(new Point3D(0, 0, bounds.Location.Z + bounds.Size.Z * i / n), new Vector3D(0, 0, 1));
         Visual3DHelper.Traverse<GeometryModel3D>(model1, this.AddContours);
     }
     for (int i = 1; i < m; i++)
     {
         this.ContourPlane = new Plane3D(new Point3D(0, bounds.Location.Y + bounds.Size.Y * i / m, 0), new Vector3D(0, 1, 0));
         Visual3DHelper.Traverse<GeometryModel3D>(model1, this.AddContours);
     }
     for (int i = 1; i < o; i++)
     {
         this.ContourPlane = new Plane3D(new Point3D(bounds.Location.X + bounds.Size.X * i / o, 0, 0), new Vector3D(1, 0, 0));
         Visual3DHelper.Traverse<GeometryModel3D>(model1, this.AddContours);
     }
 }
コード例 #34
0
        /// <summary>
        /// Intersects the specified source mesh geometry with the specified plane.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="inverseTransform">The inverse transform of the source.</param>
        /// <param name="plane">The plane.</param>
        /// <param name="complement">Cut with the complement set if set to <c>true</c>.</param>
        /// <returns>The intersected geometry.</returns>
        private MeshGeometry3D Intersect(MeshGeometry3D source, GeneralTransform3D inverseTransform, Plane3D plane, bool complement)
        {
            var p = inverseTransform.Transform(plane.Position);
            var p2 = inverseTransform.Transform(plane.Position + plane.Normal);
            var n = p2 - p;

            if (complement)
            {
                n *= -1;
            }

            return MeshGeometryHelper.Cut(source, p, n);
        }
コード例 #35
0
ファイル: Triangle.cs プロジェクト: mortennobel/UnityUtils
 void ReprojectY(List<Triangle> res, Plane3D plane)
 {
     double pos = 0;
     foreach (var t in res){
         for (int i=0;i<3;i++){
             var p = t.points[i];
             p.y = 0;
             RayD r = new RayD(p, Vector3D.up);
             if (plane.Raycast(r,out pos)){
                 p.y = (float)pos;
                 t.points[i] = p;
             }
         }
     }
 }
コード例 #36
0
ファイル: Triangle.cs プロジェクト: mortennobel/UnityUtils
 Vector3D ProjectToTriangle(Vector3D point)
 {
     Plane3D plane = new Plane3D(Normal, points[0]);
     bool isPointInPlane = System.Math.Abs(plane.GetDistanceToPoint(point))<0.0001;
     if (!isPointInPlane) {
         double dist;
         point.y = 0;
         var ray = new RayD(point, Vector3D.up);
         plane.Raycast(ray, out dist);
         point.y = dist;
     }
     return point;
 }
コード例 #37
0
ファイル: PlaneHelper.cs プロジェクト: tgjones/nexus
 /// <summary>
 /// Returns a value indicating what side (positive/negative) of a plane a point is
 /// </summary>
 /// <param name="point">The point to check with</param>
 /// <param name="plane">The plane to check against</param>
 /// <returns>Greater than zero if on the positive side, less than zero if on the negative size, 0 otherwise</returns>
 public static float ClassifyPoint(ref Point3D point, ref Plane3D plane)
 {
     return point.X * plane.Normal.X + point.Y * plane.Normal.Y + point.Z * plane.Normal.Z + plane.D;
 }