Help with Round operation

This forum is for 'Work-in-Progress' QCAD user developed script Add Ons and Plug-ins.

Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: andrew, Husky, J-J

Post Reply
sandyg
Junior Member
Posts: 20
Joined: Thu Dec 12, 2019 10:49 pm

Help with Round operation

Post by sandyg » Sat Dec 28, 2019 1:44 am

Got pretty far on my CrankWheel library plug in and was trying to go the extra mile and make some of the edge have a nice round for the internal spokes. Very easy to do manually in QCAD, but trying to automate that too.

I have some code that looks like this to draw on of the spokes -

Code: Select all

hole = new RPolyline();
hole.setClosed(true);

// draw each slot as a closed object
hole.appendVertex(RVector.createPolar(r0, (spokeAngle - a0) + spokeAngleOffset), Math.tan((2 * a0 - spokeAngle) / 4));
hole.appendVertex(RVector.createPolar(r0, a0 + spokeAngleOffset));
hole.appendVertex(RVector.createPolar(r1, a1 + spokeAngleOffset), Math.tan((spokeAngle - 2 * a1) / 4));
hole.appendVertex(RVector.createPolar(r1, (spokeAngle - a1) + spokeAngleOffset));

// once all created add and draw
addOperation.addObject(new RPolylineEntity(document, new RPolylineData(hole)));
I found the Round operation (with a small radius) as what I need to do, but not sure how to include this or do it in the script.

Couple of questions-
Do I need to installs the Round.js from Git to get this functionality or is it built in
Any example Library plugin code that shows an example of doing this

Thanks

Sandy

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

Re: Help with Round operation

Post by CVH » Sat Dec 28, 2019 4:35 am

Hi,

for one:
Normally you don't have to have all the scripts in the script folder.
All scripts are compiled present in a standard instalation.
Its the copy that will be executed, having a copy of a script file at its appropiate place.
'Incuding' them in your own script might still be nececary.
Usually there are some instructions or you have to look for common usage.
Or you might have to follow the 'include' tree.
On the other hand, why not simply including.

It never hurst to have a copy off the scripts present at GIT.
They don't have to be saved in the system area.
I have a full copy to search with NPP.


Curious in the outcome, though.
A script that would add roundings to a poly is something I am looking out for.

At math level like you code above:
While 'drawing' a poly you can add arc's in between.
This is done by DrawPolyline.js starting at: Line 188
Still a scripting novice....
Maybe you can have a look at that.

At Entity or object level there definitely is code in the
project that adds roundings between segments.
Can't pinpoint it at the moment.

...ModifyCorner.js maybe
Right under my nose (NPP)
(One of the few where RMath.absmod() is used)

Cheers,
CVH
Last edited by CVH on Sat Dec 28, 2019 4:55 am, edited 3 times in total.

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

Re: Help with Round operation

Post by CVH » Sat Dec 28, 2019 4:49 am

sandyg wrote:
Sat Dec 28, 2019 1:44 am

Code: Select all

... - a0) + spokeAngleOffset), Math.tan((2 * a0 - spokeAngle) / 4));
.... Math.tan((spokeAngle - 2 * a1) / 4));
Curious: Math.tan(abc): Can abc be pi/2 or 3pi/2?
Catch faults before they occur!...

CVH

sandyg
Junior Member
Posts: 20
Joined: Thu Dec 12, 2019 10:49 pm

Re: Help with Round operation

Post by sandyg » Mon Dec 30, 2019 3:43 am

Thanks for the tips, I had to take a step back as I found a drawing issue with the bulge on some parts. Re-wrote the drawing and seems all good. For the rounding stuff I think I'll have to play with it a bit. I think that if I do use any of the Round.js or related I will need to include that file if I deploy my code since it's not there in anyone's install unless they manually get it.

I think the tan(abc) is OK since the values don't seem to be able to get to a pi/2 etc value. I do want to do some more error checking but not sure how to handle that. Possibly catch an exception and draw some ERROR text instead of the CrankWheel object.

Interesting starting from 0 with the Gear library code and having to almost toss it all out, but got something more solid after the 3 rewrite of the generator :D

More questions coming I can feel it...

Thanks and Happy Holidays

Sandy

sandyg
Junior Member
Posts: 20
Joined: Thu Dec 12, 2019 10:49 pm

Re: Help with Round operation

Post by sandyg » Mon Dec 30, 2019 3:44 am

Should have put a link to the GitHub project in this thread too - https://github.com/sganz/CrankWheel

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

Re: Help with Round operation

Post by CVH » Mon Dec 30, 2019 7:02 am

Again:
among all, Round.js is present in compiled form in all general installations.
If you make use of it you probably have to 'include' it at the top off your code.
You don't have to physically include the script file, its part of Qcad.

And indeed, if in Math.tan(abc) the abc NEVER can be 90° or 270° your are save.
ECMAScript would return something huge but not infinite
In your math it all depends on spokeAngle, a0 and a1.
Not being able to be the limits is even better than an error check.

Cheers,
CVH

sandyg
Junior Member
Posts: 20
Joined: Thu Dec 12, 2019 10:49 pm

Re: Help with Round operation

Post by sandyg » Mon Dec 30, 2019 4:59 pm

The problem I had with trying to include the Round.js script was trying to figure out how to write the include. I tried a few different paths, but could never get it to work as it would always crash the script with just the include. I tried a few different paths but could never get it to work.

One thing to remember is that I'm not installing the script directly in the QCAD library directory which also might be a problem to use scripts that are prebuilt. Not totally sure. Some more exploration will need to be done on my part.

Sandy

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

Re: Help with Round operation

Post by CVH » Mon Dec 30, 2019 5:22 pm

OK,

I see ... you have the same problem as I have.
Windows ?!! Sure.
Did you pass by the UAC asking to save in a protected system folder...??
Search for a folder 'protected storage' on your OS drive.
If any with a Qcad entry, your in trouble

Works sometimes:
Try to include the path starting from scripts.
Build up the path as it occurs at GIT.
eg. "scripts/File/File.js"
Even without a subfolder File this will work as a copy of the script is build in.
simply Files.js wont work.

And if anything else fails:
Just put a recent copy from GIT including the parrent structure up to the path scripts.
Put a remark with your include statement saying you copied the file physically.

Once my script was released with Qcad all was functional without physical copies of the scripts
Next project, again I had to drag copies in place......

Bottom line.
If it doesn't work out: copy the file in place.
Once comming from an installation all is fine.
Read top of FlexPainter.js

Regards,
CVH

sandyg
Junior Member
Posts: 20
Joined: Thu Dec 12, 2019 10:49 pm

Re: Help with Round operation

Post by sandyg » Thu Jan 02, 2020 5:34 pm

I got tired trying to updated or copy code into the deployed QCAD directory, so just added my directory to the library path and made it easier to test deploy code changes.

Seems like, as you said, it will pick up the includes if in the proper system directory (where QCAD is deployed) I tried the proper include directories but It didn't work for me since I didn't have the sources loaded up on my dev box. Getting pretty far without using the rounding stuff yet. I still have a few more hacks to make before I attempt that. I think you can go a long way with the polyline and the bulge but it won't work in some cases for me since the Round operation does some different work on the lines then bulge does.

I'll take a look at flexpainter as well.

Thanks
Sandy

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

Re: Help with Round operation

Post by CVH » Thu Jan 02, 2020 6:52 pm

Well, looked into it.
You will almost always have to include some or other qcad resourses.
Round.js would be one.

Code: Select all

include("scripts/Modify/Round/Round.js");
>> ECMAScript is very picky about typos !!
>> Again: As such you are save even if it won't work overthere without the file physically in place.

After publication, FlexPainter worked without the files in place. :shock:
BUT Starting a new endeavour I am back at moving resources back in :!: :?: :?:

Taking the ModifyCorner.js route, again itself:

Code: Select all

include("scripts/Modify/ModifyCorner.js");
Taking the math route if your good at it like it seems:

Code: Select all

new RArc(centerRv, Radius, startAngle, endAngle, reversed)
Then, you still have to cast the arc into the drawing.
The easy way would be:

Code: Select all

simple_create.js
addArc(center, radius, startAngle, endAngle, reversed)
And then you have to include simple.js:

Code: Select all

include("scripts/simple.js");    // Added for simple API
    //# Issue Solved # Use "scripts/simple.js" instead of "simple.js"
    // See; https://qcad.org/rsforum/viewtopic.php?t=6528
That will include all 'simple' subs itself.

Just get it working with proper includes and it will work for everyone.
If the function you use fails to locate itself:
Copy the file from GIT in place with its parent structure up to 'scripts'.

I understand you would like to isolate your work for now.
finally it will need a proper place in the Qcad project following the project manner.

You can swim upstream if you want to, downstream is a lot easier.
Don't take this the hard way, I mean this as practical.


And BTW it should work perfect with bulges too:
Lets take any somewhat closed form as a string of Lines.
Adding a rounding is simply adding an Arc in between.
Not any Arc but an Arc that is tangent at both neighbours.
Any string of Lines and Arcs is simply a Polyline.
The bulge is then perfectly related at the difference in direction of both neighbours.
The neighbours themselves needs to be shortenned reffering the centerpoint perpendicular.
Math for bulge-arc-center is pritty forward.

Math for bulges is already a part of the Qcad resourses.
For that you have to include ..... got it?


Regards,
CVH

sandyg
Junior Member
Posts: 20
Joined: Thu Dec 12, 2019 10:49 pm

Re: Help with Round operation

Post by sandyg » Sat Jan 04, 2020 2:57 am

I will have to go through this carefully. A lot to digest!

I thought about doing the Rounding operation with bulges but would have to calculate the points in the polyline differently. Would have to shorten the lines a bit and add additional points and the bulge would work just fine, I have updated the code to an official v1.0.0 on GitHub.

Hopefully I can get some more time to work on it, work in full force on Monday.

Sandy

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

Re: Help with Round operation

Post by CVH » Sat Jan 04, 2020 10:33 am

This might help.
Round2Bulge.dxf
(107.12 KiB) Downloaded 739 times
Regards,
CVH

sandyg
Junior Member
Posts: 20
Joined: Thu Dec 12, 2019 10:49 pm

Re: Help with Round operation

Post by sandyg » Mon Jan 06, 2020 4:58 pm

CVH -

That totally will help. I'm going to see if I can fiddle with the drawing code to see how much work it will be. I am testing the software with my a project for my engine, and sent out a design generated with it to the laser cutting shop. I did the Rounding by hand, but I'll see how much pain it will be to add a couple of segments on the first and last tooth section of the drawing to see if I can compute things up.

I have updated the code a bit on GitHub over the weekend.

Sandy

Post Reply

Return to “QCAD 'Script Add-On & Plug-in challenge' - Work in Progress”