Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0031047Community[OCCT] OCCT:Modeling Algorithmspublic2019-10-08 17:392020-09-17 09:55
Assigned Toakulagin 
Platformg++ 9.2.0OSWindowsOS Version7
Product Version[OCCT] 7.4.0 
Target Version[OCCT] 7.6.0*Fixed in Version 
Summary0031047: Modeling Algorithms - BRepExtrema_DistShapeShape gives wrong result
DescriptionThe distance of a vertex to a face is computed. It should be zero, but it is computed to be 47.1989. I use mingw-w64 with g++ 9.2.0, but this actually shouldn't make a difference. Please see the code in "Steps To Reproduce".
Steps To Reproduce#script 1 - test DistShapeShape

restore Face.brep f
vertex v1 -79 -282.7 0
copy v1 v2
ttranslate v2 0 0.1 0
distmini d1 f v1
distmini d2 f v2
set dist1 [dval d1_val]
set dist2 [dval d2_val]
puts "dist1=$dist1"
puts "dist2=$dist2"
if {$dist1 != $dist2} {
  puts "Error: both distances must be equal to 0"

#script 2 - test BRepClass_FaceClassifier

restore Face.brep f
point p1 -79 -282.7
point p2 -79 -282.6
if ![regexp "IN" [b2dclassify f p1]] {
  puts "Error: inner point p1 is classified as OUT"
if ![regexp "IN" [b2dclassify f p2]] {
  puts "Error: inner point p2 is classified as OUT"
TagsNo tags attached.
Test case number
Attached Files? file icon Face.brep (118,509 bytes) 2019-10-08 17:39

- Relationships

-  Notes
BenjaminBihler (developer)
2019-10-10 08:28

A slight translation of the test point makes the distance measurement work. At least I can use this here to detect whether my measurement is wrong in a special test case. See this code for the disturbed (and therefore correct) calculation:

#include <TopoDS_Face.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <TopoDS.hxx>
#include <Precision.hxx>
#include <TopExp_Explorer.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>

#include <string>
#include <vector>
#include <iostream>

int main(int, char*[])
    BRep_Builder builder;
    TopoDS_Shape face;

    BRepTools::Read(face, "Face.brep", builder);

    gp_Pnt testPoint1(-79.14602309143586467143904883414507,

    BRepExtrema_DistShapeShape distanceComputer1(
            BRepBuilderAPI_MakeVertex(testPoint1), face);

    if (distanceComputer1.IsDone())
        std::cout << "Calculated Distance = " << distanceComputer1.Value()
                << std::endl;
        if (distanceComputer1.Value() > Precision::Confusion())
            std::cout << "This is wrong! The distance should be (close to) zero."
                    << std::endl;
        std::cout << "Calculation failed." << std::endl;

    std::cout << std::endl << "Translating test point..." << std::endl;

    gp_Pnt testPoint2 = testPoint1.Translated(gp_Vec(0.0, 0.1, 0.0));

    BRepExtrema_DistShapeShape distanceComputer2(
            BRepBuilderAPI_MakeVertex(testPoint2), face);

    if (distanceComputer2.IsDone())
        std::cout << "Calculated Distance = " << distanceComputer2.Value()
                << std::endl;
        if (distanceComputer2.Value() > Precision::Confusion())
            std::cout << "This is wrong! The distance should be (close to) zero."
                    << std::endl;
        std::cout << "Calculation failed." << std::endl;

    return 0;
msv (developer)
2019-10-14 16:06

I have updated steps to reproduce with a simple draw script.
It gives the error in the current OCCT version.
msv (developer)
2019-10-14 16:28

The cause of the bug is incorrect work of BRepClass_FaceClassifier. See script 2 in steps to reproduce.

The possible fix is to use BRepTopAdaptor_FClass2d for classification.
Mechanicoder (reporter)
2019-10-15 09:33

调用过程:BrepExtrema_DistShapeShape->BrepExtrema_DistSS->BrepExt_ExtFF->Extrema_GenExtSS, 最后一个步骤中,均匀取了20*20个离散点并求最近点对,进而确定Extrema_FunDistSS, math_BFGS的初始值,进行求解。根据该步骤所求的结果,计算对应曲面上的法向量,发现两个法向量夹角为180.005°。

msv (developer)
2019-10-15 09:47
edited on: 2019-10-15 09:49

Dear Mechanocider,
Very few people who uses this bugtracker can read Chinese. Please use English for your posts.

使用此bugtracker的人很少能读中文。 请使用英文撰写您的帖子。

BenjaminBihler (developer)
2019-10-15 09:51

Dear msv,

are BRepClass_FaceClassifier and BRepTopAdaptor_FClass2d serving the same purpose? Is BRepTopAdaptor_FClass2d more correct/stable? This post [^] seems to indicate that it is faster. But I have found no more information on that.

Thank you,
msv (developer)
2019-10-15 10:01

BRepTopAdaptor_FClass2d tries to use discrete representation of the boundary to solve the problem using just intersections of linear segments. In case of point located too close to bounds it calls geometric classifier BRepClass_FaceClassifier.
Mechanicoder (reporter)
2019-10-17 14:44

Dear msv,

I need to calculate distance between two surfaces, one is VPeriodic surface and another is surface of revolution. The two surfaces are clearly intersecting while BRepExtrema_DistShapeShape give the result 0.088, it's wrong.

My code like this:

    BRepExtrema_DistShapeShape ext;
    if (ext.IsDone())
        double dist = ext.Value();

I debuged sources and got the following simplified call stack:
    DistanceMapMap(myMapF1, myMapF2, myBF1, myBF2)
Then I got two closest points(UV(1),UV(2),UV(3),UV(4)) from Extrema_GenExtSS::Perform(). I calculated normal directions from the two specified points on corresponding surface, and the angle between the two direction is 180.005°。丷丷

And I think 20*20 sampling points for start point is not enough about this situation.

Test version:7.3.0

Sorry I cannot give you a test case. sorry for my bad posts.

Thank you so much!
msv (developer)
2019-10-17 14:52

Dear Mechanicoder, now your post is much clearer :). Thank you.
However, it is better to work with each bug in a separate ticket. The current one is about distance between vertex and face. Your case is distance between two faces. So, I kindly ask you to create a new bug with shapes to reproduce the problem. Without your particular shapes we hardly can reproduce it, and so cannot fix.

- Issue History
Date Modified Username Field Change
2019-10-08 17:39 BenjaminBihler New Issue
2019-10-08 17:39 BenjaminBihler Assigned To => msv
2019-10-08 17:39 BenjaminBihler File Added: Face.brep
2019-10-10 08:28 BenjaminBihler Note Added: 0087997
2019-10-14 16:06 msv Note Added: 0088107
2019-10-14 16:06 msv Steps to Reproduce Updated View Revisions
2019-10-14 16:28 msv Note Added: 0088108
2019-10-14 16:28 msv Steps to Reproduce Updated View Revisions
2019-10-14 16:29 msv Assigned To msv => ifv
2019-10-14 16:29 msv Status new => assigned
2019-10-15 09:33 Mechanicoder Note Added: 0088128
2019-10-15 09:47 msv Note Added: 0088129
2019-10-15 09:49 msv Note Edited: 0088129 View Revisions
2019-10-15 09:51 BenjaminBihler Note Added: 0088130
2019-10-15 10:01 msv Note Added: 0088131
2019-10-17 14:44 Mechanicoder Note Added: 0088255
2019-10-17 14:52 msv Note Added: 0088258
2019-12-17 13:48 kgv Summary BRepExtrema_DistShapeShape gives wrong result => Modeling Algorithms - BRepExtrema_DistShapeShape gives wrong result
2020-09-15 16:27 msv Target Version 7.5.0 => 7.6.0*
2020-09-17 09:55 ifv Assigned To ifv => akulagin

Copyright © 2000 - 2020 MantisBT Team
Powered by Mantis Bugtracker