# Fit the curves in geometry ........polyline to geometry line

**URL:** <https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320>\
**Category:** Geometry\
**Tags:** civil3d\
**Created:** [April 27, 2021, 4:35am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320 "2021-04-27T04:35:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shy\_87](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Shy\_87](https://forum.dynamobim.com/u/Shy_87)\
**Post date:** [April 27, 2021, 4:35am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/1 "2021-04-27T04:35:10Z")

</div>

Hi All,  
This is a twister around which i am unable to find any logic.  
The Task is i have a polyline and need to convert it to a geometry of small arc’s, compound curves and reverse curves (Minimum Radius 550m say) maintaining the tangency with previous curve. The only limitation is the new line should be in the range of 50mm to 100mm max from the existing polyline.

I am able to do it manually by trial and error and fixing the arc/Compund curves but was trying to find a way to automate this process.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/5/551a3793175b5b082fea875f237b76b5f6b0758a.png)

sample line is attached in the drawing. [new block.dwg](https://forum.dynamobim.com/uploads/short-url/A3jdFqw4jF0VlenEsrm48lKuiGV.dwg) (120.4 KB)

Will be really happy to get some guidance on way forward.  
Thanks.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 27, 2021, 5:00am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/2 "2021-04-27T05:00:55Z")

</div>

This might be a good place to start: [Dynamo Dictionary](https://dictionary.dynamobim.com/#/Geometry/Curve/Action/ApproximateWithArcAndLineSegments)

---

<div class="post-metadata">

**Author:** ![Shy\_87](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Shy\_87](https://forum.dynamobim.com/u/Shy_87)\
**Post date:** [April 27, 2021, 5:32am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/3 "2021-04-27T05:32:38Z")

</div>

Thanks for the reply @jacob.small but its not resolving the issue…

The node is just taking up the line vertices and adding arc/curve in between i guess. so the end result is same as the first line with same vertices.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/e/6e84d8257fb7d86d0787e17da4d1e09b61ca9106.png) am i missing something ?

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 27, 2021, 6:17am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/4 "2021-04-27T06:17:48Z")

</div>

I may not be understanding the intended result here - can you sketch out what you have vs what you want?

---

<div class="post-metadata">

**Author:** ![Shy\_87](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Shy\_87](https://forum.dynamobim.com/u/Shy_87)\
**Post date:** [April 27, 2021, 6:40am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/5 "2021-04-27T06:40:52Z")

</div>

@jacob.small Sorry if i was not clear,

The intention is to create red line of arc/compound curve from the cyan line. The sample line is attached in above drawing.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/1/c17490c6a81d130c009cfbdfaac2f1ab0ad794a6.png)

Hope i am able to explain.

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [April 27, 2021, 6:02pm UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/6 "2021-04-27T18:02:02Z")

</div>

Are you trying to offset a polyline as a polyarc (a series of arcs)? See if this helps.

 ![polylineToPolyarc_2021-04-27_01-37-22](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/b/1b8f20c8df56b0d5d8c6df6fcaae748f88582f62.png)  
[offsetPolylineAsArcs.dyn](https://forum.dynamobim.com/uploads/short-url/32PYgYUsDIsonvMixvQFOMuVwC3.dyn) (8.3 KB)

```
def lnToAr(pl:var[]..[], of:double)
{
	pc1 = List.FirstItem(pl.Curves());
	//First Arc
	ac1 = List.FirstItem(pc1);
	ac2 = ac1.Offset(of).PointAtParameter(0.5);
	ar1 = Arc.ByThreePoints(ac1.StartPoint,ac2,ac1.EndPoint);
	ac3 = List.RestOfItems(pc1);

	ar5 = [Imperative]
	{
		cnt = 1;
		pc2 = [ar1];

		for (cr in ac3)
		{
			pc2[cnt] = Arc.ByStartPointEndPointStartTangent(cr.StartPoint,cr.EndPoint,ar1.TangentAtParameter(1));
			ar1 = pc2[cnt];
			cnt = cnt + 1;
		}
		return pc2;
	}
	return ar5;
};

def offPlyArc(pl:var[]..[], off:double, mnRd:double)
{
	pl1 = pl.Offset(off);
	of1 = 0.1;
	bl1 = true;
	ar2 = [Imperative]
	{
		ar3 = [];
		while (bl1)
		{
 			ar3 = lnToAr(pl1,of1);
 			bl1 = List.Contains(ar3.Radius >= mnRd, true) && of1<10;
 			of1 = of1 + 0.1;
		}
		return ar3;
	}
	return ar2;
};
```

---

<div class="post-metadata">

**Author:** ![Shy\_87](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Shy\_87](https://forum.dynamobim.com/u/Shy_87)\
**Post date:** [April 28, 2021, 7:03am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/7 "2021-04-28T07:03:34Z")

</div>

@Vikram_Subbaiah thanks for reply, sorry if was not clear though the process is not related to creating an offset but try to fit in the arcs, compound curves to get a proper geometry from cyan line. I have moved cyan line to just provide clarity on the entity and result i am intending to get in RED. its some what best fit geometry but removing the vertices to get to that point which is not happening as per the ApproximatewithArcandLinesegment node. that being said if i can get offset line also i can get the required line from that i guess.

the code is giving bellow error in AutoCAD might be working fine in Revit (based on Revit API).

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/8/f8afe7f1d921960c020eddbbef887ae0255d45b5.png)

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [April 28, 2021, 8:00am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/8 "2021-04-28T08:00:40Z")

</div>

> [@Shy\_87](#):
>
> the process is not related to creating an offse

In that case set offset to 0

> [@Shy\_87](#):
>
> fit in the arcs, compound curves to get a proper geometry from cyan line

The definition converts a series of lines to a series of tangential curves

> [@Shy\_87](#):
>
> the code is giving bellow error in AutoCAD might be working fine in Revit

Try prefixing _Arc_ as suggested in the error  
I’ve replaced _Arc_ with _Autodesk.DesignScript.Geometry.Arc_ below. If it doesn’t work you could try _Autodesk.AutoCAD.DynamoNodes.Arc_

```
def lnToAr(pl:var[]..[], of:double)
{
	pc1 = List.FirstItem(pl.Curves());
	//First Arc
	ac1 = List.FirstItem(pc1);
	ac2 = ac1.Offset(of).PointAtParameter(0.5);
	ar1 = Autodesk.DesignScript.Geometry.Arc.ByThreePoints(ac1.StartPoint,ac2,ac1.EndPoint);
	ac3 = List.RestOfItems(pc1);

	ar5 = [Imperative]
	{
		cnt = 1;
		pc2 = [ar1];

		for (cr in ac3)
		{
			pc2[cnt] = Autodesk.DesignScript.Geometry.Arc.ByStartPointEndPointStartTangent(cr.StartPoint,cr.EndPoint,ar1.TangentAtParameter(1));
			ar1 = pc2[cnt];
			cnt = cnt + 1;
		}
		return pc2;
	}
	return ar5;
};

def offPlyArc(pl:var[]..[], off:double, mnRd:double)
{
	pl1 = pl.Offset(off);
	of1 = 0.1;
	bl1 = true;
	ar2 = [Imperative]
	{
		ar3 = [];
		while (bl1)
		{
 			ar3 = lnToAr(pl1,of1);
 			bl1 = List.Contains(ar3.Radius >= mnRd, true) && of1<10;
 			of1 = of1 + 0.1;
		}
		return ar3;
	}
	return ar2;
};

```

---

<div class="post-metadata">

**Author:** ![Shy\_87](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Shy\_87](https://forum.dynamobim.com/u/Shy_87)\
**Post date:** [April 28, 2021, 9:41am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/9 "2021-04-28T09:41:39Z")

</div>

Still not sure why its not working …

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/c/4cbcb25317d5ead86a68e4c12122ee32cc452715.png)

By the way

> [@Vikram\_Subbaiah](#):
>
> Are you trying to offset a polyline as a polyarc (a series of arcs)? See if this helps.

At this location i can see your offset line have 233 points compare to original 151, little confused if the geometry is improved points will be reduced right ?

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [April 28, 2021, 11:27am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/10 "2021-04-28T11:27:33Z")

</div>

> [@Shy\_87](#):
>
> Still not sure why its not working

Sorry, I have no clue either 😕

> [@Shy\_87](#):
>
> little confused if the geometry is improved points will be reduced right

The definition creates 151 arcs corresponding to the original 151 lines (not sure what the 233 was)

While this definition might not do what you’re looking for, I suppose you’ll need to engage a similar _Imperative_ approach as every subsequent component is dependent on the altered state of previous one.

---

<div class="post-metadata">

**Author:** ![Shy\_87](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@Shy\_87](https://forum.dynamobim.com/u/Shy_87)\
**Post date:** [April 28, 2021, 11:35am UTC](https://forum.dynamobim.com/t/fit-the-curves-in-geometry-polyline-to-geometry-line/63320/11 "2021-04-28T11:35:29Z")

</div>

Yes thats what is happening with that OTT Node too …i am doing it manually at the moment. In civil 3D we hv a option of best fit alignment but its not much useful because of the restrictions in shifting.
