The polyline is changed by using code. Here it the function that changes the polyline based on the peakHeight variable.
private Polyline CurveFromPoly(Polyline originalPolyline)
{
if (originalPolyline == null)
{
throw new ArgumentNullException(nameof(originalPolyline), "Original polyline cannot be null.");
}
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Polyline curvePolyline = null;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
curvePolyline = new Polyline();
btr.AppendEntity(curvePolyline);
tr.AddNewlyCreatedDBObject(curvePolyline, true);
// Copy properties from original polyline
curvePolyline.Linetype = originalPolyline.Linetype;
curvePolyline.Color = originalPolyline.Color;
curvePolyline.Layer = originalPolyline.Layer;
curvePolyline.LinetypeScale = originalPolyline.LinetypeScale;
double totalLength = originalPolyline.Length;
double peakHeight = 25.0;
// Define section lengths
double startStraightLength = totalLength * 0.1;
double startCurveLength = totalLength * 0.15;
double middleStraightLength = totalLength * 0.5;
double endCurveLength = startCurveLength;
double endStraightLength = startStraightLength;
// Step size for smooth curve
int curvePoints = 20;
// 1. Start straight section
for (double i = 0; i <= startStraightLength; i += startStraightLength / 10)
{
Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(i);
Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y);
curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
}
// 2. Rising curved section with smooth transition
for (int i = 0; i <= curvePoints; i++)
{
double t = i / (double)curvePoints;
double distance = startStraightLength + t * startCurveLength;
// Use sine function for smooth start of curve
double heightOffset = peakHeight * Math.Sin(t * Math.PI / 2);
Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(distance);
Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y + heightOffset);
curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
}
// 3. Middle straight section at peak height
for (double i = startStraightLength + startCurveLength; i <= startStraightLength + startCurveLength + middleStraightLength; i += middleStraightLength / 10)
{
Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(i);
Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y + peakHeight);
curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
}
// 4. Declining curved section with smooth transition
for (int i = 0; i <= curvePoints; i++)
{
double t = i / (double)curvePoints;
double distance = startStraightLength + startCurveLength + middleStraightLength + t * endCurveLength;
// Use cosine function for smooth end of curve
double heightOffset = peakHeight * Math.Cos(t * Math.PI / 2);
Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(distance);
Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y + heightOffset);
curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
}
// 5. End straight section
for (double i = startStraightLength + startCurveLength + middleStraightLength + endCurveLength; i <= totalLength; i += endStraightLength / 10)
{
Point3d pointAlongPolyline = originalPolyline.GetPointAtDist(i);
Point2d newPoint = new Point2d(pointAlongPolyline.X, pointAlongPolyline.Y);
curvePolyline.AddVertexAt(curvePolyline.NumberOfVertices, newPoint, 0, 0, 0);
}
tr.Commit();
}
return curvePolyline;
}