1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
19 #include <Prs3d_Arrow.ixx>
20 #include <Graphic3d_Group.hxx>
21 #include <Graphic3d_ArrayOfSegments.hxx>
22 #include <Graphic3d_ArrayOfPolylines.hxx>
24 //=======================================================================
27 //=======================================================================
29 void Prs3d_Arrow::Draw(const Handle(Prs3d_Presentation)& aPresentation,
30 const gp_Pnt& aLocation,
31 const gp_Dir& aDirection,
32 const Quantity_PlaneAngle anAngle,
33 const Quantity_Length aLength)
35 Quantity_Length dx,dy,dz; aDirection.Coord(dx,dy,dz);
37 // Point of the arrow:
38 Quantity_Length xo,yo,zo; aLocation.Coord(xo,yo,zo);
40 // Center of the base circle of the arrow:
41 Quantity_Length xc = xo - dx * aLength;
42 Quantity_Length yc = yo - dy * aLength;
43 Quantity_Length zc = zo - dz * aLength;
45 // Construction of i,j mark for the circle:
46 Quantity_Length xn=0., yn=0., zn=0.;
48 if ( Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) xn=1.;
49 else if ( Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) yn=1.;
51 Quantity_Length xi = dy * zn - dz * yn;
52 Quantity_Length yi = dz * xn - dx * zn;
53 Quantity_Length zi = dx * yn - dy * xn;
55 Quantity_Length Norme = sqrt ( xi*xi + yi*yi + zi*zi );
56 xi = xi / Norme; yi = yi / Norme; zi = zi/Norme;
58 const Quantity_Length xj = dy * zi - dz * yi;
59 const Quantity_Length yj = dz * xi - dx * zi;
60 const Quantity_Length zj = dx * yi - dy * xi;
62 const Standard_Integer NbPoints = 15;
64 Handle(Graphic3d_ArrayOfSegments) aPrims1 = new Graphic3d_ArrayOfSegments(2*NbPoints);
65 Handle(Graphic3d_ArrayOfPolylines) aPrims2 = new Graphic3d_ArrayOfPolylines(NbPoints+1);
68 const Standard_Real Tg=tan(anAngle);
70 for (Standard_Integer i = 1; i <= NbPoints ; i++)
72 const Standard_Real cosinus = cos ( 2 * M_PI / NbPoints * (i-1) );
73 const Standard_Real sinus = sin ( 2 * M_PI / NbPoints * (i-1) );
75 const gp_Pnt pp(xc + (cosinus * xi + sinus * xj) * aLength * Tg,
76 yc + (cosinus * yi + sinus * yj) * aLength * Tg,
77 zc + (cosinus * zi + sinus * zj) * aLength * Tg);
79 aPrims1->AddVertex(aLocation);
80 aPrims1->AddVertex(pp);
82 aPrims2->AddVertex(pp);
84 aPrims2->AddVertex(p1);
86 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims1);
87 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims2);
90 //=======================================================================
93 //=======================================================================
95 void Prs3d_Arrow::Fill(const Handle(Prs3d_Presentation)& /*aPresentation*/,
96 const gp_Pnt& /*aLocation*/,
97 const gp_Dir& /*aDirection*/,
98 const Quantity_PlaneAngle /*anAngle*/,
99 const Quantity_Length /*aLength*/)