[solved] Drawing part of a helix?

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
User avatar
DerekGove
Active Member
Posts: 41
Joined: Sat May 20, 2023 7:10 pm
Location: Cumbria

[solved] Drawing part of a helix?

Post by DerekGove » Tue May 23, 2023 11:06 am

Morning all,

I can construct a helix (the old-school way) no problem. The issue I'm having is that if I only want to view part of it, when I delete the ends of the spline, it obviously changes the shape at the end of the line.
Helix.png
Helix.png (14.06 KiB) Viewed 2227 times
Is there a way of keeping the rounded end of the curve? The best solution I have so far is to right-click on the spline and use 'Auto Create Polyline', but this means I no longer have a spline, but a dense collection of polylines. I'm just wondering if there are any different or better ways of achieving this.

Regards,
Derek
QCAD Version 3.29.4 : Windows 10

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

Re: Drawing part of a helix?

Post by CVH » Tue May 23, 2023 6:33 pm

Derek,
What you are trying to draw is a Sinusoid or Sine wave.
This is not a common drawing entity that is supported out of the box.
Your approach is probably approximating it with a fitpoint spline (SL).
That could come close enough when using many fitpoints.

Fitpoint spline endings are what they call normal.
There is no residual stress on the spline at those points (https://en.wikipedia.org/wiki/Flat_spline).

The work around is to create more than one wave with fitpoints.
Then cut them where you want, for example with Divide (DI) or draw cutting lines and use a trimming method.
The fitpoint spline will turn into a control point spline keeping the end tangents as they were.
Downsides: Almost the same and it has no longer fitpoints.

But it will never will be a sinusoid. e_geek

'Auto Create Polyline' is the same as Explode (XP).
See Application Preferences for the tolerances used by XP.
If one explodes a spline one will get 1 single polyline entity ... With multiple tangentially connected arc-segments.
If you explode that one level further you get individual arc segments.

As polyline or as arcs the shapes can end wherever you want while still resembling a sinusoid.

Regards,
CVH

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 4935
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Drawing part of a helix?

Post by Husky » Tue May 23, 2023 6:46 pm

DerekGove wrote:
Tue May 23, 2023 11:06 am
Is there a way of keeping the rounded end of the curve?
Divide the spline with "Divide" (DI) at the desired points and delete what you don't need.
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."

User avatar
DerekGove
Active Member
Posts: 41
Joined: Sat May 20, 2023 7:10 pm
Location: Cumbria

Re: Drawing part of a helix?

Post by DerekGove » Tue May 23, 2023 8:44 pm

Husky wrote:
Tue May 23, 2023 6:46 pm
Divide the spline with "Divide" (DI) at the desired points and delete what you don't need.
- Perfect! Thanks Husky. That's exactly what I was needing.
CVH wrote:
Tue May 23, 2023 6:33 pm
What you are trying to draw is a Sinusoid or Sine wave.
This is not a common drawing entity that is supported out of the box.
Your approach is probably approximating it with a fitpoint spline (SL).
Cheers CHV. Thanks for the info.
What I drew is also defined as "the locus of a point which moves around the surface of a cylinder so that it's axial and radial speeds are in a constant ratio". Or a 'helix'. ;)
The construction I used is the standard manual method, using 30/60 set squares, though obviously more points around the circle will give more accuracy. It's used for screw threads, springs, etc. The same method is also used when generating SHM or Simple Harmonic Motion in Cams. The underlying 30/60 construction is used as the basis for most intersections between different curved 3D shapes such as cylinders, cones and spheres.

With what you've said, I'm interested to compare the QCAD spline with a mathematically generated sin wave though, just to see how close they are. Of course, for many years we were expected to locate the control points and draw the curve by hand. Or if it had to be neat, we were allowed to use a flexible rule (originally from the island of Lesbos, so also known as a 'lesbian rule'). Overall, I'm content that QCAD's spline will be close enough, if not an improvement on doing it by hand.

In my day job, I work with 3D software, and if I need to generate mathematical curves such as sin waves, parabola, hyperbola, etc, there's a feature where a mathematical formula can be entered to generate a mathematically precise line. I'll maybe generate one tomorrow, export it as a dxf and compare the two. I'll let you know...
:)

Cheers,
Derek
QCAD Version 3.29.4 : Windows 10

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

Re: [solved] Drawing part of a helix?

Post by CVH » Wed May 24, 2023 6:40 am

DerekGove wrote:
Tue May 23, 2023 8:44 pm
there's a feature where a mathematical formula can be entered to generate a mathematically precise line.
Internally the 'precise line' line will be exact as it is defined by a function.
How it is generated on a screen or on paper relies on the number of generated points.
In general these are interpolated by tiny line segments. Even an arc or circle is rendered segmented.
A dot on the curved line (=exact) may look to be not on the rendered shape.

Among others, the largest errors are encountered in ellipses because there is no closed-form equation to start with.

Knowing I expect:
- No difference at the fitpoints.
- The largest deviations at high curvatures. (1)
- Larger differences for the first and the last half wavelength. (2)
- Minute second order change in the deviations depending the distance to start and end. (3)

Here (1) depends on wavelength and amplitude.
For (2) & (3) the deviation will be larger near the beginning or the end of the spline.

Because of (2) & (3) I advised to draw several waves before cutting out a portion.
Preferable far from and symmetrical in relation with start and end.
One can not expect that a third order spline mimics f(x) = A sin (B(x-C)) + D.

Regards,
CVH

User avatar
DerekGove
Active Member
Posts: 41
Joined: Sat May 20, 2023 7:10 pm
Location: Cumbria

Re: [solved] Drawing part of a helix?

Post by DerekGove » Wed May 24, 2023 8:33 pm

CVH wrote:
Wed May 24, 2023 6:40 am
Internally the 'precise line' line will be exact as it is defined by a function.
How it is generated on a screen or on paper relies on the number of generated points.
In general these are interpolated by tiny line segments. Even an arc or circle is rendered segmented.
A dot on the curved line (=exact) may look to be not on the rendered shape.
- Yep. Mathematical lines are things of beauty, but to achieve a perfect sin curve, an infinite number of points would need to be defined, which is clearly not practical. A huge part of my job is creating 3D shapes with lines which have to approximate curves, using subdivision surfaces. Once I've finished my design, it is frozen, the polygons are decimated, it is CNC'd in dense wood, hand finished, a mould taken of it, a resin cast taken, and another mould taken of that. For my work, aiming for mathematical precision is a pointless, futile exercise.
One client wanted the rounded, bevelled edges to match an earlier mould we'd done for them. The model I'd used was identical, so we couldn't work out the reason for the discrepancy. I soon realised that the chap who hand finished the first mould was a bit more heavy-handed than the chap who finished the second mould.
Mathematically defined lines and curves can only ever be theoretical, anyway. The moment we commit them to either a screen or paper, inaccuracies creep in because of pixels, ink, paper, etc. And even if you wanted to take accuracy to the extreme, right down to the atomic level, that wouldn't work either, because atoms have clouds of particles orbiting them, meaning that the radius of an atom is never a fixed distance anyway—they're always in motion. :D

When I was training, and we had to draw a curve, the mantra was to draw a 'fair curve'. That was the level of accuracy required.

CVH wrote:
Wed May 24, 2023 6:40 am
Knowing I expect:
- No difference at the fitpoints.
- The largest deviations at high curvatures. (1)
- Larger differences for the first and the last half wavelength. (2)
- Minute second order change in the deviations depending the distance to start and end. (3)
- Agree.

So here's my test.
The sin curve was generated in Lightwave 3D, with over 1,500 points defined; an amplitude of approx 2.6 metres; and an accuracy down to a tenth of a millimetre. Lightwave uses metres as it's base unit, so when I opened it in QCAD (which uses a base unit of millimetres) it was only rescaled in the sense of a different scale. No figures were recalculated or modified, just a straight transfer from metres to millimetres.
My helix was constructed over the top of this using the standard method.

The sin wave is a black line (in front), and the helix is a green line (behind).
Sin-Helix.dxf
(172.47 KiB) Downloaded 159 times
You have to zoom in really, really close to see any noticeable discrepancy between the two lines. It's easier to see if you switch to Draft Mode, but even then it's miniscule. But as CVH correctly predicted, the discrepancy is greatest in the areas of high curvature. I'd say it more than fulfils the criteria of a 'fair curve' though.

CVH wrote:
Wed May 24, 2023 6:40 am
One can not expect that a third order spline mimics f(x) = A sin (B(x-C)) + D.
- Exact match? No, never. Because they're different things. But if the definition of 'mimic' is to 'closely imitate', then I think the spline construction does the job admirably. I could increase the accuracy by adding 15 degree dividers on the circle, but I really think the construction is good enough. If both curves were to be printed out on paper, there's no way the human eye could distinguish between them.

Anyway, this has been an interesting exercise. I knew the spline curve wasn't going to be a perfect match, but it's impressively close.

Cheers,
Derek
QCAD Version 3.29.4 : Windows 10

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

Re: [solved] Drawing part of a helix?

Post by CVH » Thu May 25, 2023 2:54 am

DerekGove wrote:
Wed May 24, 2023 8:33 pm
The sin curve was generated in Lightwave 3D, with over 1,500 points defined; an amplitude of approx 2.6 metres; and an accuracy down to a tenth of a millimetre.
The SHM Curve is a polyline, an interpolation.
QCAD does that by scripting:

Code: Select all

var amplitude = 2.652582;    // See SHM Curve
var period = 100/6;          // 16.666...
var offsetX = -50;           // Align halfway with origin in X
var offsetY = -10;           // Align 10 below SHM Curve
var startAngle = 0;          // Starting at 0 degrees
var endAngle = 6*360;        // 6 full periods
var angleStep = 360/256;     // 1.40625 degrees
var i, xPos, yPos;           // Iterator and resulting X/Y
var nodes = [];              // Collector for polyline nodes

var points = (endAngle - startAngle) / angleStep;
var xStep = period * angleStep / 360;

// Populate array with nodes:
for (i=0;i<=points;i++) {
    xPos = (xStep * i) + offsetX;
    yPos = amplitude * sin(angleStep * i) + offsetY;
    nodes.push(new RVector(xPos, yPos));
}

// Adding a dedicated layer:
addLayer("QCAD Curve", "orange", "CONTINUOUS", RLineweight.Weight005);
setCurrentLayer("QCAD Curve");

// Adding a polyline drawing object:
addPolyline(nodes);

Open the Sin-Helix.dxf
Type 'GE' for Misc .. Development .. Script Shell and agree with the dialog.
SELECT ALL of the code panel above and copy that.
Paste the code in the bottom line of the Script Shell.

The result is even better there the reported area of 6 full waves is zero. :lol:
One could increase angleStep and swap addPolyline(...) for addSpline(...) :wink:

Regards,
CVH

User avatar
DerekGove
Active Member
Posts: 41
Joined: Sat May 20, 2023 7:10 pm
Location: Cumbria

Re: [solved] Drawing part of a helix?

Post by DerekGove » Thu May 25, 2023 9:52 am

That's great CVH, thanks very much for putting that script together.

I've tested it by changing some of the variables to create curves with specific properties, including splines instead of polylines, and all good.

Just thinking about other ways of making these curves more accessible, I may generate a couple of versions (maybe a polyline one and a spline version) and save them in the Library Browser. If I create them to be 100mm by 100mm, they'd be very simple to scale to whatever purpose they were needed for.

Now I'm thinking ahead to involutes too. I may have to look into the scripting used by QCAD and try to modify your script to do something slightly different. I couldn't have written that script from scratch, but I should be able to reverse engineer and modify it a bit. But then I have also spotted a tool for what I think is an archimedean spiral, so maybe that has involute functionality.

As I mentioned in my introduction, one of the reasons I'm using QCAD is to produce the content and knowledge I covered when I learned hand-drawn technical drawing, so the method I was using is absolutely fine for that purpose, but if a few extra scripts (such as the one you provided) could be built in to QCAD, that'd be great.

Cheers,
Derek
QCAD Version 3.29.4 : Windows 10

User avatar
DerekGove
Active Member
Posts: 41
Joined: Sat May 20, 2023 7:10 pm
Location: Cumbria

Re: [solved] Drawing part of a helix?

Post by DerekGove » Thu May 25, 2023 10:10 am

If anybody else would like them, here's the basic curves I've generated and put in my Library browser.

As 'building blocks', they're all a single revolution, and fit within a bounding box of 100mm x 100mm.

I've named them all 'Helix', and given them a suffix of 'P' for a polyline or 'S' for a spline, followed by the number of segments they have.

Regards,
Derek
Attachments
Helix S24.dxf
(98.47 KiB) Downloaded 161 times
Helix S12.dxf
(96.77 KiB) Downloaded 156 times
Helix P48.dxf
(96.83 KiB) Downloaded 155 times
Helix P24.dxf
(95.76 KiB) Downloaded 159 times
Helix P12.dxf
(95.23 KiB) Downloaded 145 times
QCAD Version 3.29.4 : Windows 10

Post Reply

Return to “QCAD 'How Do I' Questions”