Create normal to a face
=======================
-.. literalinclude:: examples/createNormalToFace.py
+.. literalinclude:: examples/create_normal_to_face.py
:linenos:
:language: python
-:download:`Download this script <examples/createNormalToFace.py>`
+:download:`Download this script <examples/create_normal_to_face.py>`
.. _tui_create_normal_to_face_at_vertex:
Create normal to a face at vertex
=================================
-.. literalinclude:: examples/createNormalToFaceAtVertex.py
+.. literalinclude:: examples/create_normal_to_face_at_vertex.py
:linenos:
:language: python
-:download:`Download this script <examples/createNormalToFaceAtVertex.py>`
\ No newline at end of file
+:download:`Download this script <examples/create_normal_to_face_at_vertex.py>`
+++ /dev/null
-from salome.shaper import model
-import os
-
-model.begin()
-Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
-model.do()
-
-### Create BoundingBox
-Normal_1 = model.getNormal(Part_1_doc, model.selection("FACE", "Box_1_1/Top"))
-model.do()
-
-model.end()
+++ /dev/null
-
-from salome.shaper import model
-import os
-
-model.begin()
-Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
-model.do()
-
-Normal_1 = model.getNormal(Part_1_doc, model.selection("FACE", "Box_1_1/Front"), model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Right][Box_1_1/Bottom]"))
-model.do()
-
-model.end()
--- /dev/null
+from salome.shaper import model
+import os
+
+model.begin()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+model.do()
+
+### Create BoundingBox
+Normal_1 = model.getNormal(Part_1_doc, model.selection("FACE", "Box_1_1/Top"))
+model.do()
+
+model.end()
--- /dev/null
+
+from salome.shaper import model
+import os
+
+model.begin()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+model.do()
+
+Normal_1 = model.getNormal(Part_1_doc, model.selection("FACE", "Box_1_1/Front"), model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Right][Box_1_1/Bottom]"))
+model.do()
+
+model.end()
#include <TopoDS_Iterator.hxx>
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
+#include <ShapeAnalysis.hxx>
#include <ShapeAnalysis_Surface.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepBndLib.hxx>
// Point
gp_Pnt p1 (0,0,0);
+ // Point parameters on surface
+ double u1, u2, v1, v2;
+ Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
+ Handle(ShapeAnalysis_Surface) aSurfAna = new ShapeAnalysis_Surface (aSurf);
+ gp_Ax3 aPos = GetPosition(aFace);
+ p1 = aPos.Location();
+ // Set default starting point using UV bounds
+ ShapeAnalysis::GetFaceUVBounds(aFace, u1, u2, v1, v2);
+ gp_Pnt2d pUV ((u2 + u1) * 0.5, (v2 + v1) * 0.5);
+ // Change to Vertex coord if selected
if (theOptionnelPoint.get()) {
TopoDS_Shape anOptPnt = theOptionnelPoint->impl<TopoDS_Shape>();
if (anOptPnt.IsNull()) {
return false;
}
p1 = BRep_Tool::Pnt(TopoDS::Vertex(anOptPnt));
- } else {
- gp_Ax3 aPos = GetPosition(aFace);
- p1 = aPos.Location();
+ pUV = aSurfAna->ValueOfUV(p1, Precision::Confusion());
}
- // Point parameters on surface
- Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
- Handle(ShapeAnalysis_Surface) aSurfAna = new ShapeAnalysis_Surface (aSurf);
- gp_Pnt2d pUV = aSurfAna->ValueOfUV(p1, Precision::Confusion());
-
// Normal direction
gp_Vec Vec1,Vec2;
BRepAdaptor_Surface SF (aFace);