DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

LineSnap and Curves (a heads up)

Started by prl, May 02, 2008, 05:33:56 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

prl

Bd and I have been discussing curves in this topic

http://forum.designcad.com/index.php?topic=1299.0


Since I use line snaps heavily I wanted to know how DesignCAD deals with curves when using the line snap.  I've come to the conclusion DesignCAD's line snap does not track a curve but a segmented vector approximation.

Attached is a screen recording that shows what I mean and also the file I was fiddling with to create the recording.


ps.  Thanks Bd for making me aware of this DesignCAD limitation.


Edit:  Oh yes, the first part of the recording deals with trimming several lines back to the curve.  Another conclusion is that the line snap and the trim functions are using different approximations of the curves, both of which are coarse and too far off for comfort.

Dr PR

prl,

I also have noticed the tendency to snap to a segmented approximation of a curve, like you get if you select the "Draw as line" option when creating a circle. However, it isn't quite that simple.

The attached PDF file shows two curves - actually parts of circles. The black line is a normal circle ("Draw as circle"). The red line is a circle created with "Draw as line" and 120 segments. The blue line was drawn from the circle center, and the green lines are drawn from intersect points generated by the "Intersect 2" function. As you can see, the intersect points to the "real" circle aren't the same as for the segmented circle. Both intersects are visibly correct - at least at any zoom level I have tried.

This was a 3D drawing with the circles tilted out of the planes of any of the axes (I rarely see problems in 2D drawings). I also rarely see problems in small drawings. The Intersect 2 command seems to become more unreliable as a drawing gets larger (I have no objective proof of this because the failure is difficult to reproduce on demand).

I have seen three interesting phenomena related to the Intersect 2 function:

1. When two "real" circles are drawn so both intersect a line at the same point, often the I2 command will not find an intersect with either circle and the line, but it almost always finds the intersect of the two circles.

2. Often the command will find an intersect with the far side of a circle (more distant from the line) but not the side closest to the line.

3. Often the line/curve intersect point is far away from either the line or curve. Even though the intersect point is not shown on the screen, if you click the mouse a point will be set off screen. It is as if the intersect point was calculated with a "circle" segment almost parallel to the line.
DesignCAD user since 1987

bdeck

#2
Prl,

Here are more thoughts.

Better interpolation method needed. (see attached NumMethod.dcd and NumMethod.xls)

Snapping to or trimming a line to a circle is a strightforward precise calculation.

Snapping to or trimming a line to a cubic spline ("Curve" in DesignCad) is more difficult for 2 reasons:

1) The values of x,y, and z on a cubic spline are not functions of each other, they are functions of n. As such, gravity snap and trim cannot be computed directly. Intersection points on a curve can be found accurately only by an iterative numerical interpolation process.

2) The splines used by DC are faired (or blended) in a process that uses essentially every node in the spline to determine the location of every point. This slows the calculation process somewhat, and complicates the editing process, but makes prettier splines with fewer nodes. The spline definitions are presumably compatible with OpenGL, so thad DC does not have to compute the location of every point on the screen.

Still, with little more calculation than DC performs currently, it should be easy to get much higher precision in interpolation.

How DC Does it
On the trimerror2.dcd and twolines.jpg examples previously posted, DC appears to have plotted out 10 points between the two nodes nearest to the target intersection, and performed a simple linear interpolation between the nearest 2 plotted points. ( It is unclear whether DC acturally plots all 10 points. If DC plots only enough points to find the intersection, perhaps using a modified binary search, then the number of points actually plotted could average fewer than 4).

How it Should be Done
As the attachments show, plotting 10 points using an iterative "Interpolation Search" method on a similar curve intersecting a similar line should result in a much smaller error, as each point plotted locates incrementally closer to the target intersection.

This method uses the location of the intercept on the chord between the two nodes nearest the line (nodes 2 and 3 in the example) to create a new fractional node, and then repeats the process using that new fractional node and one of the original nodes to form the next chord.

After 5 iterations, the method demonstrated is just barely more accurate than the DC, on average.

After 10 iterations, the interpolation error using this method is about 0.12% of the mean DC error. See columns M and P.

That is, by plotting ten points in an interative process, DC could increase its mean interpolation accuracy in this example by a factor of 850.

Each 4 points plotted in this example increase the accuracy by a factor of nearly 200. So after plotting 14 points, this iterative method is 166,000 times more accurate than is DC on average.

At 20 to 29 iterations, the error diminishes beyond the 10^-16 precision of my XL spreadsheet.

A Safe Implementation

A safe way to improve DC's interpolation would be to use the nearest 2 points plotted in the present DC method to define a starting chord for an iterative search method computed to floating point extinction. That would improve accuracy without sacrificing the logic that is already in place.

My cpu is fast enough. I vote for that.

BD


Note 1: DC's current trimming error depends on the serendipitous placement of the trim line along the minichord between the nearest 2 of 10 plotted interpolation points. Because the intersection fell near the end of the minichord, DC's error in this example was only about 15% of what it would have been had it fallen in the middle of the chord. On the other hand,The error in Trimerror2.dcd was .5 inches between two nodes that were only 33" apart.

Note2 : This is just an example method. There are may others. The method described here is not optimized, and is somehwhat sensitive to the angle the line forms with the curve, and the degree of curvature in the curve. But in this example, after 10 iterations its error is less than 1% of the average error that would result from a simple binary search. (see columns R and S)

Note3 : All methods have the disadvantage of needing some extra logic to assure proper results when curve has convoluted shape or crosses itself. Even DC's current method will not find a tangent or near tangent that fails to cross one of the chords.

Final note: Plotting points on a cubic spline is largely a MAC (multiply and accumulate) operation, so the DSP capabilities of an MMX CPU and particularly an AMD Athalon (with floating point dsp) should be able to crank these out in no time.


prl

Thanks Bd. It's been a long time since I thought about numerical methods.  Hopefully someone on the IMSI side is fresh out of the gate on this one!   ;)


support

The issue is that the pixels used by Windows to generate the display and the XYZ points used by DesignCAD do not always align so there are many cases when trimming to a curve will be off in the onscreen display.

Rob S

#5
Jerry, I think you really need to re-read all the posts on this subject, and look at the examples.

http://forum.designcad.com/index.php?topic=1299.0

There is a LOT more going on than just pixels off.
User since forever

DrollTroll

Look for improvements on this in 18.3
25 years with DesignCAD

accuratesteel

Do you know when 18.3 will be ready to go ?

accuratesteel

DrollTroll

25 years with DesignCAD

Slind

Bdeck,

I have imported arcs in DXF files ( with all blocks exploded );
Upon using the combine command on arcs, the smooth
arc is altered to reflect segmented sections of lines.

Would this approximation of plotted points also apply
to combined lines ?

As well, when I need to create a shallow arc, say 33" in
length and .423" high : Using the three point circle,
then switch to Point Select Mode and trim excess.
Arc alters shape considerably.  Always thought this
was software's interpretation of Curve versus Bezier
Curve but now wonder if this is complicit ?

Slind





bdeck

#10


Quote
Would this approximation of plotted points also apply to combined lines ?

Hi Slind,

In my experience, points plotted by combine lines, parallel line, vector convert, and trim (except the trim point) all fall on the source curve, arc, etc.

For curves and elliptical arcs, the trim point,  the snap point, surface connect mesh, and possibly slice lines are in error. ( ellip arcs seem to have improved somewhat lately)

The reason the shape changes so drastically on your shallow arc is that the number of points DC plots for arcs in the combine lines function (or vector convert)  is only one point every 3 degrees.

This is also a problem that should be addressed, perhaps with a user selectable point density.


Quote
Using the three point circle, then switch to Point Select Mode and trim excess. Arc alters shape considerably. 

I've seen trim and snap errors on elliptical arcs, but not circular arcs.

If you have an example, I'm sure DT would be interested in seeing it.

(Actually, SurfaceConnect seems to miss circular arcs as well as curves and ellip arcs.)

BD


PS:   DT, Thanks for the status update. Say hallelujah.   



bdeck

#11
See file below for current status.

While a minor bug fix improved the look and the precision in V 19,  DC continues to use imprecise linear interpolation to find snaps and line intercepts on curves.

Ellipse intercept precision seems to have improved in version 17.x.

BD

Slind

Regarding this post :

<  As well, when I need to create a shallow arc, say 33" in
<  length and .423" high : Using the three point circle,
<  then switch to Point Select Mode and trim excess.
<  Arc alters shape considerably. 

In the end, it was easier just to snap a curve line on the
remaining points of the ( three point circle ) arc.
This generates a smooth arc with a bounty of points. 

Sort of going the long way around, but the result is a much
smoother arc cut.

It also avoids the " flattening out " phenomena when trying
to use a curve line on three points. ( exclusively )

Slind

" Circle gets the square "