Author Topic: Closed spline with no tangency?  (Read 2777 times)

0 Members and 1 Guest are viewing this topic.

zoltan

  • Guest
Closed spline with no tangency?
« on: August 08, 2008, 04:12:26 PM »
When you use the SPLINE command to draw a spline, after you pick the last point and hit enter, it asks for a tangent direction at the start and end.  You can hit enter instead of picking a direction to have the start and end progress smoothly to the next point.  When you are pick a number of points and use the close option, you are prompted to pick a single tangent direction for the point that closes the spline, if you hit enter here, you end up with a smooth ring that progresses point to point.

When I use the VLA-AddSpline function it asks for an array of points and a start and end tangent.  If I give it the last point same as the first, it knows that it is a closed spline, but I don't know what to tell the tangent points to make the ring smooth.  I have tried to make them both 0,0,0 and I get a pointy corner at the vertex that is the start/end.

I have tried to use EntMake, since the 12 and 13 DXF codes for the start and end tangents are optional, it sometimes does and sometimes doesn't make a pointy vertex.

How do I make a smooth spline that forms a closed ring with no kinks?

Zoltan

Joe Burke

  • Guest
Re: Closed spline with no tangency?
« Reply #1 on: August 09, 2008, 08:37:26 AM »
This may help?

Code: [Select]
(defun c:test ( / *mspace* p pts spline)
  (setq *mspace*
    (vla-get-ModelSpace
      (vla-get-ActiveDocument
        (vlax-get-acad-object)
      )
    )
  )
  (setq p (getpoint "\nPick point: "))
  (while (setq p (getpoint p "\nPick point: ")) (setq pts (cons p pts)))
  (setq pts (append pts (list (car pts))))
  (setq spline
    (vlax-invoke *mspace* 'AddSpline (apply 'append pts)
      '(0.0 0.0 0.0) '(0.0 0.0 0.0)
    )
  )
  (setq fd (vlax-curve-getFirstDeriv spline 0))
  (vlax-put spline 'StartTangent fd)
  (vlax-put spline 'EndTangent fd)
  (princ)
)

Spike Wilbury

  • Guest
Re: Closed spline with no tangency?
« Reply #2 on: August 09, 2008, 03:52:15 PM »
This may help?

Code: [Select]
(defun c:test ( / *mspace* p pts spline)
  (setq *mspace*
    (vla-get-ModelSpace
      (vla-get-ActiveDocument
        (vlax-get-acad-object)
      )
    )
  )
  (setq p (getpoint "\nPick point: "))
  (while (setq p (getpoint p "\nPick point: ")) (setq pts (cons p pts)))
  (setq pts (append pts (list (car pts))))
  (setq spline
    (vlax-invoke *mspace* 'AddSpline (apply 'append pts)
      '(0.0 0.0 0.0) '(0.0 0.0 0.0)
    )
  )
  (setq fd (vlax-curve-getFirstDeriv spline 0))
  (vlax-put spline 'StartTangent fd)
  (vlax-put spline 'EndTangent fd)
  (princ)
)

Gracias Joe!

That's what I miss from this language, very few lines, straight forward and simple.
« Last Edit: August 14, 2008, 01:28:42 PM by LE »

Joe Burke

  • Guest
Re: Closed spline with no tangency?
« Reply #3 on: August 09, 2008, 08:48:45 PM »
Hola Luis,

You're welcome.

BTW, the first derivative only needs to be applied to the EndTangent, not both. Duh...

Joe Burke

  • Guest
Re: Closed spline with no tangency?
« Reply #4 on: August 09, 2008, 09:24:28 PM »
Check that. The code is correct as is. The start and end tangents should be the same. If not reshaping the spline at the first fit point doesn't work right.

zoltan

  • Guest
Re: Closed spline with no tangency?
« Reply #5 on: August 13, 2008, 06:31:51 PM »
This may help?

Code: [Select]
(defun c:test ( / *mspace* p pts spline)
  (setq *mspace*
    (vla-get-ModelSpace
      (vla-get-ActiveDocument
        (vlax-get-acad-object)
      )
    )
  )
  (setq p (getpoint "\nPick point: "))
  (while (setq p (getpoint p "\nPick point: ")) (setq pts (cons p pts)))
  (setq pts (append pts (list (car pts))))
  (setq spline
    (vlax-invoke *mspace* 'AddSpline (apply 'append pts)
      '(0.0 0.0 0.0) '(0.0 0.0 0.0)
    )
  )
  (setq fd (vlax-curve-getFirstDeriv spline 0))
  (vlax-put spline 'StartTangent fd)
  (vlax-put spline 'EndTangent fd)
  (princ)
)

That does make the spline smooth, but if you start with the spline that has a kink because of the 0.0 0.0 0.0 at the start point and copy that tangency to the end point, then the spline comes into the point and leaves at the same tangency, but it comes in at the wrong tangency that would make the spline progress around the circle of points naturally.  The spline comes in at a tangent that is kicked out a little bit. 

But you gave me an idea!  If I create a spline that goes from the last point to the first then to the second point and take the take the tangency from the first point and apply it to the tangency of the start and end point of the ring, then the ring should progress smoothly as it didn't matter which point was first.

Let me try that and get back to you.

zoltan

  • Guest
Re: Closed spline with no tangency?
« Reply #6 on: August 13, 2008, 06:42:44 PM »
That seems to work!!

something line this:
Code: [Select]
(SetQ oSpline (VLA-AddSpline
                (ZF_Get-ModelSpace)
                (DList->SafeArray (Apply (Function Append) (List (Last lstPOINTS) (Car lstPOINTS) (Cadr lstPOINTS))) )
                (VLAX-3D-Point 0.0 0.0 0.0 )
                (VLAX-3D-Point 0.0 0.0 0.0 )
               )
 )
 
 (SetQ pntDeriv (VLAX-Curve-GetFirstDeriv oSpline (VLAX-Curve-GetParamAtPoint oSpline (Car lstPOINTS))) )

 (Cons_Erase oSpline )

 (SetQ oSpline (VLA-AddSpline
                (ZF_Get-ModelSpace)
                (DList->SafeArray (Append (Apply (Function Append) lstPOINTS) (Car lstPOINTS)) )
                (VLAX-3D-Point 0.0 0.0 0.0 )
                (VLAX-3D-Point 0.0 0.0 0.0 )
               )
 )
 (VLAX-Put oSpline 'StartTangent pntDeriv )
 (VLAX-Put oSpline 'EndTangent pntDeriv )

 (VLA-Update oSpline )


Thanks for all of the help! or at least the inspiration! ;-)

Joe Burke

  • Guest
Re: Closed spline with no tangency?
« Reply #7 on: August 14, 2008, 08:10:22 AM »
You're welcome.

The code I posted was only intended to demonstrate this idea.

  (setq fd (vlax-curve-getFirstDeriv spline 0))
  (vlax-put spline 'StartTangent fd)
  (vlax-put spline 'EndTangent fd)

I figured you would have to make some adjustments to work within your routne.

BTW, you don't need safearray and vlax-3D-point if you call the AddSpline method like this (vlax-invoke <modelspace> 'AddSpline...) as shown in my code. KISS.

zoltan

  • Guest
Re: Closed spline with no tangency?
« Reply #8 on: August 14, 2008, 01:08:11 PM »
BTW, you don't need safearray and vlax-3D-point if you call the AddSpline method like this (vlax-invoke <modelspace> 'AddSpline...) as shown in my code. KISS.

yea.. I noticed that.  Interesting.  I also noticed that there is no VLA-Put-StartTangent which is kind of odd.

The most interesting thing about all of this is that if you use the spline command to pick points around the ring and close it with the close option and then hit enter to give it default tangency at that point, the spline that results differs depending on where you start.

oh well.