Create Extrusion Geometry Issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I have a floor with a slab edge underneath it, and I am trying to extend those slab edges under the slab when certain conditions exist (basically at an internal corner when the next section extends out a certain distance). I identify the external corners and then make a call to add just a simple extrusion, passing in the corner point, and the previous corner point along the plane.
/// <summary>
///
/// </summary>
/// <param name="doc"></param>
/// <param name="current">The is the Point that I want to Start From </param>
/// <param name="previous">This is the Previous Point</param>
private void CreateFooting(Document doc, XYZ current, XYZ previous)
{
// Get the extrusion direction
XYZ extrusionDirection = GetExtrusionDirection(previous, current);
Firstly, this gets the direction change between the 2 points as it could be changing X or Y or both, it then adds 300mm to the starting point (as this is the outside of the slab, and I want it from the inside of the footing)
private XYZ GetExtrusionDirection(XYZ previous, XYZ current)
{
// Calculate the vector from previous to current
XYZ directionVector = (current - previous).Normalize();
// Convert 300mm to feet
double distance = 300 / 304.8;
// Calculate the new point 300mm past the current point in the direction away from the previous point
XYZ extrusionPoint = current + directionVector * distance;
return extrusionPoint;
}
I then offset it further out by (fixed but will be eventually be parameter driven 300mm - which is the thickness of the external footing). My complete method is below, but it in essence
- gets a direction from current to previous (as I want to continue on the same plane)
- sets up 4 points (p1 to p4) in essence 300mm wide, by 200mm, but starting 300mm "past" the current starting point, then adds those 4 points into a CurveLoop
- It then creates a new extrusion (called footing) with the CurveLoop, in the extrusionDirection and 2.000m long)
- finally adds it.
private void CreateFooting(Document doc, XYZ current, XYZ previous)
{
// Get the extrusion direction
XYZ extrusionDirection = GetExtrusionDirection(previous, current);
// Convert millimeters to feet
double width = 300 / 304.8; // 300mm to feet
double depth = 200 / 304.8; // 300mm to feet
double length = 2000 / 304.8; // 2 meters to feet
// Define points for the footing profile
XYZ p1 = extrusionDirection;
XYZ p2 = extrusionDirection + new XYZ(width, 0, 0);
XYZ p3 = p2 + new XYZ(0, 0, -depth);
XYZ p4 = extrusionDirection + new XYZ(0, 0, -depth);
Line line1 = Line.CreateBound(p1, p2);
Line line2 = Line.CreateBound(p2, p3);
Line line3 = Line.CreateBound(p3, p4);
Line line4 = Line.CreateBound(p4, p1);
CurveLoop curveLoop = new CurveLoop();
curveLoop.Append(line1);
curveLoop.Append(line2);
curveLoop.Append(line3);
curveLoop.Append(line4);
// Create the extrusion
Solid footing = GeometryCreationUtilities.CreateExtrusionGeometry(new List<CurveLoop> { curveLoop }, extrusionDirection, length);
// Create a DirectShape to represent the footing
DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
ds.SetShape(new List<GeometryObject> { footing });
}
It's drawing the extrusion the right size, but on an angle, and I can't figure out why (shape is red, should be blue), so the problem has to be with y extrustion direction vector.
Am I right in assuming that I can create the vector from the current point - previous point?
Thanks for help and any ideas appreciated.
Cheers, Al