本文整理汇总了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 }
};
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}