# simple linux cam

*Grotius*on topic

*simple linux cam*

> 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.

*Reinhard*on topic

*simple linux cam*

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.

*Reinhard*on topic

*simple linux cam*

```
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.

*Reinhard*on topic

*simple linux cam*

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.

*Reinhard*on topic

*simple linux cam*

##### Attachments:

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

*Thorhian*on topic

*simple linux cam*

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

*Reinhard*on topic

*simple linux cam*

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.

*Thorhian*on topic

*simple linux cam*

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

*Reinhard*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.

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.

*Thorhian*on topic

*simple linux cam*

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.

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