pythonocc-core icon indicating copy to clipboard operation
pythonocc-core copied to clipboard

Curve approximation of Wire leads to varying end results

Open Thieso opened this issue 4 years ago • 0 comments

Hello,

I have a wire and I want to sample from it. For this, I convert it to a curve and then sample from that. The problem is that the approximated curve only covers part of the wire. The part that is covers differs between different runs of the programs which is very odd to me.

I checked that the input wire is the same every time by plotting it using the pythonOCC display. The wire is extracted from a STEP file where it is a curve on a surface.

Basically what I am doing is the following:

  c = BRepAdaptor_CompCurve()                                                                                                                                                   
  c.Initialize(wire, True)                                                                                                                                                         
  curve = BRepAdaptor_HCompCurve(c)                                                                                                                                              
  # compute length of curve for sampling                                                                                                                                                                     
  approx = Approx_Curve3d(curve, 0.001, GeomAbs_Shape.GeomAbs_C2, 1000, 25)                                                                                                                                  
  geom_curve = approx.Curve()                                                                                                                                                                                
  adaptor_curve = GeomAdaptor_Curve(geom_curve)                                                                                                                                                              
  l = GCPnts_AbscissaPoint_Length(adaptor_curve)                                                                                                                                                             
  # sample from curve using                                                                                                                                                                                  
  nr_sample_points = int(sample_resolution * l)                                                                                                                                                              
  sampled_curve = []                                                                                                                                                                                         
  point_samples_local = []                                                                                                                                                                                   
  for j in np.linspace(curve.FirstParameter(), curve.LastParameter(), nr_sample_points):                                                                                                                     
      p = curve.Value(j)                                                                                                                                                                                     
      point_samples_local.append(p)                                                                                                                                                                          
      sampled_curve.append([p.X(), p.Y(), p.Z()])                                                                                                                                                            
  self.sampled_curves.append(np.array(sampled_curve))                                                                                                                                                        
  self.point_samples.append(point_samples_local) 

Can you tell me where I am going wrong? Or what a better way might be to solve this problem?

Thanks for the help

Thieso avatar Jun 11 '21 07:06 Thieso