コード例 #1
0
ファイル: Matrix44.cs プロジェクト: idea-statica/bim-plus
        /// <summary>
        /// Gets the rotation from matrix
        /// </summary>
        /// <param name="matrix">Rotation from matrix</param>
        /// <param name="axis">Around axis</param>
        /// <returns>Angle of rotation (0 - 2PI)</returns>
        public double GetRotation(IMatrix44 matrix, Axis axis)
        {
            double rot = 0.0;
            double y   = 0.0;

            switch (axis)
            {
            case Axis.XAxis:
                rot = GeomOperation.GetAngle(matrix.AxisZ, AxisZ);
                y   = AxisZ | (matrix.AxisX * matrix.AxisZ).Normalize;
                break;

            case Axis.YAxis:
                rot = GeomOperation.GetAngle(matrix.AxisX, AxisX);
                y   = AxisX | (matrix.AxisY * matrix.AxisX).Normalize;
                break;

            case Axis.ZAxis:
                rot = GeomOperation.GetAngle(matrix.AxisY, AxisY);
                y   = AxisY | (matrix.AxisZ * matrix.AxisY).Normalize;
                break;
            }

            if (y.IsLesser(0))
            {
                rot = 2 * Math.PI - rot;
            }

            return(rot);
        }
コード例 #2
0
        internal static IPolygon2D ToPolygon2D(IPolyLine3D polyline3D, IMatrix44 lcs, int numberOfArcTiles)
        {
            var polyline = ConvertTo2D(polyline3D, lcs);
            var polygon  = ToPolygon2D(polyline, numberOfArcTiles);

            return(polygon);
        }
コード例 #3
0
        /// <summary>
        /// Calculate Points On Region.
        /// </summary>
        /// <returns>returns the point on region</returns>
        private IPoint3D GetPointOnRegion()
        {
            IPoint3D  pointOnRegion = new Point3D(OffsetX, OffsetY, 0.0);
            IMatrix44 matrix        = GeomOperation.GetMatrixPlane(region);

            return(matrix.TransformToGCS(pointOnRegion));
        }
コード例 #4
0
        public static IPolyLine3D ConvertTo3D(IPolyLine2D polyline, IMatrix44 lcs)
        {
            var geom = GeomOperation.ConvertTo3D(polyline);

            GeomOperation.TransformToGCS(lcs, geom);
            return(geom);
        }
コード例 #5
0
 /// <summary>
 /// Transform a given region to LCS using the matrix
 /// </summary>
 /// <param name="matrix">Matrix which is used to transform</param>
 /// <param name="region">Region which is to be transformed</param>
 public static void TransformToLCS(IMatrix44 matrix, IRegion3D region)
 {
     TransformToLCS(matrix, region.Outline);
     foreach (IPolyLine3D opening in region.Openings)
     {
         TransformToLCS(matrix, opening);
     }
 }
コード例 #6
0
        public static ISegment2D ConvertTo2D(ISegment3D segment3D, IMatrix44 lcs)
        {
            var segmentCopy = segment3D.CloneSegment();

            GeomOperation.TransformToLCS(lcs, segmentCopy);
            var segment2D = ConvertTo2D(segmentCopy);

            return(segment2D);
        }
コード例 #7
0
        /// <summary>
        /// Transforms given polyline 3D to LCS using matrix and converts to 2D geometry.
        /// </summary>
        /// <param name="polyline3D">Polyline to convert.</param>
        /// <param name="lcs">Local coordinate system.</param>
        /// <returns>2D geometry.</returns>
        public static IPolyLine2D ConvertTo2D(IPolyLine3D polyline3D, IMatrix44 lcs)
        {
            var polylineCopy = new PolyLine3D(polyline3D);

            GeomOperation.TransformToLCS(lcs, polylineCopy);
            var polyline2D = ConvertTo2D(polylineCopy);

            return(polyline2D);
        }
コード例 #8
0
        internal static IPolygon2D ConvertTo2D(Polygon3D polygon3D, IMatrix44 lcs)
        {
            var pts = polygon3D.Select(pt =>
            {
                var p = lcs.TransformToLCS(pt);
                return(new Point(p.X, p.Y));
            });

            return(new Polygon2D(pts));
        }
コード例 #9
0
        /// <summary>
        /// Convert the points of polyline based on baseGeometry
        /// </summary>
        /// <param name="matrix">LCS matrix of baseGeometry</param>
        /// <param name="baseGeometry">Based on this region, the given polyline is modifed</param>
        /// <param name="polyline">Input polyline object</param>
        /// <param name="modifyInput">If true, given polyline object is modified. Otherwise prepare new polyline object</param>
        /// <returns>Polyline object which is based on baseGeometry</returns>
        public static IPolyLine3D GetPolylineOnRegion(IMatrix44 matrix, IRegion3D baseGeometry, IPolyLine3D polyline, bool modifyInput = true)
        {
            if (baseGeometry == null || polyline == null)
            {
                return(null);
            }

            if (matrix == null)
            {
                matrix = GetMatrixPlane(baseGeometry);
            }

            if (!modifyInput)
            {
                polyline = new PolyLine3D(polyline);
            }

            bool isIndependent = true;

            if (polyline.IsClosed)
            {
                isIndependent = false;
            }

            ISegment3D firstSegment = null;
            IPoint3D   lastEndPoint = null;

            foreach (ISegment3D segment in polyline.Segments)
            {
                GetSegmentOnRegion(matrix, baseGeometry, segment, isIndependent);
                if (lastEndPoint != null)
                {
                    segment.StartPoint = lastEndPoint;
                }

                if (firstSegment == null)
                {
                    firstSegment = segment;
                }

                lastEndPoint  = segment.EndPoint;
                isIndependent = false;
            }

            if (firstSegment != null && lastEndPoint != null)
            {
                firstSegment.StartPoint = lastEndPoint;
            }

            return(polyline);
        }
コード例 #10
0
        /// <summary>
        /// Calculate relative position of point on polyline.
        /// </summary>
        /// <param name="region">region</param>
        /// <param name="point">Point</param>
        /// <param name="relativeX">Relative Position along local X axis</param>
        /// <param name="relativeY">Relative Position along local Y axis</param>
        /// <param name="toleranceLevel">Tolerance Level</param>
        /// <returns>True if point exist in polyline</returns>
        public static bool GetRelativePosition(IRegion3D region, IPoint3D point, ref double relativeX, ref double relativeY, double toleranceLevel = MathConstants.ZeroWeak)
        {
            IMatrix44 matrix     = GeomOperation.GetMatrixPlane(region);
            IPoint3D  pointInLCS = matrix.TransformToLCS(point);

            if (pointInLCS.Z.IsZero() == false)
            {
                return(false);
            }

            relativeX = pointInLCS.X;
            relativeY = pointInLCS.Y;
            return(true);
        }
コード例 #11
0
        /// <summary>
        /// Convert the points of segment based on baseGeometry
        /// </summary>
        /// <param name="matrix">LCS matrix of baseGeometry</param>
        /// <param name="baseGeometry">Based on this region, the given segment is modifed</param>
        /// <param name="segment">Input segment object</param>
        /// <param name="isIndependent">Segment is independent</param>
        /// <param name="modifyInput">If true, given segment object is modified. Otherwise prepare new segment object</param>
        /// <returns>Segment object which is based on baseGeometry</returns>
        public static ISegment3D GetSegmentOnRegion(IMatrix44 matrix, IRegion3D baseGeometry, ISegment3D segment, bool isIndependent = true, bool modifyInput = true)
        {
            if (baseGeometry == null || segment == null)
            {
                return(null);
            }

            if (matrix == null)
            {
                matrix = GetMatrixPlane(baseGeometry);
            }

            if (!modifyInput)
            {
                segment = segment.CloneSegment();
            }

            ILineSegment3D line = segment as ILineSegment3D;

            if (line != null)
            {
                if (isIndependent)
                {
                    line.StartPoint = GetPointOnRegion(matrix, baseGeometry, line.StartPoint);
                }

                line.EndPoint = GetPointOnRegion(matrix, baseGeometry, line.EndPoint);
                return(line);
            }

            IArcSegment3D arc = segment as IArcSegment3D;

            if (arc != null)
            {
                if (isIndependent)
                {
                    arc.StartPoint = GetPointOnRegion(matrix, baseGeometry, arc.StartPoint);
                }

                arc.IntermedPoint = GetPointOnRegion(matrix, baseGeometry, arc.IntermedPoint);
                arc.EndPoint      = GetPointOnRegion(matrix, baseGeometry, arc.EndPoint);
                return(arc);
            }

            throw new NotSupportedException();
        }
コード例 #12
0
        public static IRegion2D ConvertTo2D(IRegion3D region3D, IMatrix44 lcs)
        {
            var regionCopy = new Region3D(region3D);

            GeomOperation.TransformToLCS(lcs, regionCopy);
            var outline2D = ConvertTo2D(regionCopy.Outline);
            var region2D  = new Region2D(outline2D);

            if (regionCopy.OpeningsCount > 0)
            {
                foreach (var opening3D in regionCopy.Openings)
                {
                    region2D.Openings.Add(ConvertTo2D(opening3D));
                }
            }

            return(region2D);
        }
コード例 #13
0
        internal static Polygon3D ToPolygon3D(IPolyLine2D outline, IMatrix44 lcs)
        {
            /// pozor - konvertuje pouze koncove body - tzn. zadne obloucky
            var count   = outline.Segments.Count;
            var polygon = new Polygon3D(count + 1);

            var point   = outline.StartPoint;
            var point3D = lcs.TransformToGCS(new WM.Point3D(0, point.X, point.Y));

            polygon.Add(point3D);

            for (var i = 0; i < count; ++i)
            {
                point   = outline.Segments[i].EndPoint;
                point3D = lcs.TransformToGCS(new WM.Point3D(0, point.X, point.Y));
                polygon.Add(point3D);
            }

            return(polygon);
        }
コード例 #14
0
ファイル: Matrix44.cs プロジェクト: idea-statica/bim-plus
        /// <summary>
        /// Returns equation result
        /// </summary>
        /// <param name="matrix">Matrix</param>
        /// <param name="tolerance">Matrix</param>
        /// <returns>Return true if the data are equlas</returns>
        public bool EqualsTo(IMatrix44 matrix, double tolerance = 1e-10)
        {
            if (matrix == null)
            {
                return(false);
            }

            var matrix44 = matrix as Matrix44;

            for (int i = 0; i < RowCount; i++)
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    if (!this.matrixElement[i, j].IsEqual(matrix44.matrixElement[i, j], tolerance))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #15
0
        /// <summary>
        /// Convert the points of region based on baseGeometry
        /// </summary>
        /// <param name="baseGeometry">Based on this region, the given region is modifed</param>
        /// <param name="region">Input region object</param>
        /// <param name="modifyInput">If true, given region object is modified. Otherwise prepare new region object</param>
        /// <returns>Region object which is based on baseGeometry</returns>
        public static IRegion3D GetRegionOnRegion(IRegion3D baseGeometry, IRegion3D region, bool modifyInput = true)
        {
            if (baseGeometry == null || region == null)
            {
                return(null);
            }

            if (!modifyInput)
            {
                region = new Region3D(region);
            }

            IMatrix44 matrix = GetMatrixPlane(baseGeometry);

            GetPolylineOnRegion(matrix, baseGeometry, region.Outline);
            foreach (IPolyLine3D opening in region.Openings)
            {
                GetPolylineOnRegion(matrix, baseGeometry, opening);
            }

            return(region);
        }
コード例 #16
0
        /// <summary>
        /// Prepaer a point on region from given region and point.
        /// </summary>
        /// <param name="matrix">LCS matrix of baseGeometry</param>
        /// <param name="baseGeometry">IRegion3D</param>
        /// <param name="point">IPoint3D</param>
        /// <returns>New IPointOnRegion object</returns>
        public static IPointOnRegion GetPointOnRegion(IMatrix44 matrix, IRegion3D baseGeometry, IPoint3D point)
        {
            if (baseGeometry == null || point == null)
            {
                return(null);
            }

            if (matrix == null)
            {
                matrix = GetMatrixPlane(baseGeometry);
            }

            IPoint3D pointInLCS = matrix.TransformToLCS(point);

            if (pointInLCS.Z.IsZero() == false)
            {
                throw new NotSupportedException("Screen point and selected region are not in same plane");
            }

            IPointOnRegion pointOnRegion = new PointOnRegion(baseGeometry, pointInLCS.X, pointInLCS.Y);

            return(pointOnRegion);
        }
コード例 #17
0
        internal static IPolyLine3D ConvertTo3D(IPolygon2D polygon2D, IMatrix44 lcs = null)
        {
            if (polygon2D == null)
            {
                return(null);
            }

            var count = polygon2D.Count;

            if (count > 1)
            {
                var polyline3D = new PolyLine3D();
                var beg        = new Point3D(polygon2D[0].X, polygon2D[0].Y, 0);
                for (var i = 1; i < count; ++i)
                {
                    var end = new Point3D(polygon2D[i].X, polygon2D[i].Y, 0);
                    var seg = new LineSegment3D(beg, end);
                    polyline3D.Add(seg);
                    beg = end;
                }

                if (polygon2D.IsClosed)
                {
                    polyline3D.Segments.Last().EndPoint = polyline3D.Segments.First().StartPoint;
                }

                if (lcs != null)
                {
                    GeomOperation.TransformToGCS(lcs, polyline3D);
                }

                return(polyline3D);
            }

            return(null);
        }
コード例 #18
0
ファイル: Matrix44.cs プロジェクト: idea-statica/bim-plus
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">Source matrix</param>
 public Matrix44(IMatrix44 source)
 {
     SetMatrix(source.Origin, source.AxisX, source.AxisY, source.AxisZ);
 }