0027664: Incomplete intersection curve from the attached shapes
[occt.git] / src / IntPatch / IntPatch_CSFunction.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
f62de372 15
42cf5bc1 16#include <Adaptor2d_HCurve2d.hxx>
f62de372 17#include <Adaptor3d_HSurface.hxx>
18#include <Adaptor3d_HSurfaceTool.hxx>
7fd59977 19#include <gp_Pnt.hxx>
7fd59977 20#include <gp_Pnt2d.hxx>
42cf5bc1 21#include <gp_Vec.hxx>
7fd59977 22#include <gp_Vec2d.hxx>
42cf5bc1 23#include <IntPatch_CSFunction.hxx>
24#include <IntPatch_HCurve2dTool.hxx>
25#include <math_Matrix.hxx>
7fd59977 26
0797d9d3 27#ifndef OCCT_DEBUG
7fd59977 28#define No_Standard_RangeError
29#define No_Standard_OutOfRange
30#endif
31
32
f62de372 33#define SURFACE1 (*((Handle(Adaptor3d_HSurface) *)(surface1)))
34#define SURFACE2 (*((Handle(Adaptor3d_HSurface) *)(surface2)))
35#define CURVE (*((Handle(Adaptor2d_HCurve2d) *)(curve)))
7fd59977 36
f62de372 37IntPatch_CSFunction::IntPatch_CSFunction(const Handle(Adaptor3d_HSurface)& S1,
38 const Handle(Adaptor2d_HCurve2d)& C,
39 const Handle(Adaptor3d_HSurface)& S2)
7fd59977 40{
41 surface1 = (Standard_Address)(&S1);
42 surface2 = (Standard_Address)(&S2);
43 curve = (Standard_Address)(&C);
7dc9a407 44 f = 0.;
7fd59977 45}
46
f62de372 47Standard_Integer IntPatch_CSFunction::NbVariables()const { return 3;}
7fd59977 48
f62de372 49Standard_Integer IntPatch_CSFunction::NbEquations()const { return 3;}
7fd59977 50
f62de372 51Standard_Boolean IntPatch_CSFunction::Value(const math_Vector& X,
7fd59977 52 math_Vector& F){
53
f62de372 54 gp_Pnt Psurf(Adaptor3d_HSurfaceTool::Value(SURFACE1,X(1),X(2)));
55 gp_Pnt2d p2d(IntPatch_HCurve2dTool::Value(CURVE,X(3)));
56 gp_Pnt Pcurv(Adaptor3d_HSurfaceTool::Value(SURFACE2,p2d.X(),p2d.Y()));
7fd59977 57
58 F(1) = Psurf.X()-Pcurv.X();
59 F(2) = Psurf.Y()-Pcurv.Y();
60 F(3) = Psurf.Z()-Pcurv.Z();
61 f = F(1)*F(1)+ F(2)*F(2)+ F(3)*F(3);
62 p = gp_Pnt((Psurf.XYZ()+Pcurv.XYZ())/2.);
63 return Standard_True;
64}
65
f62de372 66Standard_Boolean IntPatch_CSFunction::Derivatives ( const math_Vector& X,
7fd59977 67 math_Matrix& D) {
68 gp_Pnt Psurf,Pcurv;
69 gp_Vec D1u,D1v,D1w;
70 gp_Pnt2d p2d;
71 gp_Vec2d d2d;
72 gp_Vec d1u,d1v;
73
f62de372 74 Adaptor3d_HSurfaceTool::D1(SURFACE1,X(1),X(2),Psurf,D1u,D1v);
75 IntPatch_HCurve2dTool::D1(CURVE,X(3),p2d,d2d);
76 Adaptor3d_HSurfaceTool::D1(SURFACE2,p2d.X(),p2d.Y(),Pcurv,d1u,d1v);
7fd59977 77 D1w.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
78
79 D(1,1) = D1u.X();
80 D(1,2) = D1v.X();
81 D(1,3) = -D1w.X();
82 D(2,1) = D1u.Y();
83 D(2,2) = D1v.Y();
84 D(2,3) = -D1w.Y();
85 D(3,1) = D1u.Z();
86 D(3,2) = D1v.Z();
87 D(3,3) = -D1w.Z();
88 return Standard_True;
89}
90
f62de372 91Standard_Boolean IntPatch_CSFunction::Values( const math_Vector& X,
7fd59977 92 math_Vector& F,
93 math_Matrix& D) {
94 gp_Pnt Psurf,Pcurv;
95 gp_Vec D1u,D1v,D1w;
96
97 gp_Pnt2d p2d;
98 gp_Vec2d d2d;
99 gp_Vec d1u,d1v;
100
f62de372 101 Adaptor3d_HSurfaceTool::D1(SURFACE1,X(1),X(2),Psurf,D1u,D1v);
102 IntPatch_HCurve2dTool::D1(CURVE,X(3),p2d,d2d);
103 Adaptor3d_HSurfaceTool::D1(SURFACE2,p2d.X(),p2d.Y(),Pcurv,d1u,d1v);
7fd59977 104 D1w.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
105
106 D(1,1) = D1u.X();
107 D(1,2) = D1v.X();
108 D(1,3) = -D1w.X();
109 D(2,1) = D1u.Y();
110 D(2,2) = D1v.Y();
111 D(2,3) = -D1w.Y();
112 D(3,1) = D1u.Z();
113 D(3,2) = D1v.Z();
114 D(3,3) = -D1w.Z();
115 F(1) = Psurf.X()-Pcurv.X();
116 F(2) = Psurf.Y()-Pcurv.Y();
117 F(3) = Psurf.Z()-Pcurv.Z();
118 f = F(1)*F(1)+ F(2)*F(2)+ F(3)*F(3);
119 p = gp_Pnt((Psurf.XYZ()+Pcurv.XYZ())/2.);
120 return Standard_True;
121}
122
f62de372 123const gp_Pnt& IntPatch_CSFunction::Point() const { return p;}
7fd59977 124
f62de372 125Standard_Real IntPatch_CSFunction::Root() const { return f;}
7fd59977 126
857ffd5e 127const Handle(Adaptor3d_HSurface)& IntPatch_CSFunction::AuxillarSurface() const {
7fd59977 128 return SURFACE1;}
129
857ffd5e 130const Handle(Adaptor2d_HCurve2d)& IntPatch_CSFunction::AuxillarCurve() const {
7fd59977 131 return CURVE;}
132
133#undef SURFACE1
134#undef SURFACE2
135#undef CURVE