simple linux cam

More
09 Apr 2022 05:40 #239710 by Grotius
Replied by Grotius on topic simple linux cam
Hi Reinhard,

> did you watch any of the videos?
Yes i have seen the video's when you posted them.

> Now I have to cut the cyan segments only, using expensive maths.

I scrambled together a example for you. It's a general approach for your app.
But certainly not the fastest algo on the market.

#include "ElCLib/ElCLib.hxx"
#include "GeomAPI_IntCS.hxx"
#include "Geom_Curve.hxx"
#include "Geom_Surface.hxx"
#include "TopoDS_Face.hxx"
#include "BRepBuilderAPI_MakeFace.hxx"
#include "gp_Cylinder.hxx"
#include "BRepAdaptor_HSurface.hxx"
#include "GC_MakeLine.hxx"

//! Create a line, GC_ has different curve's.
gp_Pnt depart(-200,0,0);
gp_Dir direction(200,0,0);
GC_MakeLine mkLine(depart, direction);

//! Create the raw material cube surface.
gp_Cylinder cil(gp::XOY(),100);
TopoDS_Face cylinder_face = BRepBuilderAPI_MakeFace(cil);

//! Do a line-face intersection.
BRepAdaptor_Surface surface(cylinder_face);
const GeomAdaptor_Surface& geomAdapSurf = surface.Surface();
const Handle(Geom_Surface)& geomSurf = geomAdapSurf.Surface();

GeomAPI_IntCS inCS;
inCS.Perform(mkLine.Value(),geomSurf);

if (inCS.IsDone()){
    if (inCS.NbPoints() == 0){
        std::cout<<"no intersections."<<std::endl;
    } else {
        for(int i=1; i<inCS.NbPoints()+1; i++){
            gp_Pnt p = inCS.Point(i);
            std::cout<<"Px:"<<p.X()<< " Py:" << p.Y() << " Pz:" << p.Z() <<std::endl;
        }
    }
};

Output :
Px:100.000000 Py:0.000000 Pz:0.000000
Px:-100.000000 Py:0.000000 Pz:0.000000
 

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

More
09 Apr 2022 06:22 #239712 by Reinhard
Replied by Reinhard on topic simple linux cam
Hi,

i am not yet so desperate that i would accept such a stupid solution. I thought you were a math specialist, but something like this is - sorry - beginner level.

Maybe I can find a real math pro who is willing to help me.

Currently, I have discovered another (similar) solution that is nicely much better (but also worse). No idea what is wrong there.
With the new variant I could cut at least 4 of 6 segments correctly:
 
Attachments:

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

More
09 Apr 2022 06:27 #239713 by Reinhard
Replied by Reinhard on topic simple linux cam
Here's the code (as separate post):
Handle(Geom_Line) line = Handle(Geom_Line)::DownCast(c);
     qDebug() << "cutCurve (line):" << first << " | " << last << " <> " << orientation;
     double dx  = p1.X() - p0.X();
     double dy  = p1.Y() - p0.Y();
     double gf  = dy / dx;
     double cf  = rMaster / sqrt(1 + gf * gf);
     double dr  = sqrt(dx * dx + dy * dy);
     double D   = p0.X() * p1.Y() - p1.X() * p0.Y();
     double res = rMaster * rMaster * dr * dr - D * D;
     double sig = dy < 0 ? -1 : 1;
     double cx0 = cf * gf;
     double cy0 = -cf;
     double cx1 = -cx0;
     double cy1 = -cy0;
     double x0  = ( D * dy + sig * dx * sqrt(res)) / (dr * dr);
     double x1  = ( D * dy - sig * dx * sqrt(res)) / (dr * dr);
     double y0  = (-D * dx + abs(dy)  * sqrt(res)) / (dr * dr);
     double y1  = (-D * dx + abs(dy)  * sqrt(res)) / (dr * dr);
     double col = first + (last - first) / 2;

     if (res <= 0) qDebug() << "OUPS - fine calculations means no cutpoints?!?";
     qDebug() << "cutpoints: " << cx0 << " / " << cy0
              <<   "   and   " << cx1 << " / " << cy1;
     qDebug() << "alt cp: "  << x0 << " / " << y0
              << "   and   " << x1 << " / " << y1;

//     Core().view3D()->createAxisCross({cx0, cy0, 0}, 2, nullptr, Quantity_NOC_BLACK);
//     Core().view3D()->createAxisCross({cx1, cy1, 0}, 2, nullptr, Quantity_NOC_WHITE);
     Core().view3D()->createAxisCross({x0, y0, 0}, 2, nullptr, Quantity_NOC_BLACK);
     Core().view3D()->createAxisCross({x1, y1, 0}, 2, nullptr, Quantity_NOC_WHITE);

//     double param0 = ElCLib::Parameter(line->Lin(), {cx0, cy0, p0.Z()});
//     double param1 = ElCLib::Parameter(line->Lin(), {cx1, cy1, p0.Z()});
     double param0 = ElCLib::Parameter(line->Lin(), {x0, y0, p0.Z()});
     double param1 = ElCLib::Parameter(line->Lin(), {x1, y1, p0.Z()});

     if (param0 >= first && param0 <= last) {
        qDebug() << "<<< first cutpoint is part of line segment ==> "
                 << first << " <> "  << param0 << " <> " << last << "orientation:" << orientation;
        if (param0 < col) {
           qDebug() << "\tsecond part is part of interest";
           edge = BRepBuilderAPI_MakeEdge(c, {x0, y0, p0.Z()}, p1);
           }
        else {
           qDebug() << "\tfirst part is part of interest";
           edge = BRepBuilderAPI_MakeEdge(c, p0, {x0, y0, p0.Z()});
           }
        }
     else if (param1 >= first && param1 <= last) {
        qDebug() << ">>> second cutpoint is part of line segment ==> "
                 << first << " <> "  << param1 << " <> " << last << "orientation:" << orientation;
        if (param1 < col) {
           qDebug() << "\tsecond part is part of interest";
           edge = BRepBuilderAPI_MakeEdge(c, {x1, y1, p0.Z()}, p1);
           }
        else {
           qDebug() << "\tfirst part is part of interest";
           edge = BRepBuilderAPI_MakeEdge(c, p0, {x1, y1, p0.Z()});
           }
        }
     else {
        qDebug() << "?!?!? - none of the calculated cutpoints is inside of line parameters?!?"
                 << first << " <> " << param0 << "|" << param1 << last;
        edge = BRepBuilderAPI_MakeEdge(c, first, last);
        }
     }

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

More
09 Apr 2022 14:22 #239734 by Reinhard
Replied by Reinhard on topic simple linux cam
Hi,

I found a nice page about math basics for circle intersetions . Based on that I created my own formulas matching the opencascade classes.
The best of it - it works to 100% - it clipped all arcs as expected. Whoohoo :)
 
Attachments:

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

More
10 Apr 2022 02:58 #239797 by Reinhard
Replied by Reinhard on topic simple linux cam
Hi,

The background info on the "radical line" was sufficient to solve both problems by myself. Now clipping of lines and circles works :)
 
Attachments:

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

More
12 Apr 2022 00:50 #240002 by Thorhian
Replied by Thorhian on topic simple linux cam
Hi Reinhard! I just wanted to thank you for this awesome work you’ve done so far. I’ve followed some of FreeCADs path development, and it’s nice to see other people interested in FOSS CAM programming. Just know that I’m rooting for you and the people working on FreeCAD as well. Also, I’m no math expert, so I don’t think I can help too much (yet), but starting towards the end of last year I started a project to make a prototype 3D adaptive roughing algorithm, utilizing OpenGL shader code to do some of the heavy lifting. It’s in Python besides the small amount of GLSL code, but at some point I want to port it to C++ or Rust once I actually get the Python prototype to make real tool paths. I’ve only got some of the core rendering done along with some functions for checking pixels with a given capsule shape (two circles with the same radius and a rectangle that has two lines tangential with the circles) to use when I finally sit down to start working on the tool path generation. The repo is here github.com/Thorhian/Path_Tinkering , but I haven’t figured out what license to use yet. Probably LGPL for FreeCAD compatibility but I haven’t decided yet. I bet you would be welcome on the gitter chat for the FreeCAD workbench too BTW. 
The following user(s) said Thank You: silopolis

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

More
12 Apr 2022 02:59 #240005 by Reinhard
Replied by Reinhard on topic simple linux cam
Hi Thorhian,

thank you for your interest! I already solved my math problems and I have lot more problems in using opencascade in a proper way. opencascade is like a russian doll - when you reach to understand a level, you realize, that there is another level below, that does other fancy things that break your work.

So there's quite a lot I stil have to learn. I'm sorry, but I don't have time to worry about freecad or python. I started using opencascade, for not having to bother with opengl.

Don't know - may be that was a wrong decision. May be I should decrease usage of opencascade and do more math on my own?
Sadly I don't know other opencascade developers to share ideas - and opencascade forum is not helpful.

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

More
12 Apr 2022 04:30 #240009 by Thorhian
Replied by Thorhian on topic simple linux cam
I mean, FreeCAD uses a lot of Python, but at its core it uses open cascade as well. It wouldn’t surprise me if you found some devs who know a good amount about it in the overall community.

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

More
12 Apr 2022 13:56 #240045 by Reinhard
Replied by Reinhard on topic simple linux cam
Hi,

I mean, FreeCAD uses a lot of Python, but at its core it uses open cascade as well. It wouldn’t surprise me if you found some devs who know a good amount about it in the overall community.


Yes, you're right. Didn't though of that.
So what do you mean with gitter chat? I'm a noob with chat things

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

More
12 Apr 2022 17:48 - 12 Apr 2022 17:55 #240063 by Thorhian
Replied by Thorhian on topic simple linux cam
Gitter is basically just a fancy chat client that some open source projects use. You can access it on your browser. You can use your GitHub account to login to it as well if you want. gitter.im/FreeCAD/FreeCAD?utm_source=sha..._campaign=share-link 

It is linked to their IRC chat too, which I believe is on the Libera server if I remember correctly. 

Just know that I found this thread and project because someone from the LCNC community posted it in FreeCAD’s Path workbench gitter chat. I believe it was CaptHindsight. 
Last edit: 12 Apr 2022 17:55 by Thorhian.

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

Moderators: Skullworks
Time to create page: 0.281 seconds
Powered by Kunena Forum