MantisBT - Community
View Issue Details
0031047Community[OCCT] OCCT:Modeling Algorithmspublic2019-10-08 17:392021-05-04 14:33
g++ 9.2.0Windows7
[OCCT] 7.4.0 
[OCCT] 7.6.0* 
0031047: Modeling Algorithms - BRepExtrema_DistShapeShape gives wrong result
The 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".
#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"
No tags attached.
? Face.brep (118,509) 2019-10-08 17:39
Issue History
2019-10-08 17:39BenjaminBihlerNew Issue
2019-10-08 17:39BenjaminBihlerAssigned To => msv
2019-10-08 17:39BenjaminBihlerFile Added: Face.brep
2019-10-10 08:28BenjaminBihlerNote Added: 0087997
2019-10-14 16:06msvNote Added: 0088107
2019-10-14 16:06msvSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=22043#r22043
2019-10-14 16:28msvNote Added: 0088108
2019-10-14 16:28msvSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=22044#r22044
2019-10-14 16:29msvAssigned Tomsv => ifv
2019-10-14 16:29msvStatusnew => assigned
2019-10-15 09:33MechanicoderNote Added: 0088128
2019-10-15 09:47msvNote Added: 0088129
2019-10-15 09:49msvNote Edited: 0088129bug_revision_view_page.php?bugnote_id=88129#r22048
2019-10-15 09:51BenjaminBihlerNote Added: 0088130
2019-10-15 10:01msvNote Added: 0088131
2019-10-17 14:44MechanicoderNote Added: 0088255
2019-10-17 14:52msvNote Added: 0088258
2019-12-17 13:48kgvSummaryBRepExtrema_DistShapeShape gives wrong result => Modeling Algorithms - BRepExtrema_DistShapeShape gives wrong result
2020-09-15 16:27msvTarget Version7.5.0 => 7.6.0*
2020-09-17 09:55ifvAssigned Toifv => akulagin
2021-03-04 16:59ifvAssigned Toakulagin => abulyche
2021-04-12 13:23gitNote Added: 0100240
2021-04-15 13:38gitNote Added: 0100314
2021-04-16 08:19gitNote Added: 0100327
2021-04-19 18:09gitNote Added: 0100461
2021-04-19 18:51gitNote Added: 0100462
2021-05-04 14:33gitNote Added: 0100760

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

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的人很少能读中文。 请使用英文撰写您的帖子。

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,
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.
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!
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.
2021-04-12 13:23   
Branch CR31047 has been created by andrey.bulychev.ext_170479.

SHA-1: 9c0eb1cf5264cd754c21b9e68c7908d228fe3006

Detailed log of new commits:

Author: abulyche
Date: Mon Apr 12 13:13:14 2021 +0300

    0031047: Modeling Algorithms - BRepExtrema_DistShapeShape gives wrong result
    Added map of edges to BrepClass_Edge
    Added searching of vertices with high tolerance to BrepClass_Intersector.cxx
2021-04-15 13:38   
Branch CR31047 has been updated forcibly by andrey.bulychev.ext_170479.

SHA-1: 0663d7a83f43d2b78db58bad85a9768e908f16a0
2021-04-16 08:19   
Branch CR31047 has been updated forcibly by andrey.bulychev.ext_170479.

SHA-1: ccc1e1bb78af4509d38b0e6e33277ac027773d18
2021-04-19 18:09   
Branch CR31047 has been updated forcibly by andrey.bulychev.ext_170479.

SHA-1: 418eb40ed5a534226fd5cdfc81daf5c2592962aa
2021-04-19 18:51   
Branch CR31047 has been updated forcibly by andrey.bulychev.ext_170479.

SHA-1: a59a277961e71a7e384a79e856413b30f7b98128
2021-05-04 14:33   
Branch CR31047 has been updated forcibly by andrey.bulychev.ext_170479.

SHA-1: 39332472e3be1ccf6fd7a2831bf6b87146ccd3e5