Curvature display in AutoCAD?

Curvature display in AutoCAD?

Hrvoje-
Advocate Advocate
5,420 Views
21 Replies
Message 1 of 22

Curvature display in AutoCAD?

Hrvoje-
Advocate
Advocate

Hi!

Is it possible to display in AutoCAD the curvature of the line like in Fusion? Please, have a look at the enclosed picture.

Thank you for the help!

 

Slika_002.png

Kind regards,
Hrvoje 🙂
0 Likes
Accepted solutions (2)
5,421 Views
21 Replies
Replies (21)
Message 2 of 22

imadHabash
Mentor
Mentor

Hi,

>> Is it possible to display in AutoCAD the curvature of the line like in Fusion?

We don't know how the procedure in Fusion !!

Imad Habash

EESignature

0 Likes
Message 3 of 22

Hrvoje-
Advocate
Advocate
I can not see the picture under the text "Imad Habash (ACA, ACP)", the link is broken.
I mentioned Fusion just to illustrate what I want to see (and use) in AutoCAD. I suppose if the possibility to represent line curvature in Fusion exists, the same possibility could exist in AutoCAD. What do you think?
Kind regards,
Hrvoje 🙂
0 Likes
Message 4 of 22

Kent1Cooper
Consultant
Consultant

What in your image constitutes "display[ing] ... the curvature of the line"?  A Line [as an object type in AutoCAD] cannot have curvature, so you must be talking about a Spline or Polyline or something.  Is the red one the "line" you want to display the curvature of, and the blue one is somehow displaying its curvature?  Or the other way around?  What are the white and black dots?  Etc., etc.

Kent Cooper, AIA
0 Likes
Message 5 of 22

pendean
Community Legend
Community Legend
AutoCAD is not FUSION.

What have you tried in AutoCAD so far? Show your work.
0 Likes
Message 6 of 22

Hrvoje-
Advocate
Advocate

Thank you for answering my question. English is not my native language, and part of the problem is just this.

 

In my work, I am using spline and consequently, I am talking about spline. Please, forgive my bad use of the term.

 

When control points define a spline, it should be smooth without breaks or sharp bends. This is best seen when the curve/spline is accompanied by a graphical representation of the curvature at each point. And this is what I need.

This is my hobby work, the superstructure of a tug boat model.

 

Pendean - And, yes, I know: Fusion is not AutoCAD.

 

Slika_007.png

Kind regards,
Hrvoje 🙂
0 Likes
Message 7 of 22

Hrvoje-
Advocate
Advocate

Is the red one the "line" you want to display the curvature of, and the blue one is somehow displaying its curvature? Or the other way around? What are the white and black dots? Etc., etc.

 

@Kent1Cooperhere is the answer on your question:

 

Slika_008.png

A white point is also a fit point.

Kind regards,
Hrvoje 🙂
0 Likes
Message 8 of 22

Kent1Cooper
Consultant
Consultant

@Hrvoje- wrote:

... when the curve/spline is accompanied by a graphical representation of the curvature at each point. ....


An I correct that the "graphical representation" is that where the curvature is greater, that is, where the tested path [blue] is farther from being straight, the distance of the red path from the blue one is greater?  In other words, the red path gets farther from the blue one where the blue one curves more sharply?  If so, AutoCAD doesn't have any way to do that, as far as I know.

 

It may be possible to create something that would do that, with some criteria.  Would it work to have a "rung" springing off the tested path at regular intervals?  [It doesn't look like they're spaced regularly along either path in your image.]  Is there a standard number of test points or spacing between them, or should the User be asked how many, or how far apart?  What determines how far off the tested path the graphic-representation path should be for a given degree of curvature?  Etc.

Kent Cooper, AIA
0 Likes
Message 9 of 22

Hrvoje-
Advocate
Advocate

There is a popup window with adjustable parameters:

 

Slika_010.png

Kind regards,
Hrvoje 🙂
0 Likes
Message 10 of 22

leeminardi
Mentor
Mentor

@Kent1Cooper "Curvature" is a measure of flatness.  A straight line has a curvature of zero.  The instantaneous radius of curvature is the inverse of curvature.  Where a line has no curvature its instantaneous radius of curvature is infinite whereas its curvature is zero. 

 

In the Fusion graphic for curvature the spline  (blue curve) is straight where the red line crosses it. The magnitude of the blue lines radiating from the spline indicate curvature magnitude. The side to which the red line resides indicates to which side the instantaneous center of is (the opposite side).

leeminardi_0-1660608008533.png

@Hrvoje- If you create a spline in AutoCAD with fit points the default spline is a degree 3 B-spline. It will have first and second derivative continuity throughout its length. If you create a spine using Control Vertices the default is also a degree 3 B-spline unless you place 2 CVs coincidently in which case you will lose second derivative continuity and if 3 CVs are coincident you will lose first derivative continuity.  In both of these cases the spline becomes a true NURBS (non-uniform rational B-Spline).  If you want to create a spline with a sharp corner place 3 CVs at the same position.  

 

I am unaware of any AutoCAD features to indicate curvature of a spline.  However, there are several tools for showing the curvature of a surface.  Go to the Surfaces panel and click Analysis Options or give the ANALYSISOPTIONS command.  I have found this tool awkward to use.

leeminardi_1-1660609072878.png

 

 

lee.minardi
0 Likes
Message 11 of 22

leeminardi
Mentor
Mentor
Accepted solution

To better ensure a smooth curve use as few CVs as possible.  As you increase the number of CVs (or fit points) you increase the likelihood of causing undulations (reversal of curvature) in the spline.  The curve you show (post #6) looks to have 18 CVs. It would be better to use 3 or 4.

lee.minardi
0 Likes
Message 12 of 22

Hrvoje-
Advocate
Advocate

Thank you so much @leeminardi for a detailed explanation.

Kind regards,
Hrvoje 🙂
0 Likes
Message 13 of 22

Hrvoje-
Advocate
Advocate

Yes, I will reduce the number of control points to obtain a smooth line. Also, I will do this through the entire drawing. Thank you for the advice. 🙂

Kind regards,
Hrvoje 🙂
0 Likes
Message 14 of 22

Kent1Cooper
Consultant
Consultant
Accepted solution

[Message 11 may be a very helpful suggestion deserving of a "Like," but it isn't a Solution.]

 

How about the attached [for Splines only -- see below] DegreeOfCurvature.lsp?  In both images the green and red are Splines, and the white is the result.

Its DOCL command [= Degree Of Curvature - Lines] does this:

Kent1Cooper_0-1660655405464.png

and its DOCS command [= Degree Of Curvature - Spline] does this, drawing another Spline along the same locations that were the off-the-path ends of the Lines under DOCL:

Kent1Cooper_1-1660655503094.png

It could be made to do both, similar to your images, but it would mean either two pull passes or putting all the other-end-of-Line points into a list for the Spline part, or something.  You can change the number 100 [in two places] for a different density, or it could be made to ask the User.  It lacks the usual enhancements, which can be added easily enough, if it does what you want otherwise.

 

It's for Splines, not Arcs or Polylines with arc segments.  The length of the second-derivative vector in those cases is the radius, so under DOCL, tighter curvature gets shorter Lines when they should be longer.

 

Working this out made me very aware that the (vlax-curve-getSecondDeriv) function in AutoLisp is badly named.  It doesn't return the real mathematical 2nd derivative, which would be just a number [higher for sharper curvature, lower for broader curvature, 0 where straight], with a positive or negative sign depending on the direction of curvature.  What it returns is an XYZ vector, which some in other topics suggest defines the perpendicular direction at the location on the path [the 1st derivative defines the tangent direction], but as you can see from the Lines drawn by DOCL using those returned vectors, they're not necessarily perpendicular.  It also returns (0 0 0) at the endpoints, which is not correct where there's curvature right to the end, so these results taper down to meet the ends, rather than having some offset there as in your images -- I hope it "tells the story" anyway, and there may be some way of compensating for that incorrect return.  And as mentioned above, for Arcs and Polyline arc segments, the length of the vector is simply the radius, so the relationship between the real 2nd derivative's size and the degree of curvature is reversed [it's greater for gentler curvature, smaller for tighter]:

Kent1Cooper_2-1660657140052.png

And the parameter numbering would need to be done differently for those.

 

In your illustration of an actual case, not very far from straight, it may be necessary to put a multiplier on the so-called 2nd-derivative vector, to make the graphic representation clearer.

Kent Cooper, AIA
0 Likes
Message 15 of 22

leeminardi
Mentor
Mentor

The DegreeOfCurvature is an interesting program but it is not clear that it provides accurate information about the curvature.  It is creating lines that are from points on the spline to a point defined by the 2nd derivative vector minus the position vector of the point.  The second derivative is not the curvature of the spline.  

For example, the red arc below is actually a spline with 3 CVs and the weight of the second CV set to 0.5. This yields a NURBS spline that exactly represents an arc. The DOCL lisp program generated the figure on the right. As I understand the program, the length of the green lines should indicate the magnitude of the curvature.  If so, they should all be the same length.  They are not.

leeminardi_0-1660701096227.png

 

Here’s an example of a spline with a discontinuity of the first (tangent) and second derivative approximately midway along its length. To the right is the result of DOCL and DOCS. What can be gleaned from the image is that the curvature flips but it’s less clear what is happening at the discontinuity point.

leeminardi_1-1660701096237.png

 

The radius of curvature at a point on a curve is the inverse of its curvature.  Here’s a good reference. As noted in the reference, for 2D curves described in Cartesian coordinates the radius of curvature is:

leeminardi_2-1660701096238.png

 

Note that it is a function of both the first and second derivatives.

For 3D parametric splines (such as the NURBS used in AutoCAD), the equation for radius of curvature becomes:

leeminardi_3-1660701096238.png

 

Just as a curve’s tangent (first derivative) is a vector and not just a number, so is its second derivative which is indicating not only the magnitude of the change in tangency but also the direction in which that change is happening particularly important with 3D splines.

 

I’ll admit that my knowledge of NURBS math is quite limited.  Perhaps @SEANT61 , or others, could jump in here and provide some clarification.

 

On a separate note, I always thought it was the OP who determined if a post was a solution.😉

 

lee.minardi
0 Likes
Message 16 of 22

SEANT61
Advisor
Advisor

It would be disappointing indeed if (vlax-curve-getSecondDeriv) returns a zero vector at the Spline’s Start-, End point. That should not be the result.


The way AutoCAD creates “Fit” splines, with AutoCAD generated Start- End Tangent, it is not surprising that the condition at the ends have no curvature - which is to say the curvature graph would be in contact with the endpoints, given inverse (1/Rad) offset. If the Fit Spline is converted to CV the first (or last) three CVs are often colinear.


The curvature value at a specific curve point is available through Managed/Native ARX via the PointOnCurve3d.GetCurvature Method, but might be unavailable through the COM interface. That notwithstanding, it’s functionality can be recreated. The linked Wikipedia article’s equation, while quite probably correct, is not the easiest to use with the vectors available via GetDerivative. The more straightforward formula would be:

Given:
Der1 = 1st Derivative
Der2 = 2nd Derivative
X = Cross Product

Then:
(Magnitude of Der1)^3 / Magnitude (Der1 X Der2)

 

Of course, this methodology would be incomplete if (vlax-curve-getSecondDeriv) returns a zero vector.


************************************************************
May your cursor always snap to the location intended.
0 Likes
Message 17 of 22

leeminardi
Mentor
Mentor

@SEANT61   Thank you for your response.  Using your formula for curvature I modified the DOCL program to draw lines that represent the magnitude and location of the radius of curvature along a spline.  The program works for 2D and 3D splines.   The cross product of the first derivative and second derivative vectors is used to create a unit vector (perp)  perpendicular to the tangent vector (der1).  The program also prints the magnitude of the curvature for each of the 100 evaluation points.

I think the results look very good!  Thank you for your help.

 

Some examples.

 

As expected, the curvature lines for a spline arc are all the same length and perpendicular to the spline tangents.

leeminardi_2-1660743832680.png

The inflection point of the spline is clear in this example.

leeminardi_1-1660743713284.png

 

In the following example there is a discontinuity of the first and second derivatives (sharp corner) as a result of having 3 coincident CVs. 

leeminardi_3-1660746278119.png

 

 

 

(defun C:DOCL (/ path inc n osm	par der1 der2 curva p perp normv p2 sf
	       curveType ans)
; = Degree Of Curvature - Lines
; Creates curvature lines or radius-of-curvature lines
; normal to a spline.
; LRM 8/18/2022 edited to place curvature vectors outside  
  (setq
    path (car (entsel))
    inc	 (/ (vlax-curve-getEndParam path) 100)
    n	 0
    osm	 (getvar 'osmode)
  )
  (setvar 'osmode 0)
  (setvar "cmdecho" 0)
  (initget "y n")
  (setq ans (getkword  "Do you want radius-of-curvature instead of curvature? [y/n] <n>: "))
	(if (= ans "y")
	   (setq curveType 1)
	   (setq curveType 2
		 sf	   (getdist "Enter scale factor.")
	   )
	)
  (repeat 100
    (setq par (* inc n))
    (setq der1 (vlax-curve-getfirstDeriv path par)
	  der2 (vlax-curve-getSecondDeriv path par)
    )
    ; calculate curvature at point par
    (setq d (distance '(0 0 0) (cross der1 der2)))
    (if	(> (abs d) 1.0e-15)
      (progn
	(setq curva (/ (expt (distance '(0 0 0) der1) 3) d))
	(if (= curveType 2)
	    (setq curva (* -1. (* sf (/ 1. curva))))
	  )
	(princ "\n") (princ n)
	(princ "   curvature = ") (princ curva)
	(setq p	    (vlax-curve-getPointAtParam path par)
	      perp  (unitv (cross der1 (cross der2 der1)))
	      normv (mapcar '* perp (list curva curva curva))
	      p2    (mapcar '+ p normv)
	)
	(command "_.line" p p2 "")
      )					; end progn
    )
    (setq n (1+ n))
  )
  (setvar 'osmode osm)
  (setvar "cmdecho" 1)
  (princ)
)


  ;;; Compute the cross product of 2 vectors a and b
(defun cross (a b / crs)
  (setq	crs (list
	      (- (* (nth 1 a) (nth 2 b))
		 (* (nth 1 b) (nth 2 a))
	      )
	      (- (* (nth 0 b) (nth 2 a))
		 (* (nth 0 a) (nth 2 b))
	      )
	      (- (* (nth 0 a) (nth 1 b))
		 (* (nth 0 b) (nth 1 a))
	      )
	    )				;end list
  )					;end setq c
)					;end cross
  (defun unitV ( v / d)
  (setq d (distance '(0 0 0) v)
	d (mapcar '/ v (list d d d))))

 

 

 

 

 

lee.minardi
0 Likes
Message 18 of 22

Kent1Cooper
Consultant
Consultant

That looks like a reversal of what's intended -- the Lines are shorter in areas of tighter curvature, rather than longer.  They should be approaching zero length near places of inflection [change in direction of curvature], rather than getting extremely long there.

Kent Cooper, AIA
0 Likes
Message 19 of 22

leeminardi
Mentor
Mentor

I just noticed an error in my last program posting. I do not have time right now to fix it but will do so soon and give the user the option of showing curvature or radius-of-curvature.

lee.minardi
0 Likes
Message 20 of 22

leeminardi
Mentor
Mentor

I have modified the program to let the user chose whether to create a radius-of-curvature vector image or a curvature image. The ends of the lines in the radius of curvature image are the instantaneous center of curvature for the spline at the point where the other end of the line touches the spline. A circle centered at that point with a radius equal to the length of the line will have the same curvature as the spline at that point.

leeminardi_1-1660781461540.png

In the radius of curvature image the end of the lines indicate the instantaneous center of curvature for the spline.

leeminardi_2-1660781977944.png

In the curvature image the curvature is zero (flat) where the line lengths are zero.  Longer lines means a tighter curve.

leeminardi_0-1660780928750.png

 

 

 

(defun C:DOCL (/ path inc n osm	par der1 der2 curva p perp normv p2 sf
	       curveType ans)
; = Degree Of Curvature - Lines
; Creates curvature lines or radius-of-curvature lines
; normal to a spline.
; LRM 8/18/2022 edited to place curvature vectors outside  
  (setq
    path (car (entsel))
    inc	 (/ (vlax-curve-getEndParam path) 100)
    n	 0
    osm	 (getvar 'osmode)
  )
  (setvar 'osmode 0)
  (setvar "cmdecho" 0)
  (initget "y n")
  (setq ans (getkword  "Do you want radius-of-curvature instead of curvature? [y/n] <n>: "))
	(if (= ans "y")
	   (setq curveType 1)
	   (setq curveType 2
		 sf	   (getdist "Enter scale factor.")
	   )
	)
  (repeat 100
    (setq par (* inc n))
    (setq der1 (vlax-curve-getfirstDeriv path par)
	  der2 (vlax-curve-getSecondDeriv path par)
    )
    ; calculate curvature at point par
    (setq d (distance '(0 0 0) (cross der1 der2)))
    (if	(> (abs d) 1.0e-15)
      (progn
	(setq curva (/ (expt (distance '(0 0 0) der1) 3) d))
	(if (= curveType 2)
	    (setq curva (* -1. (* sf (/ 1. curva))))
	  )
	(princ "\n") (princ n)
	(princ "   curvature = ") (princ curva)
	(setq p	    (vlax-curve-getPointAtParam path par)
	      perp  (unitv (cross der1 (cross der2 der1)))
	      normv (mapcar '* perp (list curva curva curva))
	      p2    (mapcar '+ p normv)
	)
	(command "_.line" p p2 "")
      )					; end progn
    )
    (setq n (1+ n))
  )
  (setvar 'osmode osm)
  (setvar "cmdecho" 1)
  (princ)
)


  ;;; Compute the cross product of 2 vectors a and b
(defun cross (a b / crs)
  (setq	crs (list
	      (- (* (nth 1 a) (nth 2 b))
		 (* (nth 1 b) (nth 2 a))
	      )
	      (- (* (nth 0 b) (nth 2 a))
		 (* (nth 0 a) (nth 2 b))
	      )
	      (- (* (nth 0 a) (nth 1 b))
		 (* (nth 0 b) (nth 1 a))
	      )
	    )				;end list
  )					;end setq c
)					;end cross
  (defun unitV ( v / d)
  (setq d (distance '(0 0 0) v)
	d (mapcar '/ v (list d d d))))
lee.minardi
0 Likes