Skip to content

Curvature Calculation Inaccurate for B-Spline Curves in DiffGeomCurve Class #30

@stp34650

Description

@stp34650

Description:

The current implementation of the curvature function in the DiffGeomCurve class from OCC.Utils.edge_py appears to provide inaccurate results when applied to B-spline curves. While the function successfully calculates curvature for circular edges, it consistently returns a value of 0 for B-spline curves, indicating inaccurate behavior.

Steps to Reproduce:

  1. Obtain the attached TXT file (sin_curve.txt) containing a B-spline representation of a sine curve.
  2. Change the file extension from .txt to .step.
  3. Load the STEP file using pythonocc.
  4. Obtain the curvature of the B-spline curve using the curvature function from the DiffGeomCurve class.

Expected Behavior:

The curvature function should accurately compute the curvature of B-spline curves, providing meaningful non-zero values consistent with the curvature of the curve at various points.

Actual Behavior:

The curvature function consistently returns 0 when applied to B-spline curves, while it correctly computes curvature for circular edges. This discrepancy indicates inaccurate behavior specific to B-spline curves.

Code Snippet:

from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_EDGE
from OCC.Core.GCPnts import GCPnts_UniformAbscissa
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve
from OCC.Core.TDocStd import TDocStd_Document
from OCC.Core.XCAFDoc import XCAFDoc_DocumentTool
from OCC.Core.STEPCAFControl import STEPCAFControl_Reader
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Core.TDF import TDF_LabelSequence

from OCCUtils.edge import Edge


doc = TDocStd_Document("pythonocc-doc")
shape_tool = XCAFDoc_DocumentTool.ShapeTool(doc.Main())

step_reader = STEPCAFControl_Reader()
step_reader.SetNameMode(True)

status = step_reader.ReadFile("sin_curve.step")
if status != IFSelect_RetDone:
    raise IOError("Failed to read STEP file")

step_reader.Transfer(doc)
labels = TDF_LabelSequence()
shape_tool.GetFreeShapes(labels)

shape = shape_tool.GetShape(labels.Value(1))

explorer = TopExp_Explorer(shape, TopAbs_EDGE)
while explorer.More():
    edge = explorer.Current()
    curve_adaptor = BRepAdaptor_Curve(edge)
    curve_edge = Edge(edge)
    curvatures = []
    _lower_bound, _upper_bound = curve_adaptor.FirstParameter(), curve_adaptor.LastParameter()

    num_eval_points = 100
    npts = GCPnts_UniformAbscissa(curve_adaptor, num_eval_points, _lower_bound, _upper_bound)
    if npts.IsDone():
        for i in range(1, npts.NbPoints() + 1):
            param = npts.Parameter(i)
            curvature = curve_edge.DiffGeom.curvature(param)
            curvatures.append(curvature)
            # Print or store the curvature value at each evaluation point
            print("Parameter:", param, "Curvature:", curvature)

    # Print all curvature values calculated for the current edge
    print("Curvatures for current edge:", curvatures)

    explorer.Next()

Geometry File:

Changed the file ending to .txt as Github doesn't allow uploads of .step files.
Attached TXT file: sin_curve.txt

Any assistance from the community in diagnosing and resolving this issue would be greatly appreciated. Thank you in advance for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions