Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Centerline Spline between two (different) Splines

7 REPLIES 7
Reply
Message 1 of 8
Eide.N
1078 Views, 7 Replies

Centerline Spline between two (different) Splines

Hi all,

 

I am looking for the average of two curves (splines). If I have sketched the white lines, I want to create the red line.

And, if possible, the ability to have more than one (red) line, each an average of that division.

I'm not even sure where to start.

 

4048.3 (2).png

 

This one below is done in AutoCAD with CURVEAXIS from cadforum.cz

https://www.cadforum.cz/en/how-to-create-an-axis-of-two-curves-average-curve-tip11025

 

Screenshot 2021-04-15 091958.png

 

 

7 REPLIES 7
Message 2 of 8
WCrihfield
in reply to: Eide.N

Are you looking for a code based solution, or just a manual process to produce the 'red' line?

Are both splines on the same flat 2D sketch plane?  Are both splines within the same 3D sketch, or is each in its own separate 3D sketch?  I feel like I need to ask more questions, but I'm not even sure which questions I need to be asking.  There are currently 4 different ways to create splines within an Inventor part document sketch, so that may play a part in it too.

For some reason, I can't visit that link you supplied.  The web browser times out.

 

If they are both on the same 2D plane, then in theory, and perhaps by code, you could start at the one end of both splines, and get the point coordinates, then through either math or the use of additional transient geometry, find the 2D point that is half way between the two points.  Then repeat that process for the point at every 1% (depending on how accurate you want it to be) of the length of each spline, creating a new point for each.  Then create a new spline that intersected each of those new points, in the order they were created.  Just one thought on the subject.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 8
Eide.N
in reply to: Eide.N

Thanks for the reply, I will add a file here for reference. 

This is currently one sketch in a part file. Both splines are on the same plane.

 

I would like to do this with code, because ideally, I'd like to create more than one line between the two.

 

I just found that there is a feature in Rhino (I don't use Rhino, nor do I have access to it) called TweenCurves and this is basically what I am looking for:

http://docs.mcneel.com/rhino/5/help/en-us/commands/tweencurves.htm

 

Your description of how to do this is spot on. This is above my current iLogic skill level so I'm hoping someone can give me some pointers! 

Message 4 of 8
WCrihfield
in reply to: Eide.N

I believe I have developed an iLogic rule solution or you.  I was not easy, and there were some unexpected bumps along the way, but I think I figured them out.

When the two splines were drawn in the same direction (for example, both were drawn left to right), I was getting the expected result.  But when one spline was drawn in the opposite direction (for example, one was drawn from left to right, while the other was drawn from right to left), it was giving me smaller, odd looking results.  It was because they have start point and end point properties, and because of the way I'm gathering points from along both splines for creating the center points between them.  If the two splines are drawn in opposing directions, then the start point of one spline and the start point of the other spline are at opposite ends from each other, and the center point between them, was being created up in the middle between the two splines.

Anyways, here's when I've got that seems to be working for me.

Sub Main
	Dim oPDoc As PartDocument = ThisDoc.Document
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	Dim oTO As TransientObjects = ThisApplication.TransientObjects
	Dim oPts As ObjectCollection = oTO.CreateObjectCollection
	Dim oSketch As PlanarSketch = oPDef.Sketches.Item(1)
	Dim oSp1 As SketchSpline = oSketch.SketchSplines.Item(1)
	Dim oSp2 As SketchSpline = oSketch.SketchSplines.Item(2)
	Dim oSp1Geom As BSplineCurve2d = oSp1.Geometry
	Dim oSp2Geom As BSplineCurve2d = oSp2.Geometry
	
	'need to determine which direction to process each spline in comparison to the other
	'start point of one spline may be at other end of other spline, resulting in odd result
	'see if start point of one spline is closer to start point or end point of the other spline
	'then use that result to determine which direction to process points along other spline
	Dim oStPt1 As Point2d = oSp1.StartSketchPoint.Geometry
	Dim oStart2Start As Double = oStPt1.DistanceTo(oSp2.StartSketchPoint.Geometry)
	Dim oStart2End As Double = oStPt1.DistanceTo(oSp2.EndSketchPoint.Geometry)
	If oStart2Start < oStart2End Then
		'first spline start point is closer to start point of other spline than its end point (normal)
		'process points along both splines from start point to end point as normal
		NormalBisectorSpline(oSp1Geom, oSp2Geom, oPts)
	Else
		'first spline start point is closer to end point of other spline than its start point (opposing directions)
		'process points along first spline from start to end with the points along the other spline from end to start
		ReverseBisectorSpline(oSp1Geom, oSp2Geom, oPts)
	End If
	
	Dim oOutPutSpline As SketchSpline = oSketch.SketchSplines.Add(oPts, SplineFitMethodEnum.kSmoothSplineFit)
End Sub

Sub NormalBisectorSpline(oSpl1 As BSplineCurve2d, oSpl2 As BSplineCurve2d, ByRef oCol As ObjectCollection)
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oParams(0) As Double
	oParams(0) = 0
	While oParams(0) <= 1
		Dim oPt1Coords(1) As Double
		Dim oPt2Coords(1) As Double
		oSpl1.Evaluator.GetPointAtParam(oParams, oPt1Coords)
		Dim oPt1 As Point2d = oTG.CreatePoint2d(oPt1Coords(0),oPt1Coords(1))
		oSpl2.Evaluator.GetPointAtParam(oParams, oPt2Coords)
		Dim oPt2 As Point2d = oTG.CreatePoint2d(oPt2Coords(0),oPt2Coords(1))
		GetAddCPoint(oPt1, oPt2, oCol)
		oParams(0) = (oParams(0) + 0.01)
	End While
End Sub

Sub ReverseBisectorSpline(oSpl1 As BSplineCurve2d, oSpl2 As BSplineCurve2d, ByRef oCol As ObjectCollection)
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oParams1(0) As Double
	oParams1(0) = 0
	Dim oParams2(0) As Double
	oParams2(0) = 1
	For i As Integer = 0 To 100
		Dim oPt1Coords(1) As Double
		oSpl1.Evaluator.GetPointAtParam(oParams1, oPt1Coords)
		Dim oPt1 As Point2d = oTG.CreatePoint2d(oPt1Coords(0), oPt1Coords(1))
		oParams1(0) = (oParams1(0) + 0.01)
		
		Dim oPt2Coords(1) As Double
		oSpl2.Evaluator.GetPointAtParam(oParams2, oPt2Coords)
		Dim oPt2 As Point2d = oTG.CreatePoint2d(oPt2Coords(0), oPt2Coords(1))
		oParams2(0) = (oParams2(0) -0.01)
		
		GetAddCPoint(oPt1, oPt2, oCol)
	Next
End Sub

Sub GetAddCPoint(oPnt1 As Point2d, oPnt2 As Point2d, ByRef oPnts As ObjectCollection)
	Dim oPnt3 As Point2d = oPnt1.Copy
	Dim oVec2d As Vector2d = oPnt1.VectorTo(oPnt2).Copy
	oVec2d.ScaleBy(0.5)
	oPnt3.TranslateBy(oVec2d)
	oPnts.Add(oPnt3)
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8
Eide.N
in reply to: Eide.N

Whoa! Can't wait to try it! I'll let you know in a few...

Message 6 of 8
Eide.N
in reply to: Eide.N

Sorry, I must be missing something. How did you set up your part file?

I made a Part file, with a 2D sketch, with two splines.

 

It's tripping an error right away (parameter is incorrect) on this line:

Dim oSp1 As SketchSpline = oSketch.SketchSplines.Item(1)

 

Message 7 of 8
WCrihfield
in reply to: Eide.N

Sorry for the delay in responding.  I've been away from work since the day of my last post, for COVID related reasons.  I too just created a new (empty) part, then created a 2D sketch, then used the 'Spline Interpolation' sketch tool to freehand draw two somewhat similar splines with a gap between them.  Then wrote this code and ran it, and it worked (after some trial/error).  The code doesn't include much in the way of error checking, so it is not very forgiving.

 

I originally created this as a 'local' rule, so the term 'ThisDoc' is getting the 'local' part document.  The code just attempts to get the first sketch in the part (the only sketch in my part), but you can change which sketch it is pointing to if needed.  My sketch only had the two splines in it, and nothing else.  I'm currently using Inventor Pro 2021.2.2, but I'm not sure if anything within the code wouldn't work with an earlier version of Inventor.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8
Eide.N
in reply to: Eide.N

@WCrihfield , no worries! I hope you have recovered well (or are well rested!) after your time away. These are crazy times, indeed!

 

I'll try it again as a local rule (and I'm currently running this on 2019, but I don't think that should matter too much).

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report