当前位置: 首页>>代码示例>>C#>>正文


C# Vector.ToXyz方法代码示例

本文整理汇总了C#中Vector.ToXyz方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.ToXyz方法的具体用法?C# Vector.ToXyz怎么用?C# Vector.ToXyz使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector的用法示例。


在下文中一共展示了Vector.ToXyz方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ByOriginDirection

        public static Dictionary<string,object> ByOriginDirection(Point origin, Vector direction, int maxBounces, Elements.Views.View3D view)
        {
            var startpt = origin.ToXyz();
            var rayCount = 0;

            var bouncePts = new List<Point> {origin};
            var bounceElements = new List<Elements.Element>();

            for (int ctr = 1; ctr <= maxBounces; ctr++)
            {
                var referenceIntersector = new ReferenceIntersector((View3D)view.InternalElement);
                IList<ReferenceWithContext> references = referenceIntersector.Find(startpt, direction.ToXyz());
                ReferenceWithContext rClosest = null;
                rClosest = FindClosestReference(references);
                if (rClosest == null)
                {
                    break;
                }
                else
                {
                    var reference = rClosest.GetReference();
                    var referenceElement = DocumentManager.Instance.CurrentDBDocument.GetElement(reference);
                    var referenceObject = referenceElement.GetGeometryObjectFromReference(reference);
                    bounceElements.Add(referenceElement.ToDSType(true));
                    var endpt = reference.GlobalPoint;
                    if (startpt.IsAlmostEqualTo(endpt))
                    {
                        break;
                    }
                    else
                    {
                        rayCount = rayCount + 1;
                        var currFace = referenceObject as Face;
                        var endptUV = reference.UVPoint;
                        var FaceNormal = currFace.ComputeDerivatives(endptUV).BasisZ;  // face normal where ray hits
                        FaceNormal = rClosest.GetInstanceTransform().OfVector(FaceNormal); // transformation to get it in terms of document coordinates instead of the parent symbol
                        var directionMirrored = direction.ToXyz() - 2 * direction.ToXyz().DotProduct(FaceNormal) * FaceNormal; //http://www.fvastro.org/presentations/ray_tracing.htm
                        direction = directionMirrored.ToVector(); // get ready to shoot the next ray
                        startpt = endpt;
                        bouncePts.Add(endpt.ToPoint());
                    }
                }
            }

            return new Dictionary<string, object>
            {
                { "points", bouncePts },
                { "elements", bounceElements }
            };
        }
开发者ID:RobertiF,项目名称:Dynamo,代码行数:50,代码来源:RayBounce.cs

示例2: Torus

        /// <summary>
        /// Create a torus aligned to an axis with a radius and a section radius.
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="center"></param>
        /// <param name="radius"></param>
        /// <param name="sectionRadius"></param>
        /// <returns></returns>
        public static Solid Torus(Vector axis, Point center, double radius, double sectionRadius)
        {
            if (center == null)
            {
                throw new ArgumentException("Center is null");
            }

            if (axis == null || axis.Length < 1e-6)
            {
                throw new ArgumentException("Your axis is null or is 0 length.");
            }

            if (radius <= 0)
            {
                throw new ArgumentException("The radius must be greater than zero.");
            }

            if (sectionRadius <= 0)
            {
                throw new ArgumentException("The section radius must be greater than zero.");
            }

            var revolveAxis = axis.ToXyz();

            // get axis that is perp to axis by first generating random vector
            var zaxis = revolveAxis.Normalize();
            var randXyz = new XYZ(1, 0, 0);
            if (zaxis.IsAlmostEqualTo(randXyz)) randXyz = new XYZ(0, 1, 0);
            var yaxis = zaxis.CrossProduct(randXyz).Normalize();

            // get second axis that is perp to axis
            var xaxis = yaxis.CrossProduct(zaxis);

            // form origin of the arc
            var origin = center.ToXyz() + xaxis * radius;

            // create circle (this is ridiculous but curve loop doesn't work with a circle
            var arc1 = Autodesk.Revit.DB.Ellipse.Create(origin, sectionRadius, sectionRadius, xaxis, zaxis, 0, RevitPI);
            var arc2 = Autodesk.Revit.DB.Ellipse.Create(origin, sectionRadius, sectionRadius, xaxis, zaxis, RevitPI, 2 * RevitPI);

            // create curve loop from cirle
            var circleLoop = CurveLoop.Create(new List<Curve>() { arc1, arc2 });

            var trans = Transform.Identity;
            trans.Origin = center.ToXyz();
            trans.BasisX = xaxis;
            trans.BasisY = yaxis;
            trans.BasisZ = zaxis;

            return new Solid(circleLoop, trans, 0, 2*RevitPI);
        }
开发者ID:TheChosen0ne,项目名称:Dynamo,代码行数:59,代码来源:Solid.cs

示例3: Cylinder

        /// <summary>
        /// Create cylinder geometry by extruding a circle of a given radius, by a given height
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="radius"></param>
        /// <param name="direction"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static Solid Cylinder(Autodesk.DesignScript.Geometry.Point origin, double radius, Vector direction, double height)
        {
            if (radius <= 0)
            {
                throw new ArgumentException("Radius must be greater than zero.");
            }

            if (direction == null)
            {
                throw new ArgumentException("Direction can not be null.");
            }

            if (height <= 0)
            {
                throw new ArgumentException("Height must be greater than zero.");
            }

            var axis = direction.ToXyz();

            // get axis that is perp to axis by first generating random vector
            var zaxis = axis.Normalize();
            var randXyz = new XYZ(1, 0, 0);
            if (axis.IsAlmostEqualTo(randXyz)) randXyz = new XYZ(0, 1, 0);
            var yaxis = zaxis.CrossProduct(randXyz).Normalize();

            // get second axis that is perp to axis
            var xaxis = yaxis.CrossProduct(zaxis);

            // create circle (this is ridiculous, but curve loop doesn't work with a circle - you need two arcs)
            var arc1 = Autodesk.Revit.DB.Ellipse.Create(origin.ToXyz(), radius, radius, xaxis, yaxis, 0, RevitPI);
            var arc2 = Autodesk.Revit.DB.Ellipse.Create(origin.ToXyz(), radius, radius, xaxis, yaxis, RevitPI, 2 * RevitPI);

            // create curve loop from cirle
            var circleLoop = Autodesk.Revit.DB.CurveLoop.Create(new List<Curve>() { arc1, arc2 });

            return new Solid(new List<CurveLoop>{circleLoop}, axis, height);
        }
开发者ID:TheChosen0ne,项目名称:Dynamo,代码行数:45,代码来源:Solid.cs

示例4: ByExtrusion

        /// <summary>
        /// Create geometry by linearly extruding a closed curve
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="direction"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static Solid ByExtrusion(Autodesk.DesignScript.Geometry.Curve[] closedProfileCurves, Vector direction, double distance)
        {
            if (closedProfileCurves == null)
            {
                throw new ArgumentNullException("closedProfileCurves");
            }

            if (direction == null)
            {
                throw new ArgumentNullException("direction");
            }

            var loop = new Autodesk.Revit.DB.CurveLoop();
            closedProfileCurves.ForEach(x => loop.Append( x.ToRevitType()));

            return new Solid(new List<CurveLoop>() { loop }, direction.ToXyz(), distance);
        }
开发者ID:TheChosen0ne,项目名称:Dynamo,代码行数:24,代码来源:Solid.cs

示例5: ByPointVectorDistance

        /// <summary>
        /// Create a Reference Point Element offset from a point along a vector
        /// </summary>
        /// <param name="basePoint"></param>
        /// <param name="direction"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public static ReferencePoint ByPointVectorDistance(Point basePoint, Vector direction, double distance)
        {
            if (!Document.IsFamilyDocument)
            {
                throw new Exception("ReferencePoint Elements can only be created in a Family Document");
            }

            if (basePoint == null)
            {
                throw new ArgumentNullException("basePoint");
            }

            if (direction == null)
            {
                throw new ArgumentNullException("direction");
            }

            var pt = basePoint.ToXyz() + direction.ToXyz() * distance;

            return new ReferencePoint(pt.X, pt.Y, pt.Z);

        }
开发者ID:algobasket,项目名称:Dynamo,代码行数:29,代码来源:ReferencePoint.cs


注:本文中的Vector.ToXyz方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。