cancel
Showing results for 
Search instead for 
Did you mean: 

Extract Y coordinate if X coordinate is known from a 2D spline

Creator
Creator

I have a 2D spline in  XY plane. How do I extract one coordinate if the other is known using UFUNC or NXOPEN? Currently I am constructing a plane parallel to XY plane at known X and using intersection of the curve with that plane to get the point. Is there a direct way? Something which utilizes the equation of spline directly.  

8 REPLIES

Re: Extract Y coordinate if X coordinate is known from a 2D spline

Esteemed Contributor
Esteemed Contributor

Note in a general case, there may also be 0 or (more than 1) intersection point.

If you don't KNOW the spline characteristics, you may want to check for these cases as well.

 

Offhand, other than walking the spline's parameter (to find the "U" value where the point on the spline at that U is the desired X), I don't know of a better way than you are doing.

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Extract Y coordinate if X coordinate is known from a 2D spline

Siemens Phenom Siemens Phenom
Siemens Phenom

Intersection is the only way to do this. To find the y value at x=k, you can either intersect the spline with the line x=k, or intersect with the plane x=k.

 

You can get the equation of the spline in the form x = x(t) y = y(t), and use numerical methods to solve the equation x(t) = k. But, in effect, you'd just be re-implementing NX's intersection function.

山田
yamada

Re: Extract Y coordinate if X coordinate is known from a 2D spline

Creator
Creator

How can we get those equations?

Re: Extract Y coordinate if X coordinate is known from a 2D spline

Valued Contributor
Valued Contributor

Have you tried getting the coordinates of spline in this way?

 

Dim MyPoint As Point4d = MySpline.GetPoles(i)

 

where i is the no of poles the spline is having.

 

Regards,

Abhi

 

Re: Extract Y coordinate if X coordinate is known from a 2D spline

Siemens Phenom Siemens Phenom
Siemens Phenom

An NX spline is just a standard NURBS (Non-uniform Rational B-Spline). You can find the equation in many places on the 'net. One example is this Wikipedia page.

 

The equation involves

  • 3D control points (poles). There are n of these.
  • Weight values, one for each pole, so there are n of these.
  • An order value, k. If the degree of the curve is m, then k = m+1.
  • Knot values. There are n+k of these

You can get all of the above data by calling NX/Open functions.

 

But, again, once you have the equation, you still have to do an intersection calculation to get the y corresponding to a given x. Better to use the NX intersection algorithm, rather than one you write yourself.

 

 

山田
yamada

Re: Extract Y coordinate if X coordinate is known from a 2D spline

Creator
Creator

Constructing a plane and getting intersection pf the curve for now. Wondering if there is a way to avoid actual construction of plane. Something like trace a ray, or project a point to curve. But unfortunately, for those functions, traget is a face/body. None of them accept curve as a traget.

Re: Extract Y coordinate if X coordinate is known from a 2D spline

Siemens Phenom Siemens Phenom
Siemens Phenom

If you have a SNAP license, then you can use Snap.Compute.Intersect(curve, plane).

 

Here, the plane is a Snap.Geom.Surface.Plane object, so it's just a transient object in your code, not a real NX plane. So, creating it takes no time at all, and you don't have to delete it after you're done.

 

Here's an example program from the SNAP Reference Guide

 

Imports Snap, Snap.Create

Public Class MyProgram

   Public Shared Sub Main()

      ' Create a spline with many wiggles
      Dim points(10) As Position
      For i As Integer = 0 to 10
         points(i) = New Position(i, (10.0*(-1)^i)/(i+5), 0)
      Next

      Dim wiggle As NX.Spline = SplineThroughPoints(points, 3)

      Dim top As New Geom.Surface.Plane( {0,1,0}, 1)

      ' Get intersections between the spline and the plane
      Dim intPoints As Position() = Compute.Intersect(wiggle, top)

      ' Output the intersection points
      For Each pt As Position in intPoints
         InfoWindow.WriteLine(pt.ToString("F6"))
         Point(pt)
      Next

   End Sub

End Class

' Results: The output in the NX Information window are ...
'     ( 0.053355 , 1.000000 , 0.000000 )
'     ( 1.566558 , 1.000000 , 0.000000 )
'     ( 2.161501 , 1.000000 , 0.000000 )
'     ( 3.798708 , 1.000000 , 0.000000 )
'     ( 4.093433 , 1.000000 , 0.000000 )

 

Actually, creating a "real" plane isn't all that bad. If you delete the plane after you're done, it will cause an Update, and your performance will suffer. But there are two ways to reduce this problem.

 

(1) Save all the planes you create, and delete them all at once. That way, you only have to endure one Update, or

 

(2) Set a mark before you start creating planes, and then Undo to that mark after you're done. The Undo will be much faster than an Update. In fact, in general, this is a very useful technique in lots of situations, so it's a good idea to learn how to do it.

山田
yamada

Re: Extract Y coordinate if X coordinate is known from a 2D spline

Creator
Creator

Thanks for the reply. But I cannot use SNAP. Is there NXOpen for the same ? Anyway I didnt know UNDO was a better option than delete. I will try that.