cancel
Showing results for 
Search instead for 
Did you mean: 

Finding intersection point of two curves..

Pioneer
Pioneer

Hi All,

I have ploted a graph in NX9. Is there any suitable way to find all the  exact intersection points programatically.

4 REPLIES

Re: Finding intersection point of two curves..

Phenom
Phenom

Not sure how to do it using native NXOpen.

However, you can use the NXOpen wrapper for UF_CURVE_intersect().

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Finding intersection point of two curves..

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Here is an example from our GTAC examples in the Solution Center.  This creates a named point at each intersection, but you could modify it to just report the locations, rather than creating the points.

 


'
' This tries to intersect each curve in the current part
' with each other curve in the current part.  It will create
' a named point where it finds an intersection.
'
' Note that as the number of curves in the part increases, the
' time required may increase at a much greater rate.
'
' IMPORTANT NOTE: this works only as long as any given curve
' will only intersect any other curve one time.
'
' If curves could have multiple intersections,
' then you will need to use Open C and call
' UF_MODL_intersect_objects(), which is not
' wrapped for use in the .Net toolkits.
'
' First tested: NX7.5

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module create_named_point_at_each_curve_intersection

    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = s.ListingWindow

    Sub Main()

        Dim dp As Part = s.Parts.Display
        Dim wp As Part = s.Parts.Work
        Dim bp As BasePart = CType(wp, BasePart)
        Dim pc As PointCollection = bp.Points
        Dim pointCounter As Integer = 1

        Dim allCurves() As Curve = wp.Curves.ToArray()
        Dim curveCount As Integer = allCurves.GetUpperBound(0)

        If curveCount < 1 Then
            lw.Open()
            lw.WriteLine("Run this in a part with at least two curves.")
        End If

        Dim copiedCurves(curveCount)
        Array.Copy(allCurves, copiedCurves, curveCount + 1)
        Array.Reverse(copiedCurves)
        ReDim Preserve copiedCurves(curveCount - 1)

        ' Turn on object name display
        dp.Preferences.NamesBorderVisualization.ObjectNameDisplay = _
            Preferences.PartVisualizationNamesBorders.NameDisplay.WorkView

        For Each thisCurve As Curve In allCurves

            For Each otherCurve As Curve In copiedCurves
                Try
                    Dim i1 As IBaseCurve = CType(thisCurve, IBaseCurve)
                    Dim i2 As IBaseCurve = CType(otherCurve, IBaseCurve)

                    Dim h1 As Point = Nothing
                    Dim h2 As Point = Nothing
                    Dim PT As Point = pc.CreatePoint(i1, i2, h1, h2, _
                                SmartObject.UpdateOption.WithinModeling)
                    PT.SetVisibility(SmartObject.VisibilityOption.Visible)
                    PT.SetName("Int_Pt_" & pointCounter.ToString())
                    pointCounter += 1

                Catch ex As Exception
                    'don't do anything - not all curves intersect!
                End Try

            Next

            If (copiedCurves.GetUpperBound(0) > 0) Then
                ReDim Preserve copiedCurves(copiedCurves.GetUpperBound(0) - 1)
            End If

        Next
        pointCounter -= 1
        MsgBox("Created " & pointCounter.ToString() & _
               " points.", MsgBoxStyle.Information)
        Dim undoMark As Session.UndoMarkId = _
            s.SetUndoMark(Session.MarkVisibility.Visible, "UpdateMark")
        s.UpdateManager.DoUpdate(undoMark)

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        Return Session.LibraryUnloadOption.Immediately

    End Function

End Module

Re: Finding intersection point of two curves..

Phenom
Phenom
I'd never have looked at creating a point when all I want is the coordinates of the intersection.
Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Finding intersection point of two curves..

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Hi Graham,

 

Right - I just thought that the example would be helpful to demonstrate one method of processing a set of curves to find the intersections.  Tweaking it for a slightly different purpose is "an exercise left for the reader".

 

8-)

 

Steve