What type of object is a Circle?

If you are having problems with QCAD, post here. Please report bugs through our Bug Tracker instead.

Always attach your original DXF or DWG file and mentions your QCAD version and the platform you are on.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
HappyShat
Active Member
Posts: 48
Joined: Thu Jul 25, 2019 9:43 pm

What type of object is a Circle?

Post by HappyShat » Sun Apr 07, 2024 8:26 pm

When I explode a circle a couple of times - I see that the circle is made from two arcs. I drew the circle using the "circle2p" command - draw a circle with two points.

Is the circle a type of block?

Thanks for any information.

I'm using QCAD version 3.24.3.0 on a Windows 11 Pro machine.

CVH
Premier Member
Posts: 3485
Joined: Wed Sep 27, 2017 4:17 pm

Re: What type of object is a Circle?

Post by CVH » Mon Apr 08, 2024 1:43 am

HappyShat wrote:
Sun Apr 07, 2024 8:26 pm
Is the circle a type of block?
No, not at all, an arc and a circle are two distinct basic CAD entities.

In normal conditions a circle would not explode at all.
Test it, draw a circle with CI for example, select and explode (XP) it.
The circle entity remains a circle. :wink:

What probably happened is that you made a polyline of the circle and exploded that.
Polylines are strings of line/arc segments or better, strings of connected segments with a bulge factor.
Bulge = zero or not bulging for a straight segment and bulge = tan(sweep/4) for segments that resemble an arc.

The bulge factor of a full circular arc would be tan(360°/4) what is an error, tan(90°) is defined as y=1 divided by x=0.
To avoid this, circles are stored as two semi circular arc segments with bulge = tan(180°/4) = 1.
If you exploded such a polyline you get indeed two semi circular arc entities.

Now, full circular arcs are another problem.
The normalized (0° <= angle < 360°) start and end angle would be identical and the difference would be sweep = zero.
QCAD will detect that in some (normal) cases and revert to sweep = 360° ...
https://www.qcad.org/rsforum/viewtopic.php?f=33&t=10259
In other words: Something to avoid. :wink:

Regards,
CVH

HappyShat
Active Member
Posts: 48
Joined: Thu Jul 25, 2019 9:43 pm

Re: What type of object is a Circle?

Post by HappyShat » Mon Apr 08, 2024 4:31 am

CVH wrote:
Mon Apr 08, 2024 1:43 am
HappyShat wrote:
Sun Apr 07, 2024 8:26 pm
Is the circle a type of block?
What probably happened is that you made a polyline of the circle and exploded that.
As I indicated in my first post using the "circle2p" command and exploded that - twice - resulting in two arcs.

The same is true using the CI keyboard shortcuts - the resultant circle created with the command CI can then be exploded two times to get two arcs.

I'm actually troubleshooting a DXF import issue (not troubleshooting QCAD) - and it turns out that I need to understand what this circle is exactly.

CVH
Premier Member
Posts: 3485
Joined: Wed Sep 27, 2017 4:17 pm

Re: What type of object is a Circle?

Post by CVH » Mon Apr 08, 2024 5:39 am

HappyShat wrote:
Mon Apr 08, 2024 4:31 am
As I indicated in my first post using the "circle2p" command and exploded that - twice - resulting in two arcs.
My bad :oops: this is by preference.
See Application Preferences .. Modify .. Explode.

First it is converted to a polyline.
After that you explode the polyline.

For me that preference is cleared for over 3 years, keeping circles what they are. :wink:
https://www.qcad.org/rsforum/viewtopic.php?f=31&t=7914

Regards,
CVH

HappyShat
Active Member
Posts: 48
Joined: Thu Jul 25, 2019 9:43 pm

Re: What type of object is a Circle?

Post by HappyShat » Mon Apr 08, 2024 4:46 pm

After a circle has been exploded - how to you turn the objects back to being a circle?

Is the circle object from QCAD identical to what AutoCAD generates?

HappyShat
Active Member
Posts: 48
Joined: Thu Jul 25, 2019 9:43 pm

Re: What type of object is a Circle?

Post by HappyShat » Mon Apr 08, 2024 6:27 pm

I've attached a DXF file with two polyline "circles." Aside from differences in radius and physical xy locations - what are the differences between these two objects?

The reason why I ask is that they do not import the same (I'm importing into a completely different CAD program).

I'd like to get a better idea why the two objects, the two circles, in the attached DXF are not treated the same when importing into another CAD software program.
Attachments
two_circles.dxf
(103.48 KiB) Downloaded 10 times

CVH
Premier Member
Posts: 3485
Joined: Wed Sep 27, 2017 4:17 pm

Re: What type of object is a Circle?

Post by CVH » Mon Apr 08, 2024 10:47 pm

HappyShat wrote:
Mon Apr 08, 2024 4:46 pm
After a circle has been exploded - how to you turn the objects back to being a circle?
The answer is partially given in the linked topic:
Something we can 'Undo' immediately if we notice it soon enough.
When 'Undo' is out of the question there is no easy way back but redrawing.
So, Undo (OO) all steps in the current QCAD session until you have the original circles back.
But if that is out of the question, when not exploded in this QCAD session, when part of a stored file ....
... Then you must replace them by new circles.
I once posted a little remedying script but I can't locate it at the moment, I can't search PM's either.
Not problematic to rewrite on the fly ... :wink:
HappyShat wrote:
Mon Apr 08, 2024 6:27 pm
I'd like to get a better idea why the two objects, the two circles, in the attached DXF are not treated the same when importing into another CAD software program.
Apart from the apparent radius they are practically the same.
Both are a closed CCW polyline made up of 2 semi circle segments.
The main differences are: Left starts at 0°, R0.6 ; Right starts at 180°, R0.58737627
A very subtle difference is that the left one has bulges factors of 0.9999999999999999 instead of 1.

When exploded to Arcs we can recombine them by creating polylines from a selection (OC).
One can filter on all arcs and select them, see menu: View .. Selection Filter.
To display the Selection Filter you can also type GF
Once all 'circular' polylines are formed we can replace all of them with circles using the script below.
It diversifies between looking for them in an existent selection or among all document entities.

Code: Select all

    var di = EAction.getDocumentInterface();
    var doc = di.getDocument();
    var ids = [];

    if (doc.hasSelection()) {
        ids = doc.querySelectedEntities();
    }
    if (!doc.hasSelection()) {
        ids = doc.queryAllEntities();
    }

    var op = new RAddObjectsOperation();
    op.setText("CircularPolys > Circles");

    for (var i=0; i<ids.length; i++) {
        var id = ids[i];
        var entity = doc.queryEntity(id);
        if (!isEntity(entity) || !isPolylineEntity(entity)) {
            continue;
        }

        if (entity.countSegments() !== 2) {
            continue;
        }

        if (!RMath.fuzzyCompare(entity.getBulgeAt(0), 1.0)) {
            continue;
        }
        if (!RMath.fuzzyCompare(entity.getBulgeAt(1), 1.0)) {
            continue;
        }

        var arc = entity.getSegmentAt(0);
        var circle = new RCircle(arc.getCenter(), arc.getRadius());
        var newEntity = new RCircleEntity(doc, new RCircleData(circle));
        newEntity.copyAttributesFrom(entity.data());

        op.deleteObject(entity);
        op.addObject(newEntity, false);
    }

    di.applyOperation(op);
Click on 'SELECT ALL' and then copy the selected text (R-click .. Copy or Ctrl+C).
In QCAD start the Misc .. Development .. Script Shell (GE) and acknowledge to the dialog.
Paste the copied script to the bottom line of the Shell (R-click .. Paste).

Regards,
CVH

HappyShat
Active Member
Posts: 48
Joined: Thu Jul 25, 2019 9:43 pm

Re: What type of object is a Circle?

Post by HappyShat » Mon Apr 08, 2024 11:00 pm

CVH wrote:
Mon Apr 08, 2024 10:47 pm
The main differences are: Left starts at 0°, R0.6 ; Right starts at 180°, R0.58737627
How do I convert the left to be the similar to the right (change it from 0°, R0.6 to 180°, R0.6)?

Also, the Properties panel isn't showing this information - where can I find it?

CVH
Premier Member
Posts: 3485
Joined: Wed Sep 27, 2017 4:17 pm

Re: What type of object is a Circle?

Post by CVH » Mon Apr 08, 2024 11:21 pm

HappyShat wrote:
Mon Apr 08, 2024 11:00 pm
Also, the Properties panel isn't showing this information - where can I find it?
When selected the red reference marker is the start point.
The rest of the info is gathered from the vertices listed in the Property Editor.
HappyShat wrote:
Mon Apr 08, 2024 11:00 pm
How do I convert the left to be the similar to the right (change it from 0°, R0.6 to 180°, R0.6)?
What about Modify .. Flip Horizontal (FH)

Remind that this are polylines and not circles, they only look exactly the same.
The right one has an apparent radius of 0.58737627 :wink:
There is no radius associated with polylines that represent a circular contour. e_geek
HappyShat wrote:
Mon Apr 08, 2024 4:46 pm
Is the circle object from QCAD identical to what AutoCAD generates?
Most probably yes, Arc and Circles are common CAD drawing entities.

Regards,
CVH

CVH
Premier Member
Posts: 3485
Joined: Wed Sep 27, 2017 4:17 pm

Re: What type of object is a Circle?

Post by CVH » Tue Apr 09, 2024 12:00 am

HappyShat wrote:
Mon Apr 08, 2024 6:27 pm
The reason why I ask is that they do not import the same (I'm importing into a completely different CAD program).
Curious on how they are handled differently ... It should not be different at all ... :wink:

Could you share a screen caption of the file with polylines in that application?

Regards,
CVH

HappyShat
Active Member
Posts: 48
Joined: Thu Jul 25, 2019 9:43 pm

Re: What type of object is a Circle?

Post by HappyShat » Tue Apr 09, 2024 12:43 am

CVH wrote:
Tue Apr 09, 2024 12:00 am
HappyShat wrote:
Mon Apr 08, 2024 6:27 pm
The reason why I ask is that they do not import the same (I'm importing into a completely different CAD program).
Curious on how they are handled differently ... It should not be different at all ... :wink:

Could you share a screen caption of the file with polylines in that application?

Regards,
CVH
There's clearly a difference when imported. My interest in this is to reproduce the issue. An effective radius shouldn't make any difference (otherwise the $12k CAD tool I'm using would be useless). Interestingly, when I compare the two objects - their bulge parameter are both listed as exactly one in the property window.

Looks like bulge factor triggers the other CAD program.

How were you able to tell the difference between the bulge factors? Both show up as exact 1 in the Property window.

CVH
Premier Member
Posts: 3485
Joined: Wed Sep 27, 2017 4:17 pm

Re: What type of object is a Circle?

Post by CVH » Tue Apr 09, 2024 7:04 am

HappyShat wrote:
Tue Apr 09, 2024 12:43 am
How were you able to tell the difference between the bulge factors? Both show up as exact 1 in the Property window.
Values in the Property Editor are always rounded values, displayed with 0 to 8 digits depending preferences.
One can change the the bulge factor of each segment in direct, even in full precision.
Remind that subtle changes to values may not be performed.
First changing the bulge factor to 0.9 and then set the value to 1 should work here.

Discovered it while debugging the script as it failed to convert the left example to a circle.
Initially it tested for entity.getBulgeAt(0) === 1.0 and entity.getBulgeAt(1) === 1.0
Replaced that with a fuzzy compare what uses a default tolerance of +/-1e-9.
The default point tolerance used in QCAD.
HappyShat wrote:
Tue Apr 09, 2024 12:43 am
Looks like bulge factor triggers the other CAD program.
It should not make any difference at all ...
... These segments represent an arc with a sweep angle of 179.99999999999998854084409738354 degrees. (sweep = 4 * atan(bulge))
Even two segments of 170, 190 or 90 degrees should be valid but the resemblance with a circle disappears.
Remember that a single segment with a sweep of 360° is a catastrophic error, tan(90°) = undefined.

Applications using Floating Point notation should expect some inaccuracies and handle that properly.
The specific origin is twofold:
- Arcs have no endpoints, they have end angles, polyline segments do have endpoints, they are called vertices or nodes.
The conversion from polar (angle based) to Cartesian (point based) or back can't be exact.
- Trigonometry is used to convert Arc sweep to bulge factor or back and that can't be exact.

Aside from:
- Floating Point notation doubles are limited to 52 bits for storing the mantissa of values, what is pretty precise BTW.
- 180° may look like a nice integer value but angles are handled in radians and 180°= Pi rads.
- Conversions between degrees and radians can't be exact there PI is an endless number what can not be stored.


As presented the conversion script already preform well for common usage.
Slightly better would be to average out the centers and radii of the 2 segments converted to arcs:

Code: Select all

    var arc0 = entity.getSegmentAt(0);
    var arc1 = entity.getSegmentAt(1);
    var circle = new RCircle(RVector.getAverage(arc0.getCenter(), arc1.getCenter()), (arc0.getRadius() + arc1.getRadius()) / 2 );
But the more we do Floating Point math, the larger the uncertainty of the result. (Similar as Entropy)
What doesn't exclude that the result would be almost perfect but it can be a few bits off with the same effort.
Number uncertainty also means that you will never know it for certain and that you can not test for it unless knowing what to expect. :wink:

Regards,
CVH

HappyShat
Active Member
Posts: 48
Joined: Thu Jul 25, 2019 9:43 pm

Re: What type of object is a Circle?

Post by HappyShat » Tue Apr 09, 2024 7:17 pm

CVH wrote:
Tue Apr 09, 2024 7:04 am
It should not make any difference at all ...
Well, apparently, this makes a difference when importing into another CAD program. My question for you is this:

I see a bulge factor of 1 for both of the circles in the DXF that I posted. You mentioned that one of the circles has a bulge fact of something similar to this 0.999999999999999. Why is it you were able see this difference and I am not able to see the difference? I'm using the Properties box/panel the view the numerical value of the bulge factor - and, both are exactly 1.

Where can I see the high resolution of the bulge factor?

CVH
Premier Member
Posts: 3485
Joined: Wed Sep 27, 2017 4:17 pm

Re: What type of object is a Circle?

Post by CVH » Tue Apr 09, 2024 11:25 pm

HappyShat wrote:
Tue Apr 09, 2024 7:17 pm
Why is it you were able see this difference and I am not able to see the difference?
CVH wrote:
Tue Apr 09, 2024 7:04 am
Discovered it while debugging the script as it failed to convert the left example to a circle.
Additionally in testing for it, I stored the actual value in a variable.
var bulge0 = entity.getBulgeAt(0);
var bulge1 = entity.getBulgeAt(1);

And then paused the script there.

Then it was also obvious that some basic tolerance was required. :wink:

Your application would have more issues with a segment representing a 90° degree arc.
A value of give or take sqrt(3-2*sqrt(2)) can't be stored exactly.

Regards,
CVH

Post Reply

Return to “QCAD Troubleshooting and Problems”