QT C++ code samples

More
7 years 3 months ago #140950 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi,

Today i started with calculating the outside contour offset of a product. To compensate kerf width for plasma
and milling. Calculating the inside offset has the same principle. This example is for lines at this moment.
Finding circle and arc intersection's is the next level to do.

Attached i a picture of a product 100x100mm that have 2 lines that are offset 5mm from the product.
To find the new closed contour point, see the yellow circle, we have to do a calculation for finding this point. It's called intersection point.



The C++ code sample :
Warning: Spoiler!


The tested console output :

determinant is : -2495
intersection point is x : 52.097 y : 105


So nice that this works !!

Attached the QT intersection project in zip format.
Attachments:
The following user(s) said Thank You: chimeno, tommylight

Please Log in or Create an account to join the conversation.

More
7 years 3 months ago - 7 years 3 months ago #140971 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi,

Thanks to chimeno & tommylight !

Me was lucky today... Made the circle and line intersection code ready quite quickly...

Attached a QT project for searching the intersecting point of a line and a circle.
This basic code can be a template for intersecting lines with arc's too.

The cad drawing with a line and a circle. The red dimension lines are calculated by the C++ code.


The C++ code :
Warning: Spoiler!


The console output of this example :

Two solutions x1 : 9.55418 y1 : 5.75232
Two solutions x2 : 3.14394 y2 : 2.19108


This Circle and line intersecting QT C++ project is attached for downloading.

Another offset example :

In this example we got a 5mm outside offset for the product.
The green lines are done by the line-line intersection methode in my previous post today.
If we see a line followed by an arc in the memory array, we do a line-circle intersection like below.
Offset of the arc is 5mm.



Code :
Warning: Spoiler!


Console output :
Two solutions x1 : 90.4489 y1 : 66.7792
Two solutions x2 : 66.6837 y2 : 90.3977


We need the closest solution. The closest founded intersection point related to the line. We can make a little formula for that with if, else.

The yellow circle is the calculated intersection point of a line collision with an arc. :woohoo:
Attachments:
Last edit: 7 years 3 months ago by Grotius.

Please Log in or Create an account to join the conversation.

More
7 years 3 months ago - 7 years 3 months ago #140976 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi,

The last item to investegate was find the intersecting point of a circle with a circle.

Cad drawing of product with a contour offset 5mm. Find where the 2 circle's collide..


Attached QT C++ project find intersection circle to circle.

File Attachment:

File Name: QT_circle_...tion.zip
File Size:49 KB


console output :
intersection x1 : 74.0697 y1 : 57.5247
intersection x2 : 92.4753 y2 : 75.9303


We have 2 solution's. We calculate wich one we need with a if else statement.

What do we do with the tiny line in within the red circle? Delete it automaticly?

The QT C++ code for intersecting circle to circle :
Warning: Spoiler!


Okey we have to go on with the next level.
Add contour offset's to the product.....

The swap class needs some improvement's, but i will try add some contour offsets first.
We have classes for line-line, line-circle and arc-arc interceptions. Without that we where lost.
But now we have more power to make offsets. B)



Glad to be back to the relaxed DxfDecoder screen.
Attachments:
Last edit: 7 years 3 months ago by Grotius.
The following user(s) said Thank You: tommylight, emilvv

Please Log in or Create an account to join the conversation.

More
7 years 3 months ago - 7 years 2 months ago #141110 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi,

Today i have a C++ example for finding a new xy offset point of a certain line. In this example the offset is 10mm.

We have the x0,y0 (0,0) and x1,y1 (200,100) points. This are the points that form the blue product line C.
We have to calculate the offset point of the blue line, see yellow circle.

Visualisation of the calculation..


Attached the QT project for this example, the zip includes the cad drawing.
The C++ code spoiler down here has some updated code... Don't forget this...

File Attachment:

File Name: QT_offset_...oint.zip
File Size:45 KB


Console output :
this calculation is between 0 and 180 degrees, the new x is : 204.472 new y is : 91.0557 (alpha 3)

The output in DxfDecoder. Tested in all quadrants. The calculated point is the endpoint of the short blue line wich has
the offset lenght of 10mm in this case. The blue line is perpendicular to the base line. The yellow lines are opposites of the blue line.
The yellow line was founded by only a + and - calculation related to the blue line.


This is nice !!

We can now draw a offset line with opengl.
After that, we can do the intersection calculation for line-line to close the contour... Yes yes..

These separate software step's (tutorials) combined (in total) will result in the base code for a complex contour offset algoritme.
Don't forget the power of Linux !! B) It's all in the game...

C++ code: (angle1 = alpha1 and so on)
Warning: Spoiler!



For a quick test we add the offset lines to the opengl class :

Later on we will copy this test to a new class and keep the opengl as clean as possible.

Next item is to execute the intersection line-line class forum.linuxcnc.org/41-guis/36768-qt-c-co...ples?start=60#140950 to find all the intersection point's... This we will do tomorrow !

If i look at the current output, we can use this for generating press brake products..
Last edit: 7 years 2 months ago by Grotius.
The following user(s) said Thank You: phillc54, tommylight

Please Log in or Create an account to join the conversation.

More
7 years 2 months ago #141188 by Grotius
Replied by Grotius on topic QT C++ code samples
Hi,

We got the contour offset algoritme working now for a line-line contour offset of only one product at the moment.

It works nice !!



Coming time we can expand this algoritme with the already tested line-arc and arc-arc intersection classes. (see previous posts).
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
7 years 2 months ago - 7 years 2 months ago #141207 by Grotius
Replied by Grotius on topic QT C++ code samples
Thank you Phill and Tommy,

I hope soon we make progress. It's a long way to the top for sure... B)

We have a closed contour, and i was curious about other cam program's so i tested this example in sheetcam.

Sheetcam output :


Dxfdecoder output :


Why has sheetcam no full output for this example?

Another example of a more complex shape :
Sheetcam output :


DxfDecoder output :


Okey a while ago i learned from Rodw how to use Switch state's in C, used for custom linux plasma component's that time.
I integrated the switch statement as C code into the C++ dxfdecoder project to startup a structure that deals with multiple contour offset's and mutiple intersection types, like line-line, line-arc, arc-arc and visa versa.
The finishing touch of a nice program that can do contour offset's needs this structure now...

WIth the knowlegde we now have, we could make a open source autocad program, with more function's for sure !!
We only have to add some student's for help coding the program.

Or a program like facebook or watsapp. Or a improvement of youtube called mytube...
Or something else. Can be almost everything.. A global window's 7 update destroyer looks funny to make, but it's not legal to write program's with this purpose this day's. It's only legal if you carry the name America and write some Stuxnet code that involves innocent pc's worldwide. Then it's legal...

In the store i can only buy a new pc with a American Window's Licence. It's to crazy to be true.
This must change soon. It's not a fair trade...

The last time we did a software stress test. Now this one. What is left?
Last edit: 7 years 2 months ago by Grotius.
The following user(s) said Thank You: phillc54, tommylight, bkt, rodw

Please Log in or Create an account to join the conversation.

Time to create page: 1.779 seconds
Powered by Kunena Forum