Author Topic: Obtain radius of a given point with hundreds of discrete points  (Read 2582 times)

0 Members and 1 Guest are viewing this topic.

sysuwzx

  • Mosquito
  • Posts: 18
I have hundreds of 3d points and now want to get the curve radius of one certain point.  I  try to draw a spline and use vlax-curve-getSecondDeriv function. But it seems that the spline is sooo smooth that every point's radius is nearly zero!
So it seems a little difficult to get what i need. Anyone who have good idea will be appreciated.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #1 on: June 25, 2016, 11:15:40 PM »
Please Clarify :
Quote
I have hundreds of 3d points ..
Are these :
AcDbPoint
or Geometry points represented by a 3 index list)
or Vertex Points associated with an object. ??

Quote
.. and now want to get the curve radius of one certain point...

What is a 'curve radius' for a 'Point' ?

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

ymg

  • Guest
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #2 on: June 26, 2016, 12:18:42 PM »
You need to fit the points to a sphere.

I've done it here for a circle.

Quote
This would be the function to minimize:
                          Σ((-x-xc)2+(y-yc)2+(z-zc)2-r2)2    

ymg
« Last Edit: June 26, 2016, 12:35:44 PM by ymg »

sysuwzx

  • Mosquito
  • Posts: 18
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #3 on: June 26, 2016, 08:25:47 PM »
Please Clarify :
Quote
I have hundreds of 3d points ..
Are these :
AcDbPoint
or Geometry points represented by a 3 index list)
or Vertex Points associated with an object. ??

Quote
.. and now want to get the curve radius of one certain point...

What is a 'curve radius' for a 'Point' ?

sorry~
1. the points is geometry points represented by a 3 index list
2. i should say it a curve radius at a point rather than for a point. As we know, the curve radius at  any point in  a circle equals the radius of the circle. Further, the curve radius at one point in a spline or polyline or any other types of curve demonstrates the tendency of the curve, and this is called curve radius, equals the radius of the closest circle. 
I wonder if this could get you understood. Any idea to this problem is welcome.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #4 on: June 27, 2016, 02:38:22 AM »
Remember a spline's "radius" is infinitely changing. That's what makes it a spline. So at any one single point along a spline, the more accurate you try to be the more the radius tends toward infinity - i.e. a straight line.


It's only once you reduce the accuracy that the radius starts to make some sense. That's because of how a radius at a point along a curve is calculated. You pick the point, then calculated 2 points either side of it equi-distant from the first. Then calculate the centre point and the radius. Simple way is to bisect a line between the mid and each side, calculate a perp line to those and see where these intersect - that would be the centre point. As sample: http://www.lee-mac.com/3pointarccircle.html And from that you should understand why a spline's "exact" radius appears to be infinite - as if it's a straight line: As the measuring distance between the picked point and its temporary measure points either side gets ever smaller, the radius increases, up to the point where the floating point number used in ACad for stuff like distances, angles, XYZ values, etc. gets to its minimum possible value (called epsilon).


The calculations become more difficult once you throw a z-value into the mix as well. This means you first need to define a UCS going through those 3 points (in order to get a flat pane between them). Only then can you properly calculate the radius in 3d space between those 3 points.


However, remember you're only approximating such "radius", since strictly speaking a spline has "no" radius at any point. And worst is that this technique wont work (without some modifications) on the start and end points of a non-closed spline.


There are other ways to calculate the same. Some math matrix calcs or trig may be used. But for starters I'd simply go with the geometric calc explained above. Just choose some chord distance between the 3 points which is appropriate for your scenario.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

SEANT

  • Bull Frog
  • Posts: 345
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #5 on: June 28, 2016, 04:12:02 AM »
With regard to curvature at point along a spline:

Unlike circles and arcs, the second derivative of a point on a spline does not give any direct information about the local curvature.  As a matter of fact the vector direction of Second derivative isn't necessarily perpendicular to that of the First, so it usually won't point towards the Curvature Circle's center.

A center pointing vector has to be derived by first computing the Curvature Circle's plane via the cross product:
Norm = FirstDer X SecondDer

Then the radius' direction via cross:
RadDir = Norm X FirstDer

The radius of curvature for that point on a spline can then be found by calculating magnitude of FirstDer (TanLength), deriving the projection (ProjLength) of SecondDer onto RadDir, then:
Radius = TanLength^2 / ProjLength
Sean Tessier
AutoCAD 2016 Mechanical

ribarm

  • Gator
  • Posts: 3250
  • Marko Ribar, architect
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #6 on: June 28, 2016, 10:37:10 PM »
SEANT is right, try what he explained and you'll get evolute... Just be sure to (entmake) 3d polyline as 3d spline isn't so thankful when (entmake) is the task...
I've tested and all is fine...
If you need additional help, just ask, we'll be happy to see your code...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

SEANT

  • Bull Frog
  • Posts: 345
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #7 on: June 29, 2016, 03:12:45 AM »
I may have taken this to a place where not many of us wanted to go - at least not without some visual aid.

See the attached drawing.  For this fairly simple spline, I've plotted the First and Second derivative, as well as construction geometry as explained in my previous post.  I've plotted the circle with radii as derived by the formula to align with the pertinent spot on the spline.

Those radius values match what would be returned by the ARX GetCurvature function 
(Radius = 1 / Autodesk.AutoCAD.Geometry.PointOnCurve3d.GetCurvature)
Sean Tessier
AutoCAD 2016 Mechanical

SEANT

  • Bull Frog
  • Posts: 345
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #8 on: June 30, 2016, 03:08:13 AM »
Still not a lot of interest.  Even with my excellent visual aid.

Tough crowd.

Perhaps my graphic was not so excellent. It was a little static and boring.  I've got a webcam . . . . don't make me do my next demo via pantomime.
Sean Tessier
AutoCAD 2016 Mechanical

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2132
  • class keyThumper<T>:ILazy<T>
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #9 on: June 30, 2016, 03:21:47 AM »
Still not a lot of interest.  Even with my excellent visual aid.

Tough crowd.

Perhaps my graphic was not so excellent. It was a little static and boring.  I've got a webcam . . . . don't make me do my next demo via pantomime.

wait ... Where did I put my popcorn ...
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Gasty

  • Newt
  • Posts: 90
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #10 on: July 03, 2016, 06:53:30 PM »
Hi,

This very old function from Vladimir Nesterovsky may help:
Code - Auto/Visual Lisp: [Select]
  1. ;; CVRAD -- curve radius for splines
  2. ;; (C.) 1999 by Vladimir Nesterovsky,
  3. ;; http://vnestr.tripod.com, vnestr@netvision.net.il
  4. ;; r = ( (x')^2 + (y')^2 )^3/2 / ( x''y' - y''x' )
  5. ;; it's the right thing!!!!! ACAD only errors for plines,
  6. ;; where it always returns radius positive
  7. (defun cvrad (o a / f s r fx fy sx sy k d)
  8.           s  (vlax-curve-getsecondderiv o a)           ; x' and y'
  9.           fx (car f)
  10.           fy (cadr f)                                  ; x'' and y''
  11.           sx (car s)
  12.           sy (cadr s)
  13.           k  (expt (+ (* fx fx) (* fy fy)) 1.5)        ; it's (- (book-formula)) somehow
  14.           d  (- (- (* sx fy) (* sy fx)))
  15.     )
  16.     (cond ((zerop d) 1e+7)                             ; instead of INF
  17.           ((< (abs (setq r (/ k d))) 1e+7) r)
  18.           ((< r 0) -1e+7)
  19.           (1e+7)
  20.     )
  21. )
  22.  
where it takes two parameters, 'o' for object,
and 'a' for a parameter to get the radius for.

Gaston Nunez


edit kdub:->addCodeTags
« Last Edit: July 03, 2016, 07:00:44 PM by kdub »

SEANT

  • Bull Frog
  • Posts: 345
Re: Obtain radius of a given point with hundreds of discrete points
« Reply #11 on: July 04, 2016, 03:51:12 AM »
Vladimir Nesterovsky is the ultimate trailblazer for curve analysis via AutoCAD automation.  I don’t see many new posting from him, though; hopefully he continues his pioneering work.  I’d love to have a conversation with the man.

Conceivably, the method I described decomposes to the math shown in Vladimir’s routine.  I notice that his routine focuses on 2D splines.  I suspect it could be modified to allow full 3d compatibility.   
Sean Tessier
AutoCAD 2016 Mechanical