Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations LittleInch on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Points at the maximum distance between 2 splines

Status
Not open for further replies.

DannyRiding

Aerospace
Joined
Aug 28, 2013
Messages
2
Location
GB
I am trying to generate points at the maximum distance between 2 splines, my only solution is to go into the deviation checking tool and find the maximum point between 2 curves.

This generates XYZ co-ordinates for the source curve which I can then input into the point command to create a point in space. I then have to go through this process again but reverse the selection between the curves.
This would be OK if I was doing it for one set of curves but when I have to create points for hundreds of sections this can get a bit laborious!

Surely this isn't the only solution, is there a simpler method that I have completely missed or has someone created a grip for this?
 
What version of NX are you running? Could you at least show us an image of what these two splines look like and how they are arranged relative to each other (or better yet, the actual part file)?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
Here is a basic journal for creating points between two splines. Currently it has two limitation in that I have not checked spline direction. That is the journal will only work for splines which are in the same direction. It is also necessary that the splines are relatively simple. For example if for one of my solution point there is more than one normal to either spline I may have an incorrect maximum point.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF

Module PointsBetweenSplines
    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = s.Parts.Work
    Sub Main()
        Dim spline1 As NXOpen.Tag = NXOpen.Tag.Null
        Dim spline2 As NXOpen.Tag = NXOpen.Tag.Null
        Dim response1 As NXOpen.Selection.Response = Selection.Response.Cancel
        Dim response2 As NXOpen.Selection.Response = Selection.Response.Cancel
        Dim title1 As String = "Select Spline 1"
        Dim title2 As String = "Select Spline 2"
start1:
        response1 = select_spline(spline1, title1)
        If response1 = Selection.Response.Cancel Then Exit Sub
        If response1 = Selection.Response.Back Then Exit Sub
        response2 = select_spline(spline2, title2)
        If response2 = Selection.Response.Cancel Then Exit Sub
        If response2 = Selection.Response.Back Then GoTo start1
        Dim junk3(2) As Double
        Dim junk As Double
        Dim point() As Double = {0.0, 0.0, 0.0}
        Dim point1() As Double = {0.0, 0.0, 0.0}
        Dim point2() As Double = {0.0, 0.0, 0.0}
        Dim vec1(2), vec2(2), vec3(2), vec4(2) As Double
        Dim unitv0(2), unitv1(2), unitv2(2), unitv3(2), unitv4(2) As Double
        Dim point3(2), point4(2), point5(2) As Double
        Dim parm, parm1, parm2 As Double
        Dim l0, l1, l2, del1, del2 As Double
        Dim tempTag As NXOpen.Tag = NXOpen.Tag.Null
        For i As Integer = 0 To 50
            parm = i / 50.0
            ufs.Modl.AskCurveProps(spline1, parm, point1, vec1, junk3, junk3, junk, junk)
            ufs.Modl.AskCurveProps(spline2, parm, point2, vec2, junk3, junk3, junk, junk)
            ufs.Vec3.Sub(point1, point2, vec3)
            ufs.Vec3.Unitize(vec3, 0.001, l0, unitv1)
            l0 /= 2.0
            point3(0) = (point1(0) + point2(0)) / 2.0
            point3(1) = (point1(1) + point2(1)) / 2.0
            point3(2) = (point1(2) + point2(2)) / 2.0
            ufs.Modl.AskCurveParm(spline1, point3, parm1, point4)
            If parm1 < 0 Or parm1 > 1 Then Continue For
            ufs.Vec3.Distance(point3, point4, l1)
            ufs.Modl.AskCurveParm(spline2, point3, parm2, point5)
            If parm2 < 0 Or parm2 > 1 Then Continue For
            ufs.Vec3.Distance(point3, point5, l2)
            del1 = l1 - l2
            del2 = Math.Abs(del1)
            Dim cnt1 As Integer = 0
            While del2 > 0.001
                l0 = l0 + del1 / 2.0
                ufs.Vec3.AffineComb(point2, l0, unitv1, point3)
                ufs.Modl.AskCurveParm(spline1, point3, parm1, point4)
                If parm1 < 0 Or parm1 > 1 Then Continue For
                ufs.Modl.AskCurveParm(spline2, point3, parm2, point5)
                If parm2 < 0 Or parm2 > 1 Then Continue For
                ufs.Vec3.Distance(point3, point4, l1)
                ufs.Modl.AskCurveParm(spline2, point3, parm2, point5)
                If parm2 < 0 Or parm2 > 1 Then Continue For
                ufs.Vec3.Distance(point3, point5, l2)
                del1 = l1 - l2
                del2 = Math.Abs(del1)
                cnt1 += 1
                If cnt1 > 10 Then
                    MsgBox("Not converging")
                    Exit While
                End If
            End While
            ufs.Curve.CreatePoint(point3, tempTag)
        Next
        ufs.Disp.SetHighlight(spline1, 0)
        ufs.Disp.SetHighlight(spline2, 0)
    End Sub

    Function select_spline(ByRef spline As NXOpen.Tag, ByVal title As String) _
                                                   As Selection.Response
        Dim mssg As String = "Mid Points:"
        Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
        Dim response As Integer
        Dim view As NXOpen.Tag
        Dim cursor(2) As Double
        Dim mask_splines As UFUi.SelInitFnT = AddressOf mask_for_splines
        ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        Try
            ufs.Ui.SelectWithSingleDialog(mssg, title, scope, mask_splines, _
                                      Nothing, response, spline, cursor, view)
        Finally
            ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        End Try
        If response <> UFConstants.UF_UI_OBJECT_SELECTED And _
           response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
            Return Selection.Response.Cancel
        ElseIf response = Selection.Response.Back Then
            Return Selection.Response.Back
        Else
            Return Selection.Response.Ok
        End If

    End Function

    Function mask_for_splines(ByVal select_ As IntPtr, _
                           ByVal userdata As IntPtr) As Integer
        Dim num_triples As Integer = 1
        Dim mask_triples(0) As UFUi.Mask
        mask_triples(0).object_type = UFConstants.UF_spline_type
        mask_triples(0).object_subtype = UFConstants.UF_spline_subtype
        mask_triples(0).solid_type = 0
        ufs.Ui.SetSelMask(select_, _
                           UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
                           num_triples, mask_triples)
        Return UFConstants.UF_UI_SEL_SUCCESS
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function
End Module

Frank Swinkels
 
I am running in NX7.5. The splines in question are intersection curves either side of an aerofoil, intersections created using XY planes at different Z heights.
 
I'm not sure i understand what's desired here but, There is an option under results display - Create line, whose endpoints should be equivalent to the desired ?

Regards,
Tomas
 
If these intersection curves were derived from a true airfoil shape then it's probably safe to assume that they are each curved in a single direction, that is, there are no inflection points. If this is the case then the following procedure should work to find the maximum 'thickness' of your airfoil at each 'station' (the plane in which the intersection curves were created) along the 'Z' axis:

For each pair of intersection curves, create a sketch on the same plane as the curves and in the sketch draw two lines which are constrained to be horizonal and then constrain each line to be tangent to one of the two intersection curves (note that the intrsection curves do NOT have to be added to the sketch as long as they lay in the same plane as the sketch). Then create a line between the end points of one end of each line and constrain this line to be vertical. Once you leave the sketch this line can be measured and its length captured as an expression which will represent the 'thickness' of your airfoil at that particular 'station'. If the intersection curves were created as associative curves, then when you edit your original airfoil surfaces the various 'thickness' values for each pair of curves will update automatically.

To see how this would work see the attached file showing what one of those sketches would look like and how it would be constrained.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
 http://files.engineering.com/getfile.aspx?folder=6568c30a-1087-4543-b0c7-ef3068bd5641&file=airfoil_section_sketch_example-JRB-1.prt
If you are interested in a journal for this then I still need some further info. Is the maximum section determined by a normal to a camber line or a chord line? Or as it seemed to me you you were taking normals from each of the airfoil curves and then getting a maximum. Determining a maximum is possible for each of the three however they would give different results and therefore I would need some clarification.

Frank Swinkels
 
Here is a journal to work out maximum distance between the splines using normals to the splines. It is still limited to the splines having both been created from nose to tail or vise versa. I have created three points to show the final lines on which the maximum is based.

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.UF

Module MaximumDistanceSplines
    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = s.Parts.Work
    Dim lw As ListingWindow = s.ListingWindow
    Sub Main()
        Dim spline1 As NXOpen.Tag = NXOpen.Tag.Null
        Dim spline2 As NXOpen.Tag = NXOpen.Tag.Null
        Dim response1 As NXOpen.Selection.Response = Selection.Response.Cancel
        Dim response2 As NXOpen.Selection.Response = Selection.Response.Cancel
        Dim title1 As String = "Select Spline 1"
        Dim title2 As String = "Select Spline 2"
start1:
        response1 = select_spline(spline1, title1)
        If response1 = Selection.Response.Cancel Then Exit Sub
        If response1 = Selection.Response.Back Then Exit Sub
        response2 = select_spline(spline2, title2)
        If response2 = Selection.Response.Cancel Then Exit Sub
        If response2 = Selection.Response.Back Then GoTo start1

        Dim lowerparm As Double = 0.0
        Dim upperparm As Double = 1.0
        Dim lowerdistance As Double = 0.0
        Dim upperdistance As Double = 0.0
        Dim middistance As Double = 0.0
        Dim cnt2 As Integer = 0

        Dim pt1(2), pt2(2), pt3(2) As Double

        ' first iteration
        determineNewLimits(spline1, spline2, lowerparm, upperparm, lowerdistance, middistance, upperdistance, pt1, pt2, pt3)
        Dim testdel As Double = Math.Abs((lowerdistance + upperdistance) / 2.0 - middistance)
        While testdel > 0.0001
            determineNewLimits(spline1, spline2, lowerparm, upperparm, lowerdistance, middistance, upperdistance, pt1, pt2, pt3)
            testdel = Math.Abs((lowerdistance + upperdistance) / 2.0 - middistance)
            cnt2 += 1
            If cnt2 > 10 Then Exit While
        End While
        ' create the points 
        Dim temptag As Tag = NXOpen.Tag.Null
        ufs.Curve.CreatePoint(pt1, temptag)
        ufs.Curve.CreatePoint(pt2, temptag)
        ufs.Curve.CreatePoint(pt3, temptag)
    End Sub

    Sub determineNewLimits(ByVal spline1 As Tag, ByVal spline2 As Tag, ByRef lowerparm As Double, ByRef upperparm As Double, _
                           ByRef lowerdistance As Double, ByRef middistance As Double, ByRef upperdistance As Double, _
                           ByRef point3() As Double, ByRef point4() As Double, ByRef point5() As Double)
        Dim junk3(2) As Double
        Dim junk As Double
        Dim vec1(2), vec2(2), vec3(2), vec4(2) As Double
        Dim unitv0(2), unitv1(2), unitv2(2), unitv3(2), unitv4(2) As Double
        Dim point1(2), point2(2) As Double
        Dim parm1, parm2 As Double
        Dim l0, l1, l2, del1, del2 As Double
        Dim distances1(10) As Double
        Dim parms1(10) As Double
        Dim parms2(10) As Double
        Dim cnt1 As Integer = 0
        Dim delparm As Double = (upperparm - lowerparm) / 10.0
        For parm As Double = lowerparm + delparm To upperparm - delparm Step delparm

            cnt1 += 1
            ufs.Modl.AskCurveProps(spline1, parm, point1, vec1, junk3, junk3, junk, junk)
            ufs.Modl.AskCurveProps(spline2, parm, point2, vec2, junk3, junk3, junk, junk)
            ufs.Vec3.Sub(point1, point2, vec3)
            ufs.Vec3.Unitize(vec3, 0.001, l0, unitv1)
            l0 /= 2.0
            point3(0) = (point1(0) + point2(0)) / 2.0
            point3(1) = (point1(1) + point2(1)) / 2.0
            point3(2) = (point1(2) + point2(2)) / 2.0
            ufs.Modl.AskCurveParm(spline1, point3, parm1, point4)
            If parm1 < 0 Or parm1 > 1 Then Continue For
            ufs.Vec3.Distance(point3, point4, l1)
            ufs.Modl.AskCurveParm(spline2, point3, parm2, point5)
            If parm2 < 0 Or parm2 > 1 Then Continue For
            ufs.Vec3.Distance(point3, point5, l2)
            del1 = l1 - l2
            del2 = Math.Abs(del1)
            Dim cnt2 As Integer = 0
            While del2 > 0.001
                l0 = l0 + del1 / 2.0
                ufs.Vec3.AffineComb(point2, l0, unitv1, point3)
                ufs.Modl.AskCurveParm(spline1, point3, parm1, point4)
                If parm1 < 0 Or parm1 > 1 Then Continue For
                ufs.Modl.AskCurveParm(spline2, point3, parm2, point5)
                If parm2 < 0 Or parm2 > 1 Then Continue For
                ufs.Vec3.Distance(point3, point4, l1)
                ufs.Modl.AskCurveParm(spline2, point3, parm2, point5)
                If parm2 < 0 Or parm2 > 1 Then Continue For
                ufs.Vec3.Distance(point3, point5, l2)
                del1 = l1 - l2
                del2 = Math.Abs(del1)
                cnt2 += 1
                If cnt2 > 10 Then
                    MsgBox("Not converging")
                    Exit Sub
                End If
            End While
            distances1(cnt1) = l1 + l2
            parms1(cnt1) = parm1
            parms2(cnt1) = parm2
        Next
        ufs.Disp.SetHighlight(spline1, 0)
        ufs.Disp.SetHighlight(spline2, 0)
        distances1(0) = lowerparm
        distances1(10) = upperparm

        For i As Integer = 2 To 8
            If distances1(i - 2) < distances1(i - 1) And distances1(i - 1) > distances1(i) Then
                lowerparm = lowerparm + delparm * (i - 2)
                upperparm = lowerparm + delparm * i
                lowerdistance = distances1(i - 2)
                middistance = distances1(i - 1)
                upperdistance = distances1(i)
                Exit For
            End If
        Next

    End Sub

    Function select_spline(ByRef spline As NXOpen.Tag, ByVal title As String) _
                                                   As Selection.Response
        Dim mssg As String = "Mid Points:"
        Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
        Dim response As Integer
        Dim view As NXOpen.Tag
        Dim cursor(2) As Double
        Dim mask_splines As UFUi.SelInitFnT = AddressOf mask_for_splines
        ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        Try
            ufs.Ui.SelectWithSingleDialog(mssg, title, scope, mask_splines, _
                                      Nothing, response, spline, cursor, view)
        Finally
            ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
        End Try
        If response <> UFConstants.UF_UI_OBJECT_SELECTED And _
           response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
            Return Selection.Response.Cancel
        ElseIf response = Selection.Response.Back Then
            Return Selection.Response.Back
        Else
            Return Selection.Response.Ok
        End If

    End Function

    Function mask_for_splines(ByVal select_ As IntPtr, _
                           ByVal userdata As IntPtr) As Integer
        Dim num_triples As Integer = 1
        Dim mask_triples(0) As UFUi.Mask
        mask_triples(0).object_type = UFConstants.UF_spline_type
        mask_triples(0).object_subtype = UFConstants.UF_spline_subtype
        mask_triples(0).solid_type = 0
        ufs.Ui.SetSelMask(select_, _
                           UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
                           num_triples, mask_triples)
        Return UFConstants.UF_UI_SEL_SUCCESS
    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function
End Module

Regards

Frank Swinkels
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top