Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Offset XYZ points

Anonymous

Offset XYZ points

Anonymous
Not applicable

Hi,

I have an array of XYZ point.

How to calculate offset points by some distance in outward or inward direction without creating line?

need to get all offset points

Please refer an imageUntitled.png

 

0 Likes
Reply
Accepted solutions (2)
1,524 Views
3 Replies
Replies (3)

jeremytammik
Autodesk
Autodesk
Accepted solution

No, of course not. 

 

Without creating the line, at least in your imagination, there is no way to determine in which direction to offset each point.

 

However, the functionality you seek is provided by the Revit API CreateViaOffset method:

 

https://apidocs.co/apps/revit/2019/6cffc624-d197-0f3b-b68c-26b9c9a0adf8.htm

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Anonymous
Not applicable

Thanks for your prompt reply.

Got solution.

public List<XYZ> GetOffsetPoints(List<XYZ> lstPoints, double offset)
{
List<XYZ> lsttmpPoints = new List<XYZ>();
try
{
CurveLoop cl = new CurveLoop();
for (int i = 0; i < lstPoints.Count; i++)
{
XYZ startPoint = lstPoints[i];
XYZ endPoint = lstPoints[0];
if (i == lstPoints.Count - 1)
endPoint = lstPoints[0];
else
endPoint = lstPoints[i + 1];
Line line = Line.CreateBound(startPoint, endPoint);
cl.Append(line);
}
CurveLoop cl1 = new CurveLoop();
cl1 = CurveLoop.CreateViaOffset(cl, offset, new XYZ(0, 0, lstPoints[0].Z + 1));
for (int i = 0; i < cl1.Count(); i++)
{
Curve cv = cl1.ElementAt(i) as Curve;
lsttmpPoints.Add(cv.GetEndPoint(0));
}
}
catch (Exception ex)
{
lsttmpPoints = lstPoints;
}
return lsttmpPoints;
}

0 Likes

jeremytammik
Autodesk
Autodesk
Accepted solution

With this solution, I assume that your points form a curve loop in the XY plane.

 

Here is a slight cleanup of your solution:

 

    /// <summary>
    /// Create a new CurveLoop from a list of points.
    /// </summary>
    public static CurveLoop CreateCurveLoop(
      List<XYZ> pts )
    {
      int n = pts.Count;
      CurveLoop curveLoop = new CurveLoop();
      for( int i = 1; i < n; ++i )
      {
        curveLoop.Append( Line.CreateBound(
          pts[i - 1], pts[i] ) );
      }
      curveLoop.Append( Line.CreateBound(
        pts[n], pts[0] ) );
      return curveLoop;
    }

    /// <summary>
    /// Offset a list of points by a distance in a 
    /// given direction in or out of the curve loop.
    /// </summary>
    public static IEnumerable<XYZ> OffsetPoints( 
      List<XYZ> pts,
      double offset,
      XYZ normal )
    {
      CurveLoop curveLoop = CreateCurveLoop( pts );

      CurveLoop curveLoop2 = CurveLoop.CreateViaOffset( 
        curveLoop, offset, normal );

      return curveLoop2.Select<Curve, XYZ>( 
          c => c.GetEndPoint( 0 ) );
    }

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder