simple linux cam

More
4 years 6 months ago #239699 by Grotius
Replied by Grotius on topic simple linux cam
Hi Reinhard,

So far looks good to me.
If you have any questions, no problem. If not too difficult i always try to provide info.

To inform.
I am trying to write a little c++ library.
The main goal is to provide some math functions for 3d.

Like finding intersection points. Trim objects etc for 3d geometry.

The idea came up when i was reverse engineering Draftsight with Ghidra and Ida past week.
I looked at the Api of Draftsight with Ghidra & Ida.
There are no secrets when opening a Elf file with these powerfull programs.

For now i came up with the example below, you can see a "Object" is created.
I like the idea that the Object is capable of intersecting different types on it's own. Like intersecting arc with line etc.

Also i came up with the idea of subclassing the gp_Pnt to gp_PntVec to create a array on the fly.
Code:
OBJECT *lineA = new OBJECT(); lineA->setType(TYPE::line); lineA->setPoints({{0,50,0},{100,50,0}}); occt_viewer->show_shape(lineA->getShape()); OBJECT *lineB = new OBJECT(); lineB->setType(TYPE::line); lineB->setPoints({{50,0,0},{50,100,0}}); occt_viewer->show_shape(lineB->getShape()); gp_PntVec pvec; lineA->getIntersections(*lineB,pvec); pvec.push_back({100,1,1}); // To show the gp_Pnt vector usage. pvec.print(); Output : gp_PntVec at i:0 Value x: 50.000000 y: 50.000000 z: 0.000000 gp_PntVec at i:1 Value x: 100.000000 y: 1.000000 z: 1.000000
More
4 years 6 months ago #239705 by Reinhard
Replied by Reinhard on topic simple linux cam
Hi,

> So far looks good to me.

did you watch any of the videos?

> Like finding intersection points.

Something very strange is going on with opencascade boolean. The splitter only returns original wire, but no error nor warning and intersection creates cutpoints at locations, where no curve is :(

So I created a cutalgo for the workpiece. With some quick checks I sort the segments of the curve into 3 groups:
  • completely inside the workpiece (rendered black)
  • completely outside the workpiece (rendered white)
  • possibly intersection (rendered cyan)
Now I have to cut the cyan segments only, using expensive maths.
 

It looks like "standard" maths leads to different result, than opencascade maths, so I have to dive deeper into that stuff :(
More
4 years 6 months ago #239706 by Reinhard
Replied by Reinhard on topic simple linux cam
Hi,

I don't know what to do anymore.
Here's the result of calculations. At first step I dedicated to cutting straight lines only (rendered in purple).
6 lines so 12 possible cutpoints. The cutpoints calculated are the little crosses at circle border.
To understand what's going on, I loaded a screenshot in incscape, where I extended the lines to cut.
4 lines seem to got the correct cutpoint, but only at the wrong side. The other cutpoints have no visual relation to any curve segment.

Does anybody have an idea, what I did wrong?
 
More
4 years 6 months ago #239707 by Reinhard
Replied by Reinhard on topic simple linux cam
... and here's the code:
Code:
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 cx0 = cf * gf; double cy0 = -cf; double cx1 = -cx0; double cy1 = -cy0; if (res <= 0) qDebug() << "OUPS - fine calculations means no cutpoints?!?"; qDebug() << "cutpoints: " << cx0 << " / " << cy0 << " and " << cx1 << " / " << cy1; Core().view3D()->createAxisCross({cx0, cy0, 0}, 2, nullptr, Quantity_NOC_BLACK); Core().view3D()->createAxisCross({cx1, cy1, 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()}); if (param0 >= first && param0 <= last) { qDebug() << "first cutpoint is part of line segment ==> " << first << " <> " << param0 << " <> " << last; // edge = BRepBuilderAPI_MakeEdge(c, {cx0, cy0, p0.Z()}, p1); } else if (param1 >= first && param1 <= last) { qDebug() << "second cutpoint is part of line segment ==> " << first << " <> " << param1 << " <> " << last; // edge = BRepBuilderAPI_MakeEdge(c, p0, {cx1, cy1, p0.Z()}); } else { qDebug() << "?!?!? - none of the calculated cutpoints is inside of line parameters?!?" << first << " <> " << param0 << "|" << param1 << last; edge = BRepBuilderAPI_MakeEdge(c, first, last); }
More
4 years 6 months ago #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
 
More
4 years 6 months ago #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:
 
Time to create page: 0.273 seconds
Powered by Kunena Forum