1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

2
src/gp/FILES Normal file
View File

@@ -0,0 +1,2 @@
gp_QuaternionNLerp.hxx
gp_QuaternionSLerp.hxx

300
src/gp/gp.cdl Executable file
View File

@@ -0,0 +1,300 @@
-- File: gp.cdl
-- Created: Tue Apr 13 12:42:16 1993
-- Author: JCV
-- <fid@mastox>
-- Copyright: Matra Datavision 1993
---Copyright: Matra Datavision 1991
package gp
--- Purpose :
-- The geometric processor package, called gp, provides an
-- implementation of entities used :
-- . for algebraic calculation such as "XYZ" coordinates, "Mat"
-- matrix
-- . for basis analytic geometry such as Transformations, point,
-- vector, line, plane, axis placement, conics, and elementary
-- surfaces.
-- These entities are defined in 2d and 3d space.
-- All the classes of this package are non-persistent.
uses Standard, TColStd
is
exception VectorWithNullMagnitude inherits DomainError;
---Purpose: Identifies the type of a geometric transformation.
enumeration TrsfForm is
Identity, Rotation, Translation, PntMirror, Ax1Mirror, Ax2Mirror, Scale,
CompoundTrsf, Other;
---Purpose: Enumerates all 24 possible variants of generalized
-- Euler angles, defining general 3d rotation by three
-- rotations around main axes of coordinate system,
-- in different possible orders.
-- The name of the enumeration
-- corresponds to order of rotations, prefixed by type
-- of co-ordinate system used:
-- - Intrinsic: rotations are made around axes of rotating
-- co-ordinate system associated with the object
-- - Extrinsic: rotations are made around axes of fixed
-- (reference) co-ordinate system
-- Two specific values provided for most frequently used
-- conventions: proper Euler angles (intrinsic ZXZ) and
-- yaw-pitch-roll (intrinsic ZYX).
enumeration EulerSequence is
EulerAngles, -- standard Euler angles, alias to Intrinsic_ZXZ
YawPitchRoll, -- Yaw Pitch Roll angles, alias to Intrinsic_ZYX
-- Tait-Bryan angles (using three different axes)
Extrinsic_XYZ,
Extrinsic_XZY,
Extrinsic_YZX,
Extrinsic_YXZ,
Extrinsic_ZXY,
Extrinsic_ZYX,
Intrinsic_XYZ,
Intrinsic_XZY,
Intrinsic_YZX,
Intrinsic_YXZ,
Intrinsic_ZXY,
Intrinsic_ZYX,
-- proper Euler angles (using two different axes, first and third the same)
Extrinsic_XYX,
Extrinsic_XZX,
Extrinsic_YZY,
Extrinsic_YXY,
Extrinsic_ZYZ,
Extrinsic_ZXZ,
Intrinsic_XYX,
Intrinsic_XZX,
Intrinsic_YZY,
Intrinsic_YXY,
Intrinsic_ZXZ,
Intrinsic_ZYZ
;
class XYZ;
--- Purpose : 3D Cartesian Coordinates {X, Y, Z}
class Mat;
--- Purpose : Matrix 3*3
class Quaternion;
--- Purpose : Quaternion representing 3d rotation
class Trsf;
--- Purpose :
-- Elementary geometric transformation. This transformation never
-- change the nature of the objects.
class GTrsf;
--- Purpose :
-- General transformation. A GTrsf can be used only to transform
-- a point or a triplet of coordinates.
class Pnt;
--- Purpose : Cartesian Point.
class Vec;
--- Purpose : Vector.
class Dir;
--- Purpose : Direction, it is an unitary vector.
class Ax1;
--- Purpose : axis placement (Coordinate system -one axis)
class Ax2;
--- Purpose : axis placement (Direct Coordinate system two
-- axis)
class Ax3;
--- Purpose : axis placement (Coordinate system two axis, can
-- be direct or indirect)
class Lin;
--- Purpose : Line.
class Circ;
--- Purpose : Circle.
class Elips;
--- Purpose : Ellipse.
class Hypr;
--- Purpose : Hyperbola.
class Parab;
--- Purpose : Parabola.
class Pln;
--- Purpose : Plane.
class Cylinder;
--- Purpose : Infinite cylindrical surface .
class Sphere;
--- Purpose : Spherical surface.
class Torus;
--- Purpose : Toroidal surface.
class Cone;
--- Purpose : Conical surface.
--- Purpose : Geometric entities for 2D.
class XY;
--- Purpose : 2D cartesian Coordinates {X, Y}
class Mat2d;
--- Purpose : Matrix 2*2
class Trsf2d;
--- Purpose :
-- Elementary geometric transformation. This transformation never
-- change the nature of the objects.
class GTrsf2d;
--- Purpose :
-- General transformation. A GTrsf can be used only to transform
-- a point or a triplet of coordinates.
class Pnt2d;
--- Purpose : Cartesian point.
class Vec2d;
--- Purpose : Vector.
class Dir2d;
--- Purpose : Direction, it is an unitary vector.
class Ax2d;
--- Purpose : axis placement (Coordinate system - one axis)
class Ax22d;
--- Purpose : axis placement (Coordinate system - two axis)
class Lin2d;
--- Purpose : Line.
class Circ2d;
--- Purpose : Circle.
class Elips2d;
--- Purpose : Ellipse.
class Hypr2d;
--- Purpose : Hyperbola.
class Parab2d;
--- Purpose : Parabola.
--- Purpose : Method of package gp
Resolution returns Real;
--- Purpose :
-- In geometric computations, defines the tolerance criterion
-- used to determine when two numbers can be considered equal.
-- Many class functions use this tolerance criterion, for
-- example, to avoid division by zero in geometric
-- computations. In the documentation, tolerance criterion is
-- always referred to as gp::Resolution().
---C++: inline
Origin returns Pnt from gp;
--- Purpose : Identifies a Cartesian point with coordinates X = Y = Z = 0.0.0
---C++: return const &
DX returns Dir from gp;
---Purpose: Returns a unit vector with the combination (1,0,0)
---C++: return const &
DY returns Dir from gp;
---Purpose: Returns a unit vector with the combination (0,1,0)
---C++: return const &
DZ returns Dir from gp;
---Purpose: Returns a unit vector with the combination (0,0,1)
---C++: return const &
OX returns Ax1 from gp;
--- Purpose :Identifies an axis where its origin is Origin
-- and its unit vector coordinates X = 1.0, Y = Z = 0.0
---C++: return const &
OY returns Ax1 from gp;
--- Purpose :Identifies an axis where its origin is Origin
-- and its unit vector coordinates Y = 1.0, X = Z = 0.0
---C++: return const &
OZ returns Ax1 from gp;
--- Purpose :Identifies an axis where its origin is Origin
-- and its unit vector coordinates Z = 1.0, Y = X = 0.0
---C++: return const &
XOY returns Ax2 from gp;
--- Purpose :Identifies a coordinate system where its origin is Origin,
-- and its "main Direction" and "X Direction" coordinates
-- Z = 1.0, X = Y =0.0 and X direction coordinates X = 1.0, Y = Z = 0.0
---C++: return const &
ZOX returns Ax2 from gp;
--- Purpose :Identifies a coordinate system where its origin is Origin,
-- and its "main Direction" and "X Direction" coordinates
-- Y = 1.0, X = Z =0.0 and X direction coordinates Z = 1.0, X = Y = 0.0
---C++: return const &
YOZ returns Ax2 from gp;
--- Purpose :Identifies a coordinate system where its origin is Origin,
-- and its "main Direction" and "X Direction" coordinates
-- X = 1.0, Z = Y =0.0 and X direction coordinates Y = 1.0, X = Z = 0.0
---C++: return const &
--- Purpose : In 2D space
Origin2d returns Pnt2d from gp;
--- Purpose : Identifies a Cartesian point with coordinates X = Y = 0.0
---C++: return const &
DX2d returns Dir2d from gp;
---Purpose: Returns a unit vector with the combinations (1,0)
---C++: return const &
DY2d returns Dir2d from gp;
---Purpose: Returns a unit vector with the combinations (0,1)
---C++: return const &
OX2d returns Ax2d from gp;
--- Purpose : Identifies an axis where its origin is Origin2d
-- and its unit vector coordinates are: X = 1.0, Y = 0.0
---C++: return const &
OY2d returns Ax2d from gp;
--- Purpose : Identifies an axis where its origin is Origin2d
-- and its unit vector coordinates are Y = 1.0, X = 0.0
---C++: return const &
end gp;

167
src/gp/gp.cxx Executable file
View File

@@ -0,0 +1,167 @@
#include <gp.ixx>
//=======================================================================
//function : Origin
//purpose :
//=======================================================================
const gp_Pnt& gp::Origin()
{
static gp_Pnt gp_Origin(0,0,0);
return gp_Origin;
}
//=======================================================================
//function : DX
//purpose :
//=======================================================================
const gp_Dir& gp::DX()
{
static gp_Dir gp_DX(1,0,0);
return gp_DX;
}
//=======================================================================
//function : DY
//purpose :
//=======================================================================
const gp_Dir& gp::DY()
{
static gp_Dir gp_DY(0,1,0);
return gp_DY;
}
//=======================================================================
//function : DZ
//purpose :
//=======================================================================
const gp_Dir& gp::DZ()
{
static gp_Dir gp_DZ(0,0,1);
return gp_DZ;
}
//=======================================================================
//function : OX
//purpose :
//=======================================================================
const gp_Ax1& gp::OX()
{
static gp_Ax1 gp_OX(gp_Pnt(0,0,0),gp_Dir(1,0,0));
return gp_OX;
}
//=======================================================================
//function : OY
//purpose :
//=======================================================================
const gp_Ax1& gp::OY()
{
static gp_Ax1 gp_OY(gp_Pnt(0,0,0),gp_Dir(0,1,0));
return gp_OY;
}
//=======================================================================
//function : OZ
//purpose :
//=======================================================================
const gp_Ax1& gp::OZ()
{
static gp_Ax1 gp_OZ(gp_Pnt(0,0,0),gp_Dir(0,0,1));
return gp_OZ;
}
//=======================================================================
//function : XOY
//purpose :
//=======================================================================
const gp_Ax2& gp::XOY()
{
static gp_Ax2 gp_XOY(gp_Pnt(0,0,0),gp_Dir(0,0,1),gp_Dir(1,0,0));
return gp_XOY;
}
//=======================================================================
//function : ZOX
//purpose :
//=======================================================================
const gp_Ax2& gp::ZOX()
{
static gp_Ax2 gp_ZOX(gp_Pnt(0,0,0),gp_Dir(0,1,0),gp_Dir(0,0,1));
return gp_ZOX;
}
//=======================================================================
//function : YOZ
//purpose :
//=======================================================================
const gp_Ax2& gp::YOZ()
{
static gp_Ax2 gp_YOZ(gp_Pnt(0,0,0),gp_Dir(1,0,0),gp_Dir(0,1,0));
return gp_YOZ;
}
//=======================================================================
//function : Origin2d
//purpose :
//=======================================================================
const gp_Pnt2d& gp::Origin2d()
{
static gp_Pnt2d gp_Origin2d(0,0);
return gp_Origin2d;
}
//=======================================================================
//function : DX2d
//purpose :
//=======================================================================
const gp_Dir2d& gp::DX2d()
{
static gp_Dir2d gp_DX2d(1,0);
return gp_DX2d;
}
//=======================================================================
//function : DY2d
//purpose :
//=======================================================================
const gp_Dir2d& gp::DY2d()
{
static gp_Dir2d gp_DY2d(0,1);
return gp_DY2d;
}
//=======================================================================
//function : OX2d
//purpose :
//=======================================================================
const gp_Ax2d& gp::OX2d()
{
static gp_Ax2d gp_OX2d(gp_Pnt2d(0,0),gp_Dir2d(1,0));
return gp_OX2d;
}
//=======================================================================
//function : OY2d
//purpose :
//=======================================================================
const gp_Ax2d& gp::OY2d()
{
static gp_Ax2d gp_OY2d(gp_Pnt2d(0,0),gp_Dir2d(0,1));
return gp_OY2d;
}

7
src/gp/gp.lxx Executable file
View File

@@ -0,0 +1,7 @@
// File: gp.lxx
// Created: Tue Jul 21 13:39:10 1992
inline Standard_Real gp::Resolution ()
{
return RealSmall();
}

228
src/gp/gp_Ax1.cdl Executable file
View File

@@ -0,0 +1,228 @@
---Copyright: Matra Datavision 1991
class Ax1 from gp inherits Storable
--- Purpose : Describes an axis in 3D space.
-- An axis is defined by:
-- - its origin (also referred to as its "Location point"), and
-- - its unit vector (referred to as its "Direction" or "main Direction").
-- An axis is used:
-- - to describe 3D geometric entities (for example, the
-- axis of a revolution entity). It serves the same purpose
-- as the STEP function "axis placement one axis", or
-- - to define geometric transformations (axis of
-- symmetry, axis of rotation, and so on).
-- For example, this entity can be used to locate a geometric entity
-- or to define a symmetry axis.
uses Ax2 from gp,
Dir from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
is
Create returns Ax1;
---C++: inline
--- Purpose : Creates an axis object representing Z axis of
-- the reference co-ordinate system.
Create (P : Pnt; V : Dir) returns Ax1;
---C++: inline
--- Purpose :
-- P is the location point and V is the direction of <me>.
SetDirection (me : in out; V : Dir) is static;
---C++: inline
--- Purpose : Assigns V as the "Direction" of this axis.
SetLocation (me : in out; P : Pnt) is static;
---C++: inline
--- Purpose : Assigns P as the origin of this axis.
Direction (me) returns Dir is static;
---C++: inline
---C++: return const&
--- Purpose : Returns the direction of <me>.
Location(me) returns Pnt is static;
---C++: inline
---C++: return const&
--- Purpose : Returns the location point of <me>.
IsCoaxial (me; Other : Ax1; AngularTolerance, LinearTolerance : Real)
returns Boolean
is static;
--- Purpose :
-- Returns True if :
-- . the angle between <me> and <Other> is lower or equal
-- to <AngularTolerance> and
-- . the distance between <me>.Location() and <Other> is lower
-- or equal to <LinearTolerance> and
-- . the distance between <Other>.Location() and <me> is lower
-- or equal to LinearTolerance.
IsNormal (me; Other : Ax1; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- Returns True if the direction of the <me> and <Other>
-- are normal to each other.
-- That is, if the angle between the two axes is equal to Pi/2.
-- Note: the tolerance criterion is given by AngularTolerance..
IsOpposite (me; Other : Ax1; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- Returns True if the direction of <me> and <Other> are
-- parallel with opposite orientation. That is, if the angle
-- between the two axes is equal to Pi.
-- Note: the tolerance criterion is given by AngularTolerance.
IsParallel (me; Other : Ax1; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- Returns True if the direction of <me> and <Other> are
-- parallel with same orientation or opposite orientation. That
-- is, if the angle between the two axes is equal to 0 or Pi.
-- Note: the tolerance criterion is given by
-- AngularTolerance.
Angle (me; Other : Ax1) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the angular value, in radians, between <me>.Direction() and
-- <Other>.Direction(). Returns the angle between 0 and 2*PI
-- radians.
Reverse (me : in out) is static;
---C++: inline
--- Purpose : Reverses the unit vector of this axis.
-- and assigns the result to this axis.
Reversed (me) returns Ax1 is static;
---C++: inline
--- Purpose : Reverses the unit vector of this axis and creates a new one.
Mirror (me : in out; P : Pnt) is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to the point P which is the
-- center of the symmetry and assigns the result to this axis.
Mirrored (me; P : Pnt) returns Ax1 is static;
--- Purpose : Performs the symmetrical transformation of an axis
-- placement with respect to the point P which is the
-- center of the symmetry and creates a new axis.
Mirror (me : in out; A1 : Ax1) is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to an axis placement which
-- is the axis of the symmetry and assigns the result to this axis.
Mirrored (me; A1 : Ax1) returns Ax1 is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to an axis placement which
-- is the axis of the symmetry and creates a new axis.
Mirror (me : in out; A2 : Ax2) is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to a plane. The axis placement
-- <A2> locates the plane of the symmetry :
-- (Location, XDirection, YDirection) and assigns the result to this axis.
Mirrored (me; A2 : Ax2) returns Ax1 is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to a plane. The axis placement
-- <A2> locates the plane of the symmetry :
-- (Location, XDirection, YDirection) and creates a new axis.
Rotate (me : in out; A1 : Ax1; Ang : Real)
---C++: inline
---Purpose: Rotates this axis at an angle Ang (in radians) about the axis A1
-- and assigns the result to this axis.
is static;
Rotated (me; A1 : Ax1; Ang : Real) returns Ax1 is static;
---C++: inline
---Purpose: Rotates this axis at an angle Ang (in radians) about the axis A1
-- and creates a new one.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++: inline
---Purpose:
-- Applies a scaling transformation to this axis with:
-- - scale factor S, and
-- - center P and assigns the result to this axis.
Scaled (me; P : Pnt; S : Real) returns Ax1 is static;
---C++: inline
---Purpose:
-- Applies a scaling transformation to this axis with:
-- - scale factor S, and
-- - center P and creates a new axis.
Transform (me : in out; T : Trsf)
---C++: inline
---Purpose: Applies the transformation T to this axis.
-- and assigns the result to this axis.
is static;
Transformed (me; T : Trsf) returns Ax1 is static;
---C++: inline
--- Purpose:
-- Applies the transformation T to this axis and creates a new one.
--- Purpose :
-- Translates an axis plaxement in the direction of the vector
-- <V>. The magnitude of the translation is the vector's magnitude.
Translate (me : in out; V : Vec)
---C++: inline
---Purpose:
-- Translates this axis by the vector V,
-- and assigns the result to this axis.
is static;
Translated (me; V : Vec) returns Ax1 is static;
---C++: inline
---Purpose:
-- Translates this axis by the vector V,
-- and creates a new one.
Translate (me : in out; P1, P2 : Pnt)
---C++: inline
---Purpose:
-- Translates this axis by:
-- the vector (P1, P2) defined from point P1 to point P2.
-- and assigns the result to this axis.
is static;
Translated (me; P1, P2 : Pnt) returns Ax1 is static;
---C++: inline
---Purpose:
-- Translates this axis by:
-- the vector (P1, P2) defined from point P1 to point P2.
-- and creates a new one.
fields
loc : Pnt;
vdir : Dir;
end;

68
src/gp/gp_Ax1.cxx Executable file
View File

@@ -0,0 +1,68 @@
// File gp_Ax1.cxx, JCV 30/08/90
//
// JCV 1/10/90 Changement de nom du package vgeom -> gp
// JCV 12/12/90 modif introduction des classes XYZ et Mat dans le package
// LPA, JCV 07/92 passage sur C1.
// JCV 07/92 Introduction de la method Dump
#define No_Standard_OutOfRange
#include <gp_Ax1.ixx>
#include <gp.hxx>
Standard_Boolean gp_Ax1::IsCoaxial
(const gp_Ax1& Other,
const Standard_Real AngularTolerance,
const Standard_Real LinearTolerance) const
{
gp_XYZ XYZ1 = loc.XYZ();
XYZ1.Subtract (Other.loc.XYZ());
XYZ1.Cross (Other.vdir.XYZ());
Standard_Real D1 = XYZ1.Modulus();
gp_XYZ XYZ2 = Other.loc.XYZ();
XYZ2.Subtract (loc.XYZ());
XYZ2.Cross (vdir.XYZ());
Standard_Real D2 = XYZ2.Modulus();
return (vdir.IsEqual (Other.vdir, AngularTolerance) &&
D1 <= LinearTolerance && D2 <= LinearTolerance);
}
void gp_Ax1::Mirror (const gp_Pnt& P)
{
loc.Mirror(P);
vdir.Reverse();
}
gp_Ax1 gp_Ax1::Mirrored (const gp_Pnt& P) const
{
gp_Ax1 A1 = *this;
A1.Mirror (P);
return A1;
}
void gp_Ax1::Mirror (const gp_Ax1& A1)
{
loc.Mirror(A1);
vdir.Mirror(A1.vdir);
}
gp_Ax1 gp_Ax1::Mirrored (const gp_Ax1& A1) const
{
gp_Ax1 A = *this;
A.Mirror (A1);
return A;
}
void gp_Ax1::Mirror (const gp_Ax2& A2)
{
loc.Mirror (A2);
vdir.Mirror (A2);
}
gp_Ax1 gp_Ax1::Mirrored (const gp_Ax2& A2) const
{
gp_Ax1 A1 = *this;
A1.Mirror (A2);
return A1;
}

115
src/gp/gp_Ax1.lxx Executable file
View File

@@ -0,0 +1,115 @@
// File gp_Ax1.lxx, JCV 30/08/90
// JCV, LPA 07/92
inline gp_Ax1::gp_Ax1() : loc(0.,0.,0.), vdir(0.,0.,1.)
{ }
inline gp_Ax1::gp_Ax1 (const gp_Pnt& P,
const gp_Dir& V) : loc(P), vdir(V)
{ }
inline void gp_Ax1::SetDirection (const gp_Dir& V)
{ vdir = V; }
inline void gp_Ax1::SetLocation (const gp_Pnt& P)
{ loc = P; }
inline const gp_Dir& gp_Ax1::Direction () const
{ return vdir; }
inline const gp_Pnt& gp_Ax1::Location () const
{ return loc; }
inline Standard_Boolean gp_Ax1::IsNormal
(const gp_Ax1& Other,
const Standard_Real AngularTolerance) const
{ return vdir.IsNormal(Other.vdir, AngularTolerance); }
inline Standard_Boolean gp_Ax1::IsOpposite
(const gp_Ax1& Other,
const Standard_Real AngularTolerance) const
{ return vdir.IsOpposite(Other.vdir, AngularTolerance); }
inline Standard_Boolean gp_Ax1::IsParallel
(const gp_Ax1& Other,
const Standard_Real AngularTolerance) const
{ return vdir.IsParallel(Other.vdir, AngularTolerance); }
inline Standard_Real gp_Ax1::Angle (const gp_Ax1& Other) const
{ return vdir.Angle (Other.vdir); }
inline void gp_Ax1::Reverse ()
{ vdir.Reverse(); }
inline gp_Ax1 gp_Ax1::Reversed () const
{
gp_Dir D = vdir.Reversed();
return gp_Ax1(loc, D);
}
inline void gp_Ax1::Rotate (const gp_Ax1& A1, const Standard_Real Ang)
{
loc.Rotate(A1, Ang);
vdir.Rotate(A1 , Ang);
}
inline gp_Ax1 gp_Ax1::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Ax1 A = *this;
A.Rotate (A1, Ang);
return A;
}
inline void gp_Ax1::Scale (const gp_Pnt& P,
const Standard_Real S)
{
loc.Scale (P, S);
if (S < 0.0) vdir.Reverse();
}
inline gp_Ax1 gp_Ax1::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Ax1 A1 = *this;
A1.Scale (P, S);
return A1;
}
inline void gp_Ax1::Transform (const gp_Trsf& T)
{
loc.Transform(T);
vdir.Transform(T);
}
inline gp_Ax1 gp_Ax1::Transformed (const gp_Trsf& T) const
{
gp_Ax1 A1 = *this;
A1.Transform (T);
return A1;
}
inline void gp_Ax1::Translate (const gp_Vec& V)
{ loc.Translate (V); }
inline gp_Ax1 gp_Ax1::Translated (const gp_Vec& V) const
{
gp_Ax1 A1 = *this;
(A1.loc).Translate (V);
return A1;
}
inline void gp_Ax1::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{
loc.Translate (P1, P2);
}
inline gp_Ax1 gp_Ax1::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Ax1 A1 = *this;
(A1.loc).Translate (P1, P2);
return A1;
}

382
src/gp/gp_Ax2.cdl Executable file
View File

@@ -0,0 +1,382 @@
---Copyright: Matra Datavision 1991
class Ax2 from gp inherits Storable
--- Purpose :
-- Describes a right-handed coordinate system in 3D space.
-- A coordinate system is defined by:
-- - its origin (also referred to as its "Location point"), and
-- - three orthogonal unit vectors, termed respectively the
-- "X Direction", the "Y Direction" and the "Direction" (also
-- referred to as the "main Direction").
-- The "Direction" of the coordinate system is called its
-- "main Direction" because whenever this unit vector is
-- modified, the "X Direction" and the "Y Direction" are
-- recomputed. However, when we modify either the "X
-- Direction" or the "Y Direction", "Direction" is not modified.
-- The "main Direction" is also the "Z Direction".
-- Since an Ax2 coordinate system is right-handed, its
-- "main Direction" is always equal to the cross product of
-- its "X Direction" and "Y Direction". (To define a
-- left-handed coordinate system, use gp_Ax3.)
-- A coordinate system is used:
-- - to describe geometric entities, in particular to position
-- them. The local coordinate system of a geometric
-- entity serves the same purpose as the STEP function
-- "axis placement two axes", or
-- - to define geometric transformations.
-- Note: we refer to the "X Axis", "Y Axis" and "Z Axis",
-- respectively, as to axes having:
-- - the origin of the coordinate system as their origin, and
-- - the unit vectors "X Direction", "Y Direction" and "main
-- Direction", respectively, as their unit vectors.
-- The "Z Axis" is also the "main Axis".
uses Ax1 from gp,
Dir from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard
is
Create returns Ax2;
---C++:inline
--- Purpose : Creates an object corresponding to the reference
-- coordinate system (OXYZ).
Create (P : Pnt; N, Vx : Dir) returns Ax2
---C++:inline
--- Purpose :
-- Creates an axis placement with an origin P such that:
-- - N is the Direction, and
-- - the "X Direction" is normal to N, in the plane
-- defined by the vectors (N, Vx): "X
-- Direction" = (N ^ Vx) ^ N,
-- Exception: raises ConstructionError if N and Vx are parallel (same or opposite orientation).
raises ConstructionError;
Create (P : Pnt; V : Dir) returns Ax2;
--- Purpose :
-- Creates - a coordinate system with an origin P, where V
-- gives the "main Direction" (here, "X Direction" and "Y
-- Direction" are defined automatically).
SetAxis (me : in out; A1 : Ax1)
--- Purpose : Assigns the origin and "main Direction" of the axis A1 to
-- this coordinate system, then recomputes its "X Direction" and "Y Direction".
-- Note: The new "X Direction" is computed as follows:
-- new "X Direction" = V1 ^(previous "X Direction" ^ V)
-- where V is the "Direction" of A1.
-- Exceptions
-- Standard_ConstructionError if A1 is parallel to the "X
-- Direction" of this coordinate system.
raises ConstructionError
is static;
SetDirection (me : in out; V : Dir)
--- Purpose :
-- Changes the "main Direction" of this coordinate system,
-- then recomputes its "X Direction" and "Y Direction".
-- Note: the new "X Direction" is computed as follows:
-- new "X Direction" = V ^ (previous "X Direction" ^ V)
-- Exceptions
-- Standard_ConstructionError if V is parallel to the "X
-- Direction" of this coordinate system.
raises ConstructionError
is static;
SetLocation (me : in out; P : Pnt) is static;
--- Purpose :
-- Changes the "Location" point (origin) of <me>.
SetXDirection (me : in out; Vx : Dir)
--- Purpose :
-- Changes the "Xdirection" of <me>. The main direction
-- "Direction" is not modified, the "Ydirection" is modified.
-- If <Vx> is not normal to the main direction then <XDirection>
-- is computed as follows XDirection = Direction ^ (Vx ^ Direction).
-- Exceptions
-- Standard_ConstructionError if Vx or Vy is parallel to
-- the "main Direction" of this coordinate system.
raises ConstructionError
is static;
SetYDirection(me : in out; Vy : Dir)
--- Purpose :
-- Changes the "Ydirection" of <me>. The main direction is not
-- modified but the "Xdirection" is changed.
-- If <Vy> is not normal to the main direction then "YDirection"
-- is computed as follows
-- YDirection = Direction ^ (<Vy> ^ Direction).
-- Exceptions
-- Standard_ConstructionError if Vx or Vy is parallel to
-- the "main Direction" of this coordinate system.
raises ConstructionError
is static;
Angle (me; Other : Ax2) returns Real is static;
--- Purpose :
-- Computes the angular value, in radians, between the main direction of
-- <me> and the main direction of <Other>. Returns the angle
-- between 0 and PI in radians.
Axis (me) returns Ax1 is static;
---C++:inline
--- Purpose :
-- Returns the main axis of <me>. It is the "Location" point
-- and the main "Direction".
---C++: return const&
Direction (me) returns Dir is static;
---C++:inline
--- Purpose :
-- Returns the main direction of <me>.
---C++: return const&
Location (me) returns Pnt is static;
---C++:inline
--- Purpose :
-- Returns the "Location" point (origin) of <me>.
---C++: return const&
XDirection (me) returns Dir is static;
---C++:inline
--- Purpose :
-- Returns the "XDirection" of <me>.
---C++: return const&
YDirection(me) returns Dir is static;
---C++:inline
--- Purpose :
-- Returns the "YDirection" of <me>.
---C++: return const&
IsCoplanar (me; Other : Ax2; LinearTolerance, AngularTolerance : Real)
returns Boolean
is static;
-- Returns True if
-- - the "main Direction" of this coordinate system is parallel to:
-- - the "main Direction" of the coordinate system Other, or
-- - the Direction of axis A1, and
--
-- Note: the tolerance criterion for angular equality is given by AngularTolerance.
IsCoplanar (me; A1 : Ax1; LinearTolerance, AngularTolerance : Real)
returns Boolean
is static;
---C++:inline
--- Purpose :
-- Returns True if
-- . the distance between <me> and the "Location" point of A1
-- is lower of equal to LinearTolerance and
-- . the main direction of <me> and the direction of A1 are normal.
-- Note: the tolerance criterion for angular equality is given by AngularTolerance.
Mirror (me : in out; P : Pnt) is static;
---Purpose:
-- Performs a symmetrical transformation of this coordinate
-- system with respect to:
-- - the point P, and assigns the result to this coordinate system.
-- Warning
-- This transformation is always performed on the origin.
-- In case of a reflection with respect to a point:
-- - the main direction of the coordinate system is not changed, and
-- - the "X Direction" and the "Y Direction" are simply reversed
-- In case of a reflection with respect to an axis or a plane:
-- - the transformation is applied to the "X Direction"
-- and the "Y Direction", then
-- - the "main Direction" is recomputed as the cross
-- product "X Direction" ^ "Y Direction".
-- This maintains the right-handed property of the
-- coordinate system.
Mirrored (me; P : Pnt) returns Ax2 is static;
---Purpose:
-- Performs a symmetrical transformation of this coordinate
-- system with respect to:
-- - the point P, and creates a new one.
-- Warning
-- This transformation is always performed on the origin.
-- In case of a reflection with respect to a point:
-- - the main direction of the coordinate system is not changed, and
-- - the "X Direction" and the "Y Direction" are simply reversed
-- In case of a reflection with respect to an axis or a plane:
-- - the transformation is applied to the "X Direction"
-- and the "Y Direction", then
-- - the "main Direction" is recomputed as the cross
-- product "X Direction" ^ "Y Direction".
-- This maintains the right-handed property of the
-- coordinate system.
Mirror (me : in out; A1 : Ax1) is static;
---Purpose:
-- Performs a symmetrical transformation of this coordinate
-- system with respect to:
-- - the axis A1, and assigns the result to this coordinate systeme.
-- Warning
-- This transformation is always performed on the origin.
-- In case of a reflection with respect to a point:
-- - the main direction of the coordinate system is not changed, and
-- - the "X Direction" and the "Y Direction" are simply reversed
-- In case of a reflection with respect to an axis or a plane:
-- - the transformation is applied to the "X Direction"
-- and the "Y Direction", then
-- - the "main Direction" is recomputed as the cross
-- product "X Direction" ^ "Y Direction".
-- This maintains the right-handed property of the
-- coordinate system.
Mirrored (me; A1 : Ax1) returns Ax2 is static;
---Purpose:
-- Performs a symmetrical transformation of this coordinate
-- system with respect to:
-- - the axis A1, and creates a new one.
-- Warning
-- This transformation is always performed on the origin.
-- In case of a reflection with respect to a point:
-- - the main direction of the coordinate system is not changed, and
-- - the "X Direction" and the "Y Direction" are simply reversed
-- In case of a reflection with respect to an axis or a plane:
-- - the transformation is applied to the "X Direction"
-- and the "Y Direction", then
-- - the "main Direction" is recomputed as the cross
-- product "X Direction" ^ "Y Direction".
-- This maintains the right-handed property of the
-- coordinate system.
Mirror (me : in out; A2 : Ax2) is static;
---Purpose:
-- Performs a symmetrical transformation of this coordinate
-- system with respect to:
-- - the plane defined by the origin, "X Direction" and "Y
-- Direction" of coordinate system A2 and assigns the result to this coordinate systeme.
-- Warning
-- This transformation is always performed on the origin.
-- In case of a reflection with respect to a point:
-- - the main direction of the coordinate system is not changed, and
-- - the "X Direction" and the "Y Direction" are simply reversed
-- In case of a reflection with respect to an axis or a plane:
-- - the transformation is applied to the "X Direction"
-- and the "Y Direction", then
-- - the "main Direction" is recomputed as the cross
-- product "X Direction" ^ "Y Direction".
-- This maintains the right-handed property of the
-- coordinate system.
Mirrored (me; A2 : Ax2) returns Ax2 is static;
---Purpose:
-- Performs a symmetrical transformation of this coordinate
-- system with respect to:
-- - the plane defined by the origin, "X Direction" and "Y
-- Direction" of coordinate system A2 and creates a new one.
-- Warning
-- This transformation is always performed on the origin.
-- In case of a reflection with respect to a point:
-- - the main direction of the coordinate system is not changed, and
-- - the "X Direction" and the "Y Direction" are simply reversed
-- In case of a reflection with respect to an axis or a plane:
-- - the transformation is applied to the "X Direction"
-- and the "Y Direction", then
-- - the "main Direction" is recomputed as the cross
-- product "X Direction" ^ "Y Direction".
-- This maintains the right-handed property of the
-- coordinate system.
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
---C++:inline
Rotated (me; A1 : Ax1; Ang : Real) returns Ax2 is static;
---C++:inline
--- Purpose :
-- Rotates an axis placement. <A1> is the axis of the
-- rotation . Ang is the angular value of the rotation
-- in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++:inline
Scaled (me; P : Pnt; S : Real) returns Ax2 is static;
---C++:inline
--- Purpose :
-- Applies a scaling transformation on the axis placement.
-- The "Location" point of the axisplacement is modified.
--- Warnings :
-- If the scale <S> is negative :
-- . the main direction of the axis placement is not changed.
-- . The "XDirection" and the "YDirection" are reversed.
-- So the axis placement stay right handed.
Transform (me : in out; T : Trsf) is static;
---C++:inline
Transformed (me; T : Trsf) returns Ax2 is static;
---C++:inline
--- Purpose :
-- Transforms an axis placement with a Trsf.
-- The "Location" point, the "XDirection" and the
-- "YDirection" are transformed with T. The resulting
-- main "Direction" of <me> is the cross product between
-- the "XDirection" and the "YDirection" after transformation.
Translate (me : in out; V : Vec)
---C++:inline
is static;
Translated (me; V : Vec) returns Ax2 is static;
---C++:inline
--- Purpose :
-- Translates an axis plaxement in the direction of the vector
-- <V>. The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt)
---C++:inline
is static;
Translated (me; P1, P2 : Pnt) returns Ax2 is static;
---C++:inline
--- Purpose :
-- Translates an axis placement from the point <P1> to the
-- point <P2>.
fields
axis : Ax1;
vydir : Dir;
vxdir : Dir;
end;

95
src/gp/gp_Ax2.cxx Executable file
View File

@@ -0,0 +1,95 @@
// File vgeom_Ax2.cxx , JCV 30/08/90
// JCV 1/10/90 Changement de nom du package vgeom -> gp
// JCV 12/12/90 Modif mineur suite a la premiere revue de projet
// LPA, JCV 07/92 passage sur C1.
// JCV 07/92 Introduction de la method Dump
#define No_Standard_OutOfRange
#include <gp_Ax2.ixx>
#include <gp.hxx>
gp_Ax2::gp_Ax2 (const gp_Pnt& P, const gp_Dir& V) :
axis(P,V)
{
Standard_Real A = V.X();
Standard_Real B = V.Y();
Standard_Real C = V.Z();
Standard_Real Aabs = A;
if (Aabs < 0) Aabs = - Aabs;
Standard_Real Babs = B;
if (Babs < 0) Babs = - Babs;
Standard_Real Cabs = C;
if (Cabs < 0) Cabs = - Cabs;
gp_Dir D;
// pour determiner l axe X :
// on dit que le produit scalaire Vx.V = 0.
// et on recherche le max(A,B,C) pour faire la division.
// l'une des coordonnees du vecteur est nulle.
if ( Babs <= Aabs && Babs <= Cabs) {
if (Aabs > Cabs) D.SetCoord(-C,0., A);
else D.SetCoord( C,0.,-A);
}
else if ( Aabs <= Babs && Aabs <= Cabs) {
if (Babs > Cabs) D.SetCoord(0.,-C, B);
else D.SetCoord(0., C,-B);
}
else {
if (Aabs > Babs) D.SetCoord(-B, A,0.);
else D.SetCoord( B,-A,0.);
}
SetXDirection(D);
}
void gp_Ax2::Mirror (const gp_Pnt& P)
{
gp_Pnt Temp = axis.Location();
Temp.Mirror (P);
axis.SetLocation (Temp);
vxdir.Reverse ();
vydir.Reverse ();
}
gp_Ax2 gp_Ax2::Mirrored(const gp_Pnt& P) const
{
gp_Ax2 Temp = *this;
Temp.Mirror (P);
return Temp;
}
void gp_Ax2::Mirror (const gp_Ax1& A1)
{
vydir.Mirror (A1);
vxdir.Mirror (A1);
gp_Pnt Temp = axis.Location();
Temp.Mirror (A1);
axis.SetLocation (Temp);
axis.SetDirection (vxdir.Crossed (vydir));
}
gp_Ax2 gp_Ax2::Mirrored(const gp_Ax1& A1) const
{
gp_Ax2 Temp = *this;
Temp.Mirror (A1);
return Temp;
}
void gp_Ax2::Mirror (const gp_Ax2& A2)
{
vydir.Mirror (A2);
vxdir.Mirror (A2);
gp_Pnt Temp = axis.Location();
Temp.Mirror (A2);
axis.SetLocation (Temp);
axis.SetDirection (vxdir.Crossed (vydir));
}
gp_Ax2 gp_Ax2::Mirrored(const gp_Ax2& A2) const
{
gp_Ax2 Temp = *this;
Temp.Mirror (A2);
return Temp;
}

199
src/gp/gp_Ax2.lxx Executable file
View File

@@ -0,0 +1,199 @@
// File: gp_Ax2.lxx
#include <gp.hxx>
#include <gp_Ax1.hxx>
#include <Precision.hxx>
inline gp_Ax2::gp_Ax2() : vydir(0.,1.,0.), vxdir(1.,0.,0.)
{ }
inline gp_Ax2::gp_Ax2(const gp_Pnt& P,
const gp_Dir& N,
const gp_Dir& Vx) : axis(P, N), vydir(N), vxdir(N)
{
vxdir.CrossCross(Vx, N);
vydir.Cross(vxdir);
}
inline void gp_Ax2::SetAxis (const gp_Ax1& A1)
{
Standard_Real a = A1.Direction() * vxdir;
if(Abs(Abs(a) - 1.) <= Precision::Angular()) {
if(a > 0.) {
vxdir = vydir;
vydir = axis.Direction();
axis = A1;
}
else {
vxdir = axis.Direction();
axis = A1;
}
}
else {
axis = A1;
vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction());
vydir = axis.Direction().Crossed (vxdir);
}
}
inline void gp_Ax2::SetDirection (const gp_Dir& V)
{
Standard_Real a = V * vxdir;
if(Abs(Abs(a) - 1.) <= Precision::Angular()) {
if(a > 0.) {
vxdir = vydir;
vydir = axis.Direction();
axis.SetDirection (V);
}
else {
vxdir = axis.Direction();
axis.SetDirection (V);
}
}
else {
axis.SetDirection (V);
vxdir = V.CrossCrossed (vxdir, V);
vydir = V.Crossed (vxdir);
}
}
inline void gp_Ax2::SetLocation (const gp_Pnt& P)
{ axis.SetLocation(P); }
inline void gp_Ax2::SetXDirection (const gp_Dir& Vx)
{
vxdir = axis.Direction().CrossCrossed (Vx, axis.Direction());
vydir = axis.Direction().Crossed (vxdir);
}
inline void gp_Ax2::SetYDirection (const gp_Dir& Vy)
{
vxdir = Vy.Crossed (axis.Direction());
vydir = (axis.Direction()).Crossed (vxdir);
}
inline Standard_Real gp_Ax2::Angle (const gp_Ax2& Other) const
{ return axis.Angle (Other.axis); }
inline const gp_Ax1& gp_Ax2::Axis () const
{ return axis; }
inline const gp_Dir& gp_Ax2::Direction () const
{ return axis.Direction(); }
inline const gp_Pnt& gp_Ax2::Location () const
{ return axis.Location(); }
inline const gp_Dir& gp_Ax2::XDirection () const
{ return vxdir; }
inline const gp_Dir& gp_Ax2::YDirection () const
{ return vydir; }
inline Standard_Boolean gp_Ax2::IsCoplanar
(const gp_Ax2& Other,
const Standard_Real LinearTolerance,
const Standard_Real AngularTolerance) const
{
const gp_Dir& DD = axis.Direction();
const gp_Pnt& PP = axis.Location ();
const gp_Pnt& OP = Other.axis.Location ();
Standard_Real D1 = (DD.X() * (OP.X() - PP.X()) +
DD.Y() * (OP.Y() - PP.Y()) +
DD.Z() * (OP.Z() - PP.Z()));
if (D1 < 0 ) D1 = - D1;
return (D1 <= LinearTolerance &&
axis.IsParallel (Other.axis, AngularTolerance));
}
inline Standard_Boolean gp_Ax2::IsCoplanar
(const gp_Ax1& A,
const Standard_Real LinearTolerance,
const Standard_Real AngularTolerance) const
{
const gp_Dir& DD = axis.Direction();
const gp_Pnt& PP = axis.Location ();
const gp_Pnt& AP = A .Location ();
Standard_Real D1 = (DD.X() * (AP.X() - PP.X()) +
DD.Y() * (AP.Y() - PP.Y()) +
DD.Z() * (AP.Z() - PP.Z()));
if (D1 < 0) D1 = - D1;
return (D1 <= LinearTolerance &&
axis.IsNormal (A, AngularTolerance));
}
inline void gp_Ax2::Rotate(const gp_Ax1& A1, const Standard_Real Ang)
{
gp_Pnt Temp = axis.Location();
Temp.Rotate (A1, Ang);
axis.SetLocation (Temp);
vxdir.Rotate (A1, Ang);
vydir.Rotate (A1, Ang);
axis.SetDirection (vxdir.Crossed (vydir));
}
inline gp_Ax2 gp_Ax2::Rotated(const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Ax2 Temp = *this;
Temp.Rotate (A1, Ang);
return Temp;
}
inline void gp_Ax2::Scale (const gp_Pnt& P, const Standard_Real S)
{
gp_Pnt Temp = axis.Location();
Temp.Scale (P, S);
axis.SetLocation (Temp);
if (S < 0.0) {
vxdir.Reverse ();
vydir.Reverse ();
}
}
inline gp_Ax2 gp_Ax2::Scaled(const gp_Pnt& P,
const Standard_Real S) const
{
gp_Ax2 Temp = *this;
Temp.Scale (P, S);
return Temp;
}
inline void gp_Ax2::Transform (const gp_Trsf& T)
{
gp_Pnt Temp = axis.Location();
Temp.Transform (T);
axis.SetLocation (Temp);
vxdir.Transform (T);
vydir.Transform (T);
axis.SetDirection (vxdir.Crossed (vydir));
}
inline gp_Ax2 gp_Ax2::Transformed(const gp_Trsf& T) const
{
gp_Ax2 Temp = *this;
Temp.Transform (T);
return Temp;
}
inline void gp_Ax2::Translate (const gp_Vec& V)
{ axis.Translate (V); }
inline gp_Ax2 gp_Ax2::Translated(const gp_Vec& V) const
{
gp_Ax2 Temp = *this;
Temp.Translate (V);
return Temp;
}
inline void gp_Ax2::Translate (const gp_Pnt& P1, const gp_Pnt& P2)
{ axis.Translate (P1, P2); }
inline gp_Ax2 gp_Ax2::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Ax2 Temp = *this;
Temp.Translate (P1, P2);
return Temp;
}

258
src/gp/gp_Ax22d.cdl Executable file
View File

@@ -0,0 +1,258 @@
---Copyright: Matra Datavision 1991
class Ax22d from gp inherits Storable
--- Purpose :
-- Describes a coordinate system in a plane (2D space).
-- A coordinate system is defined by:
-- - its origin (also referred to as its "Location point"), and
-- - two orthogonal unit vectors, respectively, called the "X
-- Direction" and the "Y Direction".
-- A gp_Ax22d may be right-handed ("direct sense") or
-- left-handed ("inverse" or "indirect sense").
-- You use a gp_Ax22d to:
-- - describe 2D geometric entities, in particular to position
-- them. The local coordinate system of a geometric
-- entity serves for the same purpose as the STEP
-- function "axis placement two axes", or
-- - define geometric transformations.
-- Note: we refer to the "X Axis" and "Y Axis" as the axes having:
-- - the origin of the coordinate system as their origin, and
-- - the unit vectors "X Direction" and "Y Direction",
-- respectively, as their unit vectors.
uses Ax2d from gp,
Dir2d from gp,
Pnt2d from gp,
Trsf2d from gp,
Vec2d from gp
raises ConstructionError from Standard
is
Create returns Ax22d;
---C++:inline
--- Purpose : Creates an object representing the reference
-- co-ordinate system (OXY).
Create (P : Pnt2d; Vx, Vy : Dir2d) returns Ax22d
---C++:inline
--- Purpose :
-- Creates a coordinate system with origin P and where:
-- - Vx is the "X Direction", and
-- - the "Y Direction" is orthogonal to Vx and
-- oriented so that the cross products Vx^"Y
-- Direction" and Vx^Vy have the same sign.
-- Raises ConstructionError if Vx and Vy are parallel (same or opposite orientation).
raises ConstructionError;
Create (P : Pnt2d;
V : Dir2d;
Sense : Boolean from Standard = Standard_True) returns Ax22d;
---C++:inline
--- Purpose :
-- Creates - a coordinate system with origin P and "X Direction"
-- V, which is:
-- - right-handed if Sense is true (default value), or
-- - left-handed if Sense is false
Create (A : Ax2d;
Sense : Boolean from Standard = Standard_True) returns Ax22d;
---C++:inline
--- Purpose :
-- Creates - a coordinate system where its origin is the origin of
-- A and its "X Direction" is the unit vector of A, which is:
-- - right-handed if Sense is true (default value), or
-- - left-handed if Sense is false.
SetAxis (me : in out; A1 : Ax22d)
---C++:inline
--- Purpose :
-- Assigns the origin and the two unit vectors of the
-- coordinate system A1 to this coordinate system.
is static;
SetXAxis (me : in out; A1 : Ax2d)
---C++:inline
--- Purpose :
-- Changes the XAxis and YAxis ("Location" point and "Direction")
-- of <me>.
-- The "YDirection" is recomputed in the same sense as before.
is static;
SetYAxis (me : in out; A1 : Ax2d)
---C++:inline
--- Purpose : Changes the XAxis and YAxis ("Location" point and "Direction") of <me>.
-- The "XDirection" is recomputed in the same sense as before.
is static;
SetLocation (me : in out; P : Pnt2d) is static;
---C++:inline
--- Purpose :
-- Changes the "Location" point (origin) of <me>.
SetXDirection (me : in out; Vx : Dir2d)
---C++:inline
--- Purpose :
-- Assigns Vx to the "X Direction" of
-- this coordinate system. The other unit vector of this
-- coordinate system is recomputed, normal to Vx ,
-- without modifying the orientation (right-handed or
-- left-handed) of this coordinate system.
is static;
SetYDirection(me : in out; Vy : Dir2d)
---C++:inline
--- Purpose : Assignsr Vy to the "Y Direction" of
-- this coordinate system. The other unit vector of this
-- coordinate system is recomputed, normal to Vy,
-- without modifying the orientation (right-handed or
-- left-handed) of this coordinate system.
is static;
XAxis (me) returns Ax2d is static;
---C++:inline
--- Purpose : Returns an axis, for which
-- - the origin is that of this coordinate system, and
-- - the unit vector is either the "X Direction" of this coordinate system.
-- Note: the result is the "X Axis" of this coordinate system.
YAxis (me) returns Ax2d is static;
---C++:inline
--- Purpose : Returns an axis, for which
-- - the origin is that of this coordinate system, and
-- - the unit vector is either the "Y Direction" of this coordinate system.
-- Note: the result is the "Y Axis" of this coordinate system.
Location (me) returns Pnt2d is static;
---C++:inline
--- Purpose :
-- Returns the "Location" point (origin) of <me>.
---C++: return const&
XDirection (me) returns Dir2d is static;
---C++:inline
--- Purpose :
-- Returns the "XDirection" of <me>.
---C++: return const&
YDirection(me) returns Dir2d is static;
---C++:inline
--- Purpose :
-- Returns the "YDirection" of <me>.
---C++: return const&
Mirror (me : in out; P : Pnt2d) is static;
Mirrored (me; P : Pnt2d) returns Ax22d is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to the point P which is the
-- center of the symmetry.
--- Warnings :
-- The main direction of the axis placement is not changed.
-- The "XDirection" and the "YDirection" are reversed.
-- So the axis placement stay right handed.
Mirror (me : in out; A : Ax2d) is static;
Mirrored (me; A : Ax2d) returns Ax22d is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to an axis placement which
-- is the axis of the symmetry.
-- The transformation is performed on the "Location"
-- point, on the "XDirection" and "YDirection".
-- The resulting main "Direction" is the cross product between
-- the "XDirection" and the "YDirection" after transformation.
Rotate (me : in out; P : Pnt2d; Ang : Real) is static;
---C++:inline
Rotated (me; P : Pnt2d; Ang : Real) returns Ax22d is static;
---C++:inline
--- Purpose :
-- Rotates an axis placement. <A1> is the axis of the
-- rotation . Ang is the angular value of the rotation
-- in radians.
Scale (me : in out; P : Pnt2d; S : Real) is static;
---C++:inline
Scaled (me; P : Pnt2d; S : Real) returns Ax22d is static;
---C++:inline
--- Purpose :
-- Applies a scaling transformation on the axis placement.
-- The "Location" point of the axisplacement is modified.
--- Warnings :
-- If the scale <S> is negative :
-- . the main direction of the axis placement is not changed.
-- . The "XDirection" and the "YDirection" are reversed.
-- So the axis placement stay right handed.
Transform (me : in out; T : Trsf2d) is static;
---C++:inline
Transformed (me; T : Trsf2d) returns Ax22d is static;
---C++:inline
--- Purpose :
-- Transforms an axis placement with a Trsf.
-- The "Location" point, the "XDirection" and the
-- "YDirection" are transformed with T. The resulting
-- main "Direction" of <me> is the cross product between
-- the "XDirection" and the "YDirection" after transformation.
Translate (me : in out; V : Vec2d)
---C++:inline
is static;
Translated (me; V : Vec2d) returns Ax22d is static;
---C++:inline
--- Purpose :
-- Translates an axis plaxement in the direction of the vector
-- <V>. The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt2d)
---C++:inline
is static;
Translated (me; P1, P2 : Pnt2d) returns Ax22d is static;
---C++:inline
--- Purpose :
-- Translates an axis placement from the point <P1> to the
-- point <P2>.
fields
point : Pnt2d;
vydir : Dir2d;
vxdir : Dir2d;
end;

40
src/gp/gp_Ax22d.cxx Executable file
View File

@@ -0,0 +1,40 @@
// File vgeom_Ax22d.cxx , JCV 30/08/90
// JCV 1/10/90 Changement de nom du package vgeom -> gp
// JCV 12/12/90 Modif mineur suite a la premiere revue de projet
// LPA, JCV 07/92 passage sur C1.
// JCV 07/92 Introduction de la method Dump
#include <gp_Ax22d.ixx>
void gp_Ax22d::Mirror (const gp_Pnt2d& P)
{
gp_Pnt2d Temp = point;
Temp.Mirror (P);
point = Temp;
vxdir.Reverse ();
vydir.Reverse ();
}
gp_Ax22d gp_Ax22d::Mirrored(const gp_Pnt2d& P) const
{
gp_Ax22d Temp = *this;
Temp.Mirror (P);
return Temp;
}
void gp_Ax22d::Mirror (const gp_Ax2d& A1)
{
vydir.Mirror (A1);
vxdir.Mirror (A1);
gp_Pnt2d Temp = point;
Temp.Mirror (A1);
point = Temp;
}
gp_Ax22d gp_Ax22d::Mirrored(const gp_Ax2d& A1) const
{
gp_Ax22d Temp = *this;
Temp.Mirror (A1);
return Temp;
}

170
src/gp/gp_Ax22d.lxx Executable file
View File

@@ -0,0 +1,170 @@
// File: gp_Ax22d.lxx
inline gp_Ax22d::gp_Ax22d() : vydir(0.,1.), vxdir(1.,0.)
{}
inline gp_Ax22d::gp_Ax22d(const gp_Pnt2d& P ,
const gp_Dir2d& Vx,
const gp_Dir2d& Vy) :
point(P),
vydir(Vy),
vxdir(Vx)
{
Standard_Real value = Vx.Crossed(Vy);
if (value >= 0.0) vydir.SetCoord(-vxdir.Y(), vxdir.X());
else vydir.SetCoord( vxdir.Y(),-vxdir.X());
}
inline gp_Ax22d::gp_Ax22d(const gp_Pnt2d& P ,
const gp_Dir2d& Vx ,
const Standard_Boolean Sense) :
point(P),
vxdir(Vx)
{
if (Sense) vydir.SetCoord(-Vx.Y(), Vx.X());
else vydir.SetCoord( Vx.Y(),-Vx.X());
}
inline gp_Ax22d::gp_Ax22d(const gp_Ax2d& A ,
const Standard_Boolean Sense) :
point(A.Location()),
vxdir(A.Direction())
{
if (Sense) vydir.SetCoord(-vxdir.Y(), vxdir.X());
else vydir.SetCoord( vxdir.Y(),-vxdir.X());
}
inline void gp_Ax22d::SetAxis(const gp_Ax22d& A1)
{
point = A1.Location();
vxdir = A1.XDirection();
vydir = A1.YDirection();
}
inline void gp_Ax22d::SetXAxis (const gp_Ax2d& A1)
{
Standard_Boolean sign = (vxdir.Crossed(vydir)) >= 0.0;
point = A1.Location ();
vxdir = A1.Direction();
if (sign) vydir.SetCoord(-vxdir.Y(), vxdir.X());
else vydir.SetCoord( vxdir.Y(),-vxdir.X());
}
inline void gp_Ax22d::SetYAxis (const gp_Ax2d& A1)
{
Standard_Boolean sign = (vxdir.Crossed(vydir)) >= 0.0;
point = A1.Location ();
vydir = A1.Direction();
if (sign) vxdir.SetCoord( vydir.Y(),-vydir.X());
else vxdir.SetCoord(-vydir.Y(), vydir.X());
}
inline void gp_Ax22d::SetLocation (const gp_Pnt2d& P)
{ point = P; }
inline void gp_Ax22d::SetXDirection (const gp_Dir2d& Vx)
{
Standard_Boolean sign = (vxdir.Crossed(vydir)) >= 0.0;
vxdir = Vx;
if (sign) vydir.SetCoord(-Vx.Y(), Vx.X());
else vydir.SetCoord( Vx.Y(),-Vx.X());
}
inline void gp_Ax22d::SetYDirection (const gp_Dir2d& Vy)
{
Standard_Boolean sign = (vxdir.Crossed(vydir)) >= 0.0;
vydir = Vy;
if (sign) vxdir.SetCoord( Vy.Y(),-Vy.X());
else vxdir.SetCoord(-Vy.Y(), Vy.X());
}
inline gp_Ax2d gp_Ax22d::XAxis () const
{ return gp_Ax2d(point, vxdir); }
inline gp_Ax2d gp_Ax22d::YAxis () const
{ return gp_Ax2d(point, vydir); }
inline const gp_Pnt2d& gp_Ax22d::Location () const
{ return point; }
inline const gp_Dir2d& gp_Ax22d::XDirection () const
{ return vxdir; }
inline const gp_Dir2d& gp_Ax22d::YDirection () const
{ return vydir; }
inline void gp_Ax22d::Rotate (const gp_Pnt2d& P,
const Standard_Real Ang)
{
gp_Pnt2d Temp = point;
Temp.Rotate (P,Ang);
point = Temp;
vxdir.Rotate (Ang);
vydir.Rotate (Ang);
}
inline gp_Ax22d gp_Ax22d::Rotated(const gp_Pnt2d& P,
const Standard_Real Ang) const
{
gp_Ax22d Temp = *this;
Temp.Rotate (P,Ang);
return Temp;
}
inline void gp_Ax22d::Scale (const gp_Pnt2d& P,
const Standard_Real S)
{
gp_Pnt2d Temp = point;
Temp.Scale (P, S);
point = Temp;
if (S < 0.0) {
vxdir.Reverse ();
vydir.Reverse ();
}
}
inline gp_Ax22d gp_Ax22d::Scaled(const gp_Pnt2d& P,
const Standard_Real S) const
{
gp_Ax22d Temp = *this;
Temp.Scale (P, S);
return Temp;
}
inline void gp_Ax22d::Transform (const gp_Trsf2d& T)
{
gp_Pnt2d Temp = point;
Temp.Transform (T);
point = Temp;
vxdir.Transform (T);
vydir.Transform (T);
}
inline gp_Ax22d gp_Ax22d::Transformed(const gp_Trsf2d& T) const
{
gp_Ax22d Temp = *this;
Temp.Transform (T);
return Temp;
}
inline void gp_Ax22d::Translate (const gp_Vec2d& V)
{ point.Translate (V); }
inline gp_Ax22d gp_Ax22d::Translated(const gp_Vec2d& V) const
{
gp_Ax22d Temp = *this;
Temp.Translate (V);
return Temp;
}
inline void gp_Ax22d::Translate (const gp_Pnt2d& P1,const gp_Pnt2d& P2)
{ point.Translate (P1, P2); }
inline gp_Ax22d gp_Ax22d::Translated (const gp_Pnt2d& P1,
const gp_Pnt2d& P2) const
{
gp_Ax22d Temp = *this;
Temp.Translate (P1, P2);
return Temp;
}

203
src/gp/gp_Ax2d.cdl Executable file
View File

@@ -0,0 +1,203 @@
---Copyright: Matra Datavision 1991
class Ax2d from gp inherits Storable
---Purpose:
-- Describes an axis in the plane (2D space).
-- An axis is defined by:
-- - its origin (also referred to as its "Location point"), and
-- - its unit vector (referred to as its "Direction").
-- An axis implicitly defines a direct, right-handed
-- coordinate system in 2D space by:
-- - its origin,
-- - its "Direction" (giving the "X Direction" of the coordinate system), and
-- - the unit vector normal to "Direction" (positive angle
-- measured in the trigonometric sense).
-- An axis is used:
-- - to describe 2D geometric entities (for example, the
-- axis which defines angular coordinates on a circle).
-- It serves for the same purpose as the STEP function
-- "axis placement one axis", or
-- - to define geometric transformations (axis of
-- symmetry, axis of rotation, and so on).
-- Note: to define a left-handed 2D coordinate system, use gp_Ax22d.
uses Dir2d, Pnt2d, Trsf2d, Vec2d
is
Create returns Ax2d;
---C++:inline
--- Purpose : Creates an axis object representing X axis of
-- the reference co-ordinate system.
Create (P : Pnt2d; V : Dir2d) returns Ax2d;
---C++:inline
--- Purpose :
-- Creates an Ax2d. <P> is the "Location" point of
-- the axis placement and V is the "Direction" of
-- the axis placement.
SetLocation (me : out; Locat : Pnt2d) is static;
---C++:inline
--- Purpose : Changes the "Location" point (origin) of <me>.
SetDirection (me : out; V : Dir2d) is static;
---C++:inline
--- Purpose : Changes the direction of <me>.
Location (me) returns Pnt2d is static;
---C++:inline
--- Purpose : Returns the origin of <me>.
---C++: return const&
Direction (me) returns Dir2d is static;
---C++:inline
--- Purpose : Returns the direction of <me>.
---C++: return const&
IsCoaxial (me; Other : Ax2d; AngularTolerance, LinearTolerance : Real)
returns Boolean
is static;
--- Purpose :
-- Returns True if :
-- . the angle between <me> and <Other> is lower or equal
-- to <AngularTolerance> and
-- . the distance between <me>.Location() and <Other> is lower
-- or equal to <LinearTolerance> and
-- . the distance between <Other>.Location() and <me> is lower
-- or equal to LinearTolerance.
IsNormal (me; Other : Ax2d; AngularTolerance : Real) returns Boolean
is static;
---C++:inline
--- Purpose : Returns true if this axis and the axis Other are normal to
-- each other. That is, if the angle between the two axes is equal to Pi/2 or -Pi/2.
-- Note: the tolerance criterion is given by AngularTolerance.
IsOpposite (me; Other : Ax2d; AngularTolerance : Real) returns Boolean
is static;
---C++:inline
--- Purpose : Returns true if this axis and the axis Other are parallel,
-- and have opposite orientations. That is, if the angle
-- between the two axes is equal to Pi or -Pi.
-- Note: the tolerance criterion is given by AngularTolerance.
IsParallel (me; Other : Ax2d; AngularTolerance : Real) returns Boolean
is static;
---C++:inline
--- Purpose : Returns true if this axis and the axis Other are parallel,
-- and have either the same or opposite orientations. That
-- is, if the angle between the two axes is equal to 0, Pi or -Pi.
-- Note: the tolerance criterion is given by AngularTolerance.
Angle (me; Other : Ax2d) returns Real is static;
---C++:inline
--- Purpose :
-- Computes the angle, in radians, between this axis and
-- the axis Other. The value of the angle is between -Pi and Pi.
Reverse (me : in out) is static;
---C++:inline
--- Purpose : Reverses the direction of <me> and assigns the result to this axis.
Reversed (me) returns Ax2d is static;
---C++:inline
--- Purpose :
-- Computes a new axis placement with a direction opposite to
-- the direction of <me>.
Mirror (me : in out; P : Pnt2d) is static;
Mirrored (me; P : Pnt2d) returns Ax2d is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to the point P which is the
-- center of the symmetry.
Mirror (me : in out; A : Ax2d) is static;
Mirrored (me; A : Ax2d) returns Ax2d is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to an axis placement which
-- is the axis of the symmetry.
Rotate (me : in out; P : Pnt2d; Ang : Real) is static;
---C++:inline
Rotated (me; P : Pnt2d; Ang : Real) returns Ax2d is static;
---C++:inline
--- Purpose :
-- Rotates an axis placement. <P> is the center of the
-- rotation . Ang is the angular value of the rotation
-- in radians.
Scale (me : in out; P : Pnt2d; S : Real) is static;
Scaled (me; P : Pnt2d; S : Real) returns Ax2d is static;
---C++:inline
--- Purpose :
-- Applies a scaling transformation on the axis placement.
-- The "Location" point of the axisplacement is modified.
-- The "Direction" is reversed if the scale is negative.
Transform (me : in out; T : Trsf2d) is static;
---C++:inline
Transformed(me; T : Trsf2d) returns Ax2d is static;
---C++:inline
--- Purpose : Transforms an axis placement with a Trsf.
Translate (me : in out; V : Vec2d) is static;
---C++:inline
Translated (me; V : Vec2d) returns Ax2d is static;
---C++:inline
--- Purpose :
-- Translates an axis placement in the direction of the vector
-- <V>. The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt2d) is static;
---C++:inline
Translated (me; P1, P2 : Pnt2d) returns Ax2d is static;
---C++:inline
--- Purpose :
-- Translates an axis placement from the point <P1> to the
-- point <P2>.
fields
loc : Pnt2d;
vdir : Dir2d;
end;

60
src/gp/gp_Ax2d.cxx Executable file
View File

@@ -0,0 +1,60 @@
// File gp_Ax2d.cxx, JCV 06/90
// File gp_Ax2d.cxx, REG 27/10/90 nouvelle version
// JCV 08/01/91 modif introduction des classes XY et Mat dans le package
// LPA, JCV 07/92 passage sur C1.
// JCV 07/92 Introduction de la method Dump
#define No_Standard_OutOfRange
#include <gp_Ax2d.ixx>
#include <gp_XY.hxx>
Standard_Boolean gp_Ax2d::IsCoaxial (const gp_Ax2d& Other,
const Standard_Real AngularTolerance,
const Standard_Real LinearTolerance) const
{
gp_XY XY1 = loc.XY();
XY1.Subtract (Other.loc.XY());
Standard_Real D1 = XY1.Crossed (Other.vdir.XY());
if (D1 < 0) D1 = - D1;
gp_XY XY2 = Other.loc.XY();
XY2.Subtract (loc.XY());
Standard_Real D2 = XY2.Crossed (vdir.XY());
if (D2 < 0) D2 = - D2;
return (vdir.IsParallel (Other.vdir, AngularTolerance) &&
D1 <= LinearTolerance && D2 <= LinearTolerance);
}
void gp_Ax2d::Scale (const gp_Pnt2d& P,
const Standard_Real S)
{
loc.Scale(P, S);
if (S < 0.0) vdir.Reverse();
}
void gp_Ax2d::Mirror (const gp_Pnt2d& P)
{
loc.Mirror(P);
vdir.Reverse();
}
gp_Ax2d gp_Ax2d::Mirrored (const gp_Pnt2d& P) const
{
gp_Ax2d A = *this;
A.Mirror (P);
return A;
}
void gp_Ax2d::Mirror (const gp_Ax2d& A)
{
loc.Mirror (A);
vdir.Mirror (A.vdir);
}
gp_Ax2d gp_Ax2d::Mirrored (const gp_Ax2d& A) const
{
gp_Ax2d AA = *this;
AA.Mirror (A);
return AA;
}

111
src/gp/gp_Ax2d.lxx Executable file
View File

@@ -0,0 +1,111 @@
// File gp_Ax1.lxx, REG 27/10/90
// Modif jcv 08/01/1991
// JCV, LPA 07/92
#include <gp_Ax2d.hxx>
inline gp_Ax2d::gp_Ax2d() : loc(0.,0.), vdir(1.,0.)
{ }
inline gp_Ax2d::gp_Ax2d (const gp_Pnt2d& P,
const gp_Dir2d& V) : loc(P), vdir(V)
{ }
inline void gp_Ax2d::SetLocation(const gp_Pnt2d& P)
{ loc = P; }
inline void gp_Ax2d::SetDirection(const gp_Dir2d& V)
{ vdir = V; }
inline const gp_Pnt2d& gp_Ax2d::Location () const
{ return loc; }
inline const gp_Dir2d& gp_Ax2d::Direction () const
{ return vdir; }
inline Standard_Boolean gp_Ax2d::IsNormal
(const gp_Ax2d& Other,
const Standard_Real AngularTolerance) const
{ return vdir.IsNormal(Other.vdir, AngularTolerance); }
inline Standard_Boolean gp_Ax2d::IsOpposite
(const gp_Ax2d& Other,
const Standard_Real AngularTolerance) const
{ return vdir.IsOpposite (Other.vdir, AngularTolerance); }
inline Standard_Boolean gp_Ax2d::IsParallel
(const gp_Ax2d& Other,
const Standard_Real AngularTolerance) const
{ return vdir.IsParallel(Other.vdir, AngularTolerance); }
inline Standard_Real gp_Ax2d::Angle (const gp_Ax2d& Other) const
{ return vdir.Angle (Other.vdir); }
inline void gp_Ax2d::Reverse()
{ vdir.Reverse(); }
inline gp_Ax2d gp_Ax2d::Reversed() const
{
gp_Ax2d Temp = *this;
Temp.Reverse ();
return Temp;
}
inline void gp_Ax2d::Rotate (const gp_Pnt2d& P,
const Standard_Real Ang)
{
loc.Rotate (P, Ang);
vdir.Rotate (Ang);
}
inline gp_Ax2d gp_Ax2d::Rotated (const gp_Pnt2d& P,
const Standard_Real Ang) const
{
gp_Ax2d A = *this;
A.Rotate (P, Ang);
return A;
}
inline gp_Ax2d gp_Ax2d::Scaled (const gp_Pnt2d& P,
const Standard_Real S) const
{
gp_Ax2d A = *this;
A.Scale (P, S);
return A;
}
inline void gp_Ax2d::Transform (const gp_Trsf2d& T)
{
loc.Transform (T);
vdir.Transform (T);
}
inline gp_Ax2d gp_Ax2d::Transformed (const gp_Trsf2d& T) const
{
gp_Ax2d A = *this;
A.Transform (T);
return A;
}
inline void gp_Ax2d::Translate (const gp_Vec2d& V)
{ loc.Translate (V); }
inline gp_Ax2d gp_Ax2d::Translated (const gp_Vec2d& V) const
{
gp_Ax2d A = *this;
(A.loc).Translate (V);
return A;
}
inline void gp_Ax2d::Translate (const gp_Pnt2d& P1,
const gp_Pnt2d& P2)
{ loc.Translate (P1,P2); }
inline gp_Ax2d gp_Ax2d::Translated (const gp_Pnt2d& P1,
const gp_Pnt2d& P2) const
{
gp_Ax2d A = *this;
(A.loc).Translate( gp_Vec2d (P1, P2));
return A;
}

340
src/gp/gp_Ax3.cdl Executable file
View File

@@ -0,0 +1,340 @@
-- File: gp_Ax3.cdl
-- Created: Mon Aug 2 18:33:16 1993
-- Author: Laurent BOURESCHE
-- <lbo@phylox>
---Copyright: Matra Datavision 1993
class Ax3 from gp inherits Storable
--- Purpose : Describes a coordinate system in 3D space. Unlike a
-- gp_Ax2 coordinate system, a gp_Ax3 can be
-- right-handed ("direct sense") or left-handed ("indirect sense").
-- A coordinate system is defined by:
-- - its origin (also referred to as its "Location point"), and
-- - three orthogonal unit vectors, termed the "X
-- Direction", the "Y Direction" and the "Direction" (also
-- referred to as the "main Direction").
-- The "Direction" of the coordinate system is called its
-- "main Direction" because whenever this unit vector is
-- modified, the "X Direction" and the "Y Direction" are
-- recomputed. However, when we modify either the "X
-- Direction" or the "Y Direction", "Direction" is not modified.
-- "Direction" is also the "Z Direction".
-- The "main Direction" is always parallel to the cross
-- product of its "X Direction" and "Y Direction".
-- If the coordinate system is right-handed, it satisfies the equation:
-- "main Direction" = "X Direction" ^ "Y Direction"
-- and if it is left-handed, it satisfies the equation:
-- "main Direction" = -"X Direction" ^ "Y Direction"
-- A coordinate system is used:
-- - to describe geometric entities, in particular to position
-- them. The local coordinate system of a geometric
-- entity serves the same purpose as the STEP function
-- "axis placement three axes", or
-- - to define geometric transformations.
-- Note:
-- - We refer to the "X Axis", "Y Axis" and "Z Axis",
-- respectively, as the axes having:
-- - the origin of the coordinate system as their origin, and
-- - the unit vectors "X Direction", "Y Direction" and
-- "main Direction", respectively, as their unit vectors.
-- - The "Z Axis" is also the "main Axis".
-- - gp_Ax2 is used to define a coordinate system that must be always right-handed.
uses Ax1 from gp,
Ax2 from gp,
Dir from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard
is
Create returns Ax3 from gp;
--- Purpose : Creates an object corresponding to the reference
-- coordinate system (OXYZ).
Create (A : Ax2 from gp) returns Ax3 from gp;
---Purpose: Creates a coordinate system from a right-handed
-- coordinate system.
Create (P : Pnt from gp; N, Vx : Dir from gp) returns Ax3 from gp
--- Purpose : Creates a right handed axis placement with the
-- "Location" point P and two directions, N gives the
-- "Direction" and Vx gives the "XDirection".
-- Raises ConstructionError if N and Vx are parallel (same or opposite orientation).
raises ConstructionError;
Create (P : Pnt from gp; V : Dir from gp) returns Ax3 from gp;
--- Purpose :
-- Creates an axis placement with the "Location" point <P>
-- and the normal direction <V>.
XReverse(me : in out)
---Purpose: Reverses the X direction of <me>.
is static;
YReverse(me : in out)
---Purpose: Reverses the Y direction of <me>.
is static;
ZReverse(me : in out)
---Purpose: Reverses the Z direction of <me>.
is static;
SetAxis (me : in out; A1 : Ax1)
--- Purpose : Assigns the origin and "main Direction" of the axis A1 to
-- this coordinate system, then recomputes its "X Direction" and "Y Direction".
-- Note:
-- - The new "X Direction" is computed as follows:
-- new "X Direction" = V1 ^(previous "X Direction" ^ V)
-- where V is the "Direction" of A1.
-- - The orientation of this coordinate system
-- (right-handed or left-handed) is not modified.
-- Raises ConstructionError if the "Direction" of <A1> and the "XDirection" of <me>
-- are parallel (same or opposite orientation) because it is
-- impossible to calculate the new "XDirection" and the new
-- "YDirection".
raises ConstructionError
is static;
SetDirection (me : in out; V : Dir)
--- Purpose :
-- Changes the main direction of this coordinate system,
-- then recomputes its "X Direction" and "Y Direction".
-- Note:
-- - The new "X Direction" is computed as follows:
-- new "X Direction" = V ^ (previous "X Direction" ^ V).
-- - The orientation of this coordinate system (left- or right-handed) is not modified.
-- Raises ConstructionError if <V< and the previous "XDirection" are parallel
-- because it is impossible to calculate the new "XDirection"
-- and the new "YDirection".
raises ConstructionError
is static;
SetLocation (me : in out; P : Pnt) is static;
--- Purpose :
-- Changes the "Location" point (origin) of <me>.
SetXDirection (me : in out; Vx : Dir)
--- Purpose :
-- Changes the "Xdirection" of <me>. The main direction
-- "Direction" is not modified, the "Ydirection" is modified.
-- If <Vx> is not normal to the main direction then <XDirection>
-- is computed as follows XDirection = Direction ^ (Vx ^ Direction).
-- Raises ConstructionError if <Vx> is parallel (same or opposite
-- orientation) to the main direction of <me>
raises ConstructionError
is static;
SetYDirection(me : in out; Vy : Dir)
---C++:inline
--- Purpose :
-- Changes the "Ydirection" of <me>. The main direction is not
-- modified but the "Xdirection" is changed.
-- If <Vy> is not normal to the main direction then "YDirection"
-- is computed as follows
-- YDirection = Direction ^ (<Vy> ^ Direction).
-- Raises ConstructionError if <Vy> is parallel to the main direction of <me>
raises ConstructionError
is static;
Angle (me; Other : Ax3) returns Real is static;
---C++:inline
--- Purpose :
-- Computes the angular value between the main direction of
-- <me> and the main direction of <Other>. Returns the angle
-- between 0 and PI in radians.
Axis (me) returns Ax1 is static;
---C++:inline
--- Purpose :
-- Returns the main axis of <me>. It is the "Location" point
-- and the main "Direction".
---C++: return const&
Ax2 (me) returns Ax2 from gp
---Purpose: Computes a right-handed coordinate system with the
-- same "X Direction" and "Y Direction" as those of this
-- coordinate system, then recomputes the "main Direction".
-- If this coordinate system is right-handed, the result
-- returned is the same coordinate system. If this
-- coordinate system is left-handed, the result is reversed.
is static;
Direction (me) returns Dir is static;
---C++:inline
--- Purpose :
-- Returns the main direction of <me>.
---C++: return const&
Location (me) returns Pnt is static;
---C++:inline
--- Purpose :
-- Returns the "Location" point (origin) of <me>.
---C++: return const&
XDirection (me) returns Dir is static;
---C++:inline
--- Purpose :
-- Returns the "XDirection" of <me>.
---C++: return const&
YDirection(me) returns Dir is static;
---C++:inline
--- Purpose :
-- Returns the "YDirection" of <me>.
---C++: return const&
Direct(me) returns Boolean
---C++:inline
---Purpose: Returns True if the coordinate system is right-handed. i.e.
-- XDirection().Crossed(YDirection()).Dot(Direction()) > 0
is static;
IsCoplanar (me; Other : Ax3; LinearTolerance, AngularTolerance : Real)
returns Boolean
is static;
---C++:inline
--- Purpose :
-- Returns True if
-- . the distance between the "Location" point of <me> and
-- <Other> is lower or equal to LinearTolerance and
-- . the distance between the "Location" point of <Other> and
-- <me> is lower or equal to LinearTolerance and
-- . the main direction of <me> and the main direction of
-- <Other> are parallel (same or opposite orientation).
IsCoplanar (me; A1 : Ax1; LinearTolerance, AngularTolerance : Real)
returns Boolean
is static;
---C++:inline
--- Purpose : Returns True if
-- . the distance between <me> and the "Location" point of A1
-- is lower of equal to LinearTolerance and
-- . the distance between A1 and the "Location" point of <me>
-- is lower or equal to LinearTolerance and
-- . the main direction of <me> and the direction of A1 are normal.
Mirror (me : in out; P : Pnt) is static;
Mirrored (me; P : Pnt) returns Ax3 is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to the point P which is the
-- center of the symmetry.
-- Warnings :
-- The main direction of the axis placement is not changed.
-- The "XDirection" and the "YDirection" are reversed.
-- So the axis placement stay right handed.
Mirror (me : in out; A1 : Ax1) is static;
Mirrored (me; A1 : Ax1) returns Ax3 is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to an axis placement which
-- is the axis of the symmetry.
-- The transformation is performed on the "Location"
-- point, on the "XDirection" and "YDirection".
-- The resulting main "Direction" is the cross product between
-- the "XDirection" and the "YDirection" after transformation.
Mirror (me : in out; A2 : Ax2) is static;
Mirrored (me; A2 : Ax2) returns Ax3 is static;
--- Purpose :
-- Performs the symmetrical transformation of an axis
-- placement with respect to a plane.
-- The axis placement <A2> locates the plane of the symmetry :
-- (Location, XDirection, YDirection).
-- The transformation is performed on the "Location"
-- point, on the "XDirection" and "YDirection".
-- The resulting main "Direction" is the cross product between
-- the "XDirection" and the "YDirection" after transformation.
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
Rotated (me; A1 : Ax1; Ang : Real) returns Ax3 is static;
--- Purpose :
-- Rotates an axis placement. <A1> is the axis of the
-- rotation . Ang is the angular value of the rotation
-- in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
Scaled (me; P : Pnt; S : Real) returns Ax3 is static;
--- Purpose :
-- Applies a scaling transformation on the axis placement.
-- The "Location" point of the axisplacement is modified.
-- Warnings :
-- If the scale <S> is negative :
-- . the main direction of the axis placement is not changed.
-- . The "XDirection" and the "YDirection" are reversed.
-- So the axis placement stay right handed.
Transform (me : in out; T : Trsf) is static;
Transformed (me; T : Trsf) returns Ax3 is static;
--- Purpose :
-- Transforms an axis placement with a Trsf.
-- The "Location" point, the "XDirection" and the
-- "YDirection" are transformed with T. The resulting
-- main "Direction" of <me> is the cross product between
-- the "XDirection" and the "YDirection" after transformation.
Translate (me : in out; V : Vec) is static;
Translated (me; V : Vec) returns Ax3 is static;
--- Purpose :
-- Translates an axis plaxement in the direction of the vector
-- <V>. The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt) is static;
Translated (me; P1, P2 : Pnt) returns Ax3 is static;
--- Purpose :
-- Translates an axis placement from the point <P1> to the
-- point <P2>.
fields
axis : Ax1 from gp;
vydir : Dir from gp;
vxdir : Dir from gp;
end;

89
src/gp/gp_Ax3.cxx Executable file
View File

@@ -0,0 +1,89 @@
// File: gp_Ax3.cxx
// Created: Tue Aug 3 12:42:36 1993
// Author: Laurent BOURESCHE
// <lbo@nonox>
#include <gp_Ax3.ixx>
//=======================================================================
//function : gp_Ax3
//purpose :
//=======================================================================
gp_Ax3::gp_Ax3 (const gp_Pnt& P,
const gp_Dir& V) : axis(P,V)
{
Standard_Real A = V.X();
Standard_Real B = V.Y();
Standard_Real C = V.Z();
Standard_Real Aabs = A;
if (Aabs < 0) Aabs = - Aabs;
Standard_Real Babs = B;
if (Babs < 0) Babs = - Babs;
Standard_Real Cabs = C;
if (Cabs < 0) Cabs = - Cabs;
gp_Dir D;
// pour determiner l axe X :
// on dit que le produit scalaire Vx.V = 0.
// et on recherche le max(A,B,C) pour faire la division.
// l une des coordonnees du vecteur est nulle.
if ( Babs <= Aabs && Babs <= Cabs) {
if (Aabs > Cabs) D.SetCoord(-C,0., A);
else D.SetCoord( C,0.,-A);
}
else if( Aabs <= Babs && Aabs <= Cabs) {
if (Babs > Cabs) D.SetCoord(0.,-C, B);
else D.SetCoord(0., C,-B);
}
else {
if (Aabs > Babs) D.SetCoord(-B, A,0.);
else D.SetCoord( B,-A,0.);
}
vxdir = D;
vydir = V.Crossed(vxdir);
}
void gp_Ax3::Mirror(const gp_Pnt& P)
{
axis.Mirror (P);
vxdir.Reverse ();
vydir.Reverse ();
}
gp_Ax3 gp_Ax3::Mirrored(const gp_Pnt& P)const
{
gp_Ax3 Temp = *this;
Temp.Mirror (P);
return Temp;
}
void gp_Ax3::Mirror(const gp_Ax1& A1)
{
vydir.Mirror (A1);
vxdir.Mirror (A1);
axis.Mirror (A1);
}
gp_Ax3 gp_Ax3::Mirrored(const gp_Ax1& A1)const
{
gp_Ax3 Temp = *this;
Temp.Mirror (A1);
return Temp;
}
void gp_Ax3::Mirror(const gp_Ax2& A2)
{
vydir.Mirror (A2);
vxdir.Mirror (A2);
axis.Mirror (A2);
}
gp_Ax3 gp_Ax3::Mirrored(const gp_Ax2& A2)const
{
gp_Ax3 Temp = *this;
Temp.Mirror (A2);
return Temp;
}

187
src/gp/gp_Ax3.lxx Executable file
View File

@@ -0,0 +1,187 @@
// File: gp_Ax3.lxx
#include <gp.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax1.hxx>
inline gp_Ax3::gp_Ax3() : vydir(0.,1.,0.), vxdir(1.,0.,0.)
{ }
inline gp_Ax3::gp_Ax3(const gp_Ax2& A) :
axis(A.Axis()),
vydir(A.YDirection()),
vxdir(A.XDirection())
{ }
inline gp_Ax3::gp_Ax3(const gp_Pnt& P, const gp_Dir& N, const gp_Dir& Vx) :
axis(P, N), vydir(N), vxdir(N)
{
vxdir.CrossCross(Vx, N);
vydir.Cross(vxdir);
}
inline void gp_Ax3::XReverse()
{ vxdir.Reverse(); }
inline void gp_Ax3::YReverse()
{ vydir.Reverse(); }
inline void gp_Ax3::ZReverse()
{ axis.Reverse(); }
inline void gp_Ax3::SetAxis(const gp_Ax1& A1)
{
Standard_Boolean direct = Direct();
axis = A1;
vxdir = axis.Direction().CrossCrossed (vxdir, axis.Direction());
if(direct) { vydir = axis.Direction().Crossed(vxdir); }
else { vydir = vxdir.Crossed(axis.Direction()); }
}
inline void gp_Ax3::SetDirection(const gp_Dir& V)
{
Standard_Boolean direct = Direct();
axis.SetDirection (V);
vxdir = V.CrossCrossed (vxdir, V);
if (direct) { vydir = V.Crossed (vxdir); }
else { vydir = vxdir.Crossed (V); }
}
inline void gp_Ax3::SetLocation(const gp_Pnt& P)
{ axis.SetLocation(P); }
inline void gp_Ax3::SetXDirection(const gp_Dir& Vx)
{
Standard_Boolean direct = Direct();
vxdir = axis.Direction().CrossCrossed (Vx, axis.Direction());
if (direct) { vydir = axis.Direction().Crossed(vxdir); }
else { vydir = vxdir.Crossed(axis.Direction()); }
}
inline void gp_Ax3::SetYDirection(const gp_Dir& Vy)
{
Standard_Boolean direct = Direct();
vxdir = Vy.Crossed (axis.Direction());
vydir = (axis.Direction()).Crossed (vxdir);
if (!direct) { vxdir.Reverse(); }
}
inline Standard_Real gp_Ax3::Angle(const gp_Ax3& Other) const
{ return axis.Angle (Other.axis); }
inline const gp_Ax1& gp_Ax3::Axis()const
{ return axis; }
inline gp_Ax2 gp_Ax3::Ax2()const
{
gp_Dir zz = axis.Direction();
if (!Direct()) { zz.Reverse(); }
return gp_Ax2 (axis.Location(),zz,vxdir);
}
inline const gp_Dir& gp_Ax3::Direction()const
{ return axis.Direction(); }
inline const gp_Pnt& gp_Ax3::Location()const
{ return axis.Location(); }
inline const gp_Dir& gp_Ax3::XDirection()const
{ return vxdir; }
inline const gp_Dir& gp_Ax3::YDirection()const
{ return vydir; }
inline Standard_Boolean gp_Ax3::Direct()const
{ return (vxdir.Crossed(vydir).Dot(axis.Direction()) > 0.); }
inline Standard_Boolean gp_Ax3::IsCoplanar
(const gp_Ax3& Other,
const Standard_Real LinearTolerance,
const Standard_Real AngularTolerance)const
{
gp_Vec vec(axis.Location(),Other.axis.Location());
Standard_Real D1 = gp_Vec(axis.Direction() ).Dot(vec);
if (D1 < 0) D1 = - D1;
Standard_Real D2 = gp_Vec(Other.axis.Direction()).Dot(vec);
if (D2 < 0) D2 = - D2;
return (D1 <= LinearTolerance && D2 <= LinearTolerance &&
axis.IsParallel (Other.axis, AngularTolerance));
}
inline Standard_Boolean gp_Ax3::IsCoplanar
(const gp_Ax1& A1,
const Standard_Real LinearTolerance,
const Standard_Real AngularTolerance)const
{
gp_Vec vec(axis.Location(),A1.Location());
Standard_Real D1 = gp_Vec(axis.Direction()).Dot(vec);
if (D1 < 0) D1 = - D1;
Standard_Real D2 = (gp_Vec(A1.Direction()).Crossed(vec)).Magnitude();
if (D2 < 0) D2 = - D2;
return (D1 <= LinearTolerance && D2 <= LinearTolerance &&
axis.IsNormal (A1, AngularTolerance));
}
inline void gp_Ax3::Rotate(const gp_Ax1& A1,
const Standard_Real Ang)
{
axis.Rotate (A1,Ang);
vxdir.Rotate (A1,Ang);
vydir.Rotate (A1,Ang);
}
inline gp_Ax3 gp_Ax3::Rotated(const gp_Ax1& A1,
const Standard_Real Ang)const
{
gp_Ax3 Temp = *this;
Temp.Rotate (A1,Ang);
return Temp;
}
inline void gp_Ax3::Scale(const gp_Pnt& P, const Standard_Real S)
{
axis.Scale (P,S);
if (S < 0.) {
vxdir.Reverse ();
vydir.Reverse ();
}
}
inline gp_Ax3 gp_Ax3::Scaled(const gp_Pnt& P,
const Standard_Real S)const
{
gp_Ax3 Temp = *this;
Temp.Scale (P,S);
return Temp;
}
inline void gp_Ax3::Transform(const gp_Trsf& T)
{
axis.Transform (T);
vxdir.Transform (T);
vydir.Transform (T);
}
inline gp_Ax3 gp_Ax3::Transformed(const gp_Trsf& T)const
{
gp_Ax3 Temp = *this;
Temp.Transform (T);
return Temp;
}
inline void gp_Ax3::Translate(const gp_Vec& V)
{ axis.Translate (V); }
inline gp_Ax3 gp_Ax3::Translated(const gp_Vec& V)const
{
gp_Ax3 Temp = *this;
Temp.Translate (V);
return Temp;
}
inline void gp_Ax3::Translate(const gp_Pnt& P1, const gp_Pnt& P2)
{ Translate(gp_Vec(P1,P2)); }
inline gp_Ax3 gp_Ax3::Translated(const gp_Pnt& P1, const gp_Pnt& P2)const
{ return Translated(gp_Vec(P1,P2)); }

251
src/gp/gp_Circ.cdl Executable file
View File

@@ -0,0 +1,251 @@
---Copyright: Matra Datavision 1991, 1992
class Circ from gp inherits Storable
--- Purpose :
-- Describes a circle in 3D space.
-- A circle is defined by its radius and positioned in space
-- with a coordinate system (a gp_Ax2 object) as follows:
-- - the origin of the coordinate system is the center of the circle, and
-- - the origin, "X Direction" and "Y Direction" of the
-- coordinate system define the plane of the circle.
-- This positioning coordinate system is the "local
-- coordinate system" of the circle. Its "main Direction"
-- gives the normal vector to the plane of the circle. The
-- "main Axis" of the coordinate system is referred to as
-- the "Axis" of the circle.
-- Note: when a gp_Circ circle is converted into a
-- Geom_Circle circle, some implicit properties of the
-- circle are used explicitly:
-- - the "main Direction" of the local coordinate system
-- gives an implicit orientation to the circle (and defines
-- its trigonometric sense),
-- - this orientation corresponds to the direction in
-- which parameter values increase,
-- - the starting point for parameterization is that of the
-- "X Axis" of the local coordinate system (i.e. the "X Axis" of the circle).
-- See Also
-- gce_MakeCirc which provides functions for more complex circle constructions
-- Geom_Circle which provides additional functions for
-- constructing circles and works, in particular, with the
-- parametric equations of circles
uses Ax1 from gp,
Ax2 from gp,
Pln from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard
is
Create returns Circ;
---C++: inline
--- Purpose : Creates an indefinite circle.
Create (A2 : Ax2; Radius : Real) returns Circ
---C++: inline
--- Purpose :
-- A2 locates the circle and gives its orientation in 3D space.
-- Warnings :
-- It is not forbidden to create a circle with Radius = 0.0 Raises ConstructionError if Radius < 0.0
raises ConstructionError;
SetAxis (me : in out; A1 : Ax1)
---C++: inline
--- Purpose :
-- Changes the main axis of the circle. It is the axis
-- perpendicular to the plane of the circle.
-- Raises ConstructionError if the direction of A1
-- is parallel to the "XAxis" of the circle.
raises ConstructionError
is static;
SetLocation (me : in out; P :Pnt) is static;
---C++:inline
--- Purpose :
-- Changes the "Location" point (center) of the circle.
SetPosition (me : in out; A2 : Ax2) is static;
---C++:inline
--- Purpose : Changes the position of the circle.
SetRadius (me : out; Radius : Real)
---C++: inline
---Purpose: Modifies the radius of this circle.
-- Warning. This class does not prevent the creation of a circle where Radius is null.
-- Exceptions
-- Standard_ConstructionError if Radius is negative.
raises ConstructionError
is static;
Area (me) returns Real is static;
---C++: inline
--- Purpose : Computes the area of the circle.
Axis (me) returns Ax1 is static;
---C++: inline
--- Purpose :
-- Returns the main axis of the circle.
-- It is the axis perpendicular to the plane of the circle,
-- passing through the "Location" point (center) of the circle.
---C++: return const&
Length (me) returns Real is static;
---C++: inline
--- Purpose : Computes the circumference of the circle.
Location (me) returns Pnt is static;
---C++: inline
--- Purpose :
-- Returns the center of the circle. It is the
-- "Location" point of the local coordinate system
-- of the circle
---C++: return const&
Position (me) returns Ax2 is static;
--- Purpose :
-- Returns the position of the circle.
-- It is the local coordinate system of the circle.
---C++: inline
---C++: return const&
Radius (me) returns Real is static;
---C++: inline
---Purpose: Returns the radius of this circle.
XAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose :
-- Returns the "XAxis" of the circle.
-- This axis is perpendicular to the axis of the conic.
-- This axis and the "Yaxis" define the plane of the conic.
YAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose :
-- Returns the "YAxis" of the circle.
-- This axis and the "Xaxis" define the plane of the conic.
-- The "YAxis" is perpendicular to the "Xaxis".
Distance (me; P : Pnt) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the minimum of distance between the point P and
-- any point on the circumference of the circle.
SquareDistance (me; P : Pnt) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the square distance between <me> and the point P.
Contains (me; P : Pnt; LinearTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- Returns True if the point P is on the circumference.
-- The distance between <me> and <P> must be lower or
-- equal to LinearTolerance.
Mirror (me : in out; P : Pnt) is static;
Mirrored (me; P : Pnt) returns Circ is static;
--- Purpose :
-- Performs the symmetrical transformation of a circle
-- with respect to the point P which is the center of the
-- symmetry.
Mirror (me : in out; A1 : Ax1) is static;
Mirrored (me; A1 : Ax1) returns Circ is static;
--- Purpose :
-- Performs the symmetrical transformation of a circle with
-- respect to an axis placement which is the axis of the
-- symmetry.
Mirror (me : in out; A2 : Ax2) is static;
Mirrored (me; A2 : Ax2) returns Circ is static;
--- Purpose :
-- Performs the symmetrical transformation of a circle with respect
-- to a plane. The axis placement A2 locates the plane of the
-- of the symmetry : (Location, XDirection, YDirection).
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
---C++: inline
Rotated (me; A1 : Ax1; Ang : Real) returns Circ is static;
---C++: inline
--- Purpose :
-- Rotates a circle. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt; S : Real) returns Circ is static;
---C++: inline
--- Purpose :
-- Scales a circle. S is the scaling value.
-- Warnings :
-- If S is negative the radius stay positive but
-- the "XAxis" and the "YAxis" are reversed as for
-- an ellipse.
Transform (me : in out; T : Trsf) is static;
---C++: inline
Transformed (me; T : Trsf) returns Circ is static;
---C++: inline
--- Purpose :
-- Transforms a circle with the transformation T from class Trsf.
Translate (me : in out; V : Vec) is static;
---C++: inline
Translated (me; V : Vec) returns Circ is static;
---C++: inline
--- Purpose :
-- Translates a circle in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt) is static;
---C++: inline
Translated (me; P1, P2 : Pnt) returns Circ is static;
---C++: inline
--- Purpose :
-- Translates a circle from the point P1 to the point P2.
fields
pos : Ax2;
radius : Real;
end;

34
src/gp/gp_Circ.cxx Executable file
View File

@@ -0,0 +1,34 @@
//File gp_Circ.cxx JCV 06/10/90
#include <gp_Circ.ixx>
void gp_Circ::Mirror (const gp_Pnt& P)
{ pos.Mirror(P); }
gp_Circ gp_Circ::Mirrored (const gp_Pnt& P) const
{
gp_Circ C = *this;
C.pos.Mirror (P);
return C;
}
void gp_Circ::Mirror (const gp_Ax1& A1)
{ pos.Mirror(A1); }
gp_Circ gp_Circ::Mirrored (const gp_Ax1& A1) const
{
gp_Circ C = *this;
C.pos.Mirror (A1);
return C;
}
void gp_Circ::Mirror (const gp_Ax2& A2)
{ pos.Mirror(A2); }
gp_Circ gp_Circ::Mirrored (const gp_Ax2& A2) const
{
gp_Circ C = *this;
C.pos.Mirror (A2);
return C;
}

141
src/gp/gp_Circ.lxx Executable file
View File

@@ -0,0 +1,141 @@
//File gp_Circ.lxx JCV 06/10/90
#include <Standard_ConstructionError.hxx>
#include <gp_Pnt.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
inline gp_Circ::gp_Circ () : radius(RealLast())
{ }
inline gp_Circ::gp_Circ (const gp_Ax2& A2,
const Standard_Real R) : pos(A2), radius(R)
{
Standard_ConstructionError_Raise_if (R < 0.0, "");
}
inline void gp_Circ::SetAxis (const gp_Ax1& A1)
{ pos.SetAxis (A1); }
inline void gp_Circ::SetLocation (const gp_Pnt& P)
{ pos.SetLocation (P); }
inline void gp_Circ::SetPosition (const gp_Ax2& A2)
{ pos = A2; }
inline void gp_Circ::SetRadius (const Standard_Real R)
{
Standard_ConstructionError_Raise_if (R < 0.0, "");
radius = R;
}
inline Standard_Real gp_Circ::Area() const
{ return Standard_PI*radius*radius; }
inline const gp_Ax1& gp_Circ::Axis () const
{ return pos.Axis(); }
inline Standard_Real gp_Circ::Length() const
{ return 2.*Standard_PI*radius; }
inline const gp_Pnt& gp_Circ::Location () const
{ return pos.Location(); }
inline const gp_Ax2& gp_Circ::Position() const
{ return pos; }
inline Standard_Real gp_Circ::Radius() const
{ return radius; }
inline gp_Ax1 gp_Circ::XAxis () const
{return gp_Ax1(pos.Location(), pos.XDirection());}
inline gp_Ax1 gp_Circ::YAxis () const
{return gp_Ax1(pos.Location(), pos.YDirection());}
inline Standard_Real gp_Circ::Distance (const gp_Pnt& P) const
{ return sqrt(SquareDistance(P)); }
inline Standard_Real gp_Circ::SquareDistance (const gp_Pnt& P) const
{
gp_Vec V(Location(),P);
Standard_Real x = V.Dot(pos.XDirection());
Standard_Real y = V.Dot(pos.YDirection());
Standard_Real z = V.Dot(pos.Direction ());
Standard_Real t = sqrt( x*x + y*y) - radius;
return (t*t + z*z);
}
inline Standard_Boolean gp_Circ::Contains
(const gp_Pnt& P,
const Standard_Real LinearTolerance) const
{ return Distance(P) <= LinearTolerance; }
inline void gp_Circ::Rotate (const gp_Ax1& A1,
const Standard_Real Ang)
{ pos.Rotate(A1, Ang); }
inline gp_Circ gp_Circ::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Circ C = *this;
C.pos.Rotate(A1, Ang);
return C;
}
inline void gp_Circ::Scale (const gp_Pnt& P,
const Standard_Real S)
{
radius *= S;
if (radius < 0) radius = - radius;
pos.Scale(P, S);
}
inline gp_Circ gp_Circ::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Circ C = *this;
C.radius *= S;
if (C.radius < 0) C.radius = - C.radius;
C.pos.Scale(P, S);
return C;
}
inline void gp_Circ::Transform (const gp_Trsf& T)
{
radius *= T.ScaleFactor();
if (radius < 0) radius = - radius;
pos.Transform(T);
}
inline gp_Circ gp_Circ::Transformed (const gp_Trsf& T) const
{
gp_Circ C = *this;
C.radius *= T.ScaleFactor();
if (C.radius < 0) C.radius = - C.radius;
C.pos.Transform(T);
return C;
}
inline void gp_Circ::Translate (const gp_Vec& V)
{ pos.Translate(V); }
inline gp_Circ gp_Circ::Translated (const gp_Vec& V) const
{
gp_Circ C = *this;
C.pos.Translate(V);
return C;
}
inline void gp_Circ::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{pos.Translate(P1,P2);}
inline gp_Circ gp_Circ::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Circ C = *this;
C.pos.Translate(P1, P2);
return C;
}

255
src/gp/gp_Circ2d.cdl Executable file
View File

@@ -0,0 +1,255 @@
---Copyright: Matra Datavision 1991
class Circ2d from gp inherits Storable
--- Purpose : Describes a circle in the plane (2D space).
-- A circle is defined by its radius and positioned in the
-- plane with a coordinate system (a gp_Ax22d object) as follows:
-- - the origin of the coordinate system is the center of the circle, and
-- - the orientation (direct or indirect) of the coordinate
-- system gives an implicit orientation to the circle (and
-- defines its trigonometric sense).
-- This positioning coordinate system is the "local
-- coordinate system" of the circle.
-- Note: when a gp_Circ2d circle is converted into a
-- Geom2d_Circle circle, some implicit properties of the
-- circle are used explicitly:
-- - the implicit orientation corresponds to the direction in
-- which parameter values increase,
-- - the starting point for parameterization is that of the "X
-- Axis" of the local coordinate system (i.e. the "X Axis" of the circle).
-- See Also
-- GccAna and Geom2dGcc packages which provide
-- functions for constructing circles defined by geometric constraints
-- gce_MakeCirc2d which provides functions for more
-- complex circle constructions
-- Geom2d_Circle which provides additional functions for
-- constructing circles and works, with the parametric
-- equations of circles in particular gp_Ax22d
uses Ax2d from gp,
Ax22d from gp,
Pnt2d from gp,
Trsf2d from gp,
Vec2d from gp
raises ConstructionError from Standard
is
Create returns Circ2d;
---C++: inline
--- Purpose : creates an indefinite circle.
Create (XAxis : Ax2d;
Radius : Real;
Sense : Boolean from Standard = Standard_True) returns Circ2d
---C++: inline
--- Purpose :
-- The location point of XAxis is the center of the circle.
-- Warnings :
-- It is not forbidden to create a circle with Radius = 0.0 Raises ConstructionError if Radius < 0.0.
raises ConstructionError;
--- Purpose : Raised if Radius < 0.0.
Create (Axis : Ax22d; Radius : Real) returns Circ2d
---C++: inline
--- Purpose :
-- Axis defines the Xaxis and Yaxis of the circle which defines
-- the origin and the sense of parametrization.
-- The location point of Axis is the center of the circle.
-- Warnings :
-- It is not forbidden to create a circle with Radius = 0.0 Raises ConstructionError if Radius < 0.0.
raises ConstructionError;
--- Purpose : Raised if Radius < 0.0.
SetLocation (me : in out; P : Pnt2d) is static;
--- Purpose : Changes the location point (center) of the circle.
SetXAxis (me : in out; A : Ax2d) is static;
---C++:inline
--- Purpose : Changes the X axis of the circle.
SetAxis (me : in out; A : Ax22d) is static;
---C++:inline
--- Purpose : Changes the X axis of the circle.
SetYAxis (me : in out; A : Ax2d) is static;
---C++:inline
--- Purpose : Changes the Y axis of the circle.
SetRadius (me : in out; Radius : Real)
---C++:inline
---Purpose: Modifies the radius of this circle.
-- This class does not prevent the creation of a circle where
-- Radius is null.
-- Exceptions
-- Standard_ConstructionError if Radius is negative.
raises ConstructionError
is static;
Area (me) returns Real is static;
---C++: inline
--- Purpose : Computes the area of the circle.
Coefficients (me; A, B, C, D, E, F : out Real) is static;
---C++: inline
--- Purpose :
-- Returns the normalized coefficients from the implicit equation
-- of the circle :
-- A * (X**2) + B * (Y**2) + 2*C*(X*Y) + 2*D*X + 2*E*Y + F = 0.0
Contains (me; P : Pnt2d; LinearTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose : Does <me> contain P ?
-- Returns True if the distance between P and any point on
-- the circumference of the circle is lower of equal to
-- <LinearTolerance>.
Distance (me; P : Pnt2d) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the minimum of distance between the point P and any
-- point on the circumference of the circle.
SquareDistance (me; P : Pnt2d) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the square distance between <me> and the point P.
Length (me) returns Real is static;
--- Purpose : computes the circumference of the circle.
---C++: inline
Location (me) returns Pnt2d is static;
---C++:inline
--- Purpose : Returns the location point (center) of the circle.
---C++: return const&
Radius (me) returns Real is static;
--- Purpose : Returns the radius value of the circle.
---C++: inline
Axis (me) returns Ax22d is static;
--- Purpose : returns the position of the circle.
---C++: inline
---C++: return const&
Position (me) returns Ax22d is static;
--- Purpose : returns the position of the circle. Idem Axis(me).
---C++: inline
---C++: return const&
XAxis (me) returns Ax2d is static;
---C++: inline
--- Purpose : returns the X axis of the circle.
YAxis (me) returns Ax2d is static;
---C++: inline
--- Purpose : Returns the Y axis of the circle.
--- Purpose : Reverses the direction of the circle.
Reverse (me : in out) is static;
---C++: inline
--- Purpose: Reverses the orientation of the local coordinate system
-- of this circle (the "Y Direction" is reversed) and therefore
--- changes the implicit orientation of this circle.
-- Reverse assigns the result to this circle,
Reversed (me) returns Circ2d is static;
---C++: inline
---Purpose: Reverses the orientation of the local coordinate system
-- of this circle (the "Y Direction" is reversed) and therefore
-- changes the implicit orientation of this circle.
-- Reversed creates a new circle.
IsDirect (me) returns Boolean is static;
---C++: inline
--- Purpose : Returns true if the local coordinate system is direct
-- and false in the other case.
Mirror (me : in out; P : Pnt2d) is static;
Mirrored (me; P : Pnt2d) returns Circ2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a circle with respect
-- to the point P which is the center of the symmetry
Mirror (me : in out; A : Ax2d) is static;
Mirrored (me; A : Ax2d) returns Circ2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a circle with respect
-- to an axis placement which is the axis of the symmetry.
Rotate (me : in out; P : Pnt2d; Ang : Real) is static;
---C++: inline
Rotated (me; P : Pnt2d; Ang : Real) returns Circ2d is static;
---C++: inline
--- Purpose :
-- Rotates a circle. P is the center of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt2d; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt2d; S : Real) returns Circ2d is static;
---C++: inline
--- Purpose :
-- Scales a circle. S is the scaling value.
-- Warnings :
-- If S is negative the radius stay positive but
-- the "XAxis" and the "YAxis" are reversed as for
-- an ellipse.
Transform (me : in out; T : Trsf2d) is static;
---C++: inline
Transformed (me; T : Trsf2d) returns Circ2d is static;
---C++: inline
--- Purpose :
-- Transforms a circle with the transformation T from class Trsf2d.
Translate (me : in out; V : Vec2d) is static;
---C++: inline
Translated (me; V : Vec2d) returns Circ2d is static;
---C++: inline
--- Purpose :
-- Translates a circle in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt2d) is static;
---C++: inline
Translated (me; P1, P2 : Pnt2d) returns Circ2d is static;
---C++: inline
--- Purpose :
-- Translates a circle from the point P1 to the point P2.
fields
pos : Ax22d;
radius : Real;
end;

25
src/gp/gp_Circ2d.cxx Executable file
View File

@@ -0,0 +1,25 @@
//File gp_Circ2d.cxx FID 30/10/90
//modif JCV 10/01/91 suite a la deuxieme revue de projet toolkit geometry
#include <gp_Circ2d.ixx>
void gp_Circ2d::Mirror (const gp_Pnt2d& P)
{ pos.Mirror(P); }
gp_Circ2d gp_Circ2d::Mirrored (const gp_Pnt2d& P) const
{
gp_Circ2d C = *this;
C.pos.Mirror (P);
return C;
}
void gp_Circ2d::Mirror (const gp_Ax2d& A)
{ pos.Mirror (A); }
gp_Circ2d gp_Circ2d::Mirrored (const gp_Ax2d& A) const
{
gp_Circ2d C = *this;
C.pos.Mirror (A);
return C;
}

189
src/gp/gp_Circ2d.lxx Executable file
View File

@@ -0,0 +1,189 @@
//File gp_Circ2d.lxx
#include <Standard_ConstructionError.hxx>
inline gp_Circ2d::gp_Circ2d () : radius(RealLast())
{ }
inline gp_Circ2d::gp_Circ2d (const gp_Ax2d& XAxis,
const Standard_Real Radius,
const Standard_Boolean Sense) : radius(Radius)
{
Standard_ConstructionError_Raise_if(Radius < 0.0,"");
pos = gp_Ax22d(XAxis,Sense);
}
inline gp_Circ2d::gp_Circ2d (const gp_Ax22d& Axis,
const Standard_Real Radius) :
pos(Axis),
radius(Radius)
{ Standard_ConstructionError_Raise_if(Radius < 0.0,""); }
inline void gp_Circ2d::SetLocation (const gp_Pnt2d& P)
{ pos.SetLocation (P); }
inline void gp_Circ2d::SetXAxis (const gp_Ax2d& A)
{ pos.SetXAxis(A); }
inline void gp_Circ2d::SetAxis (const gp_Ax22d& A)
{ pos.SetAxis(A);}
inline void gp_Circ2d::SetYAxis (const gp_Ax2d& A)
{ pos.SetYAxis(A); }
inline void gp_Circ2d::SetRadius (const Standard_Real Radius)
{
Standard_ConstructionError_Raise_if(Radius < 0.0,"");
radius = Radius;
}
inline Standard_Real gp_Circ2d::Area() const
{ return Standard_PI*radius*radius; }
inline void gp_Circ2d::Coefficients (Standard_Real& A,
Standard_Real& B,
Standard_Real& C,
Standard_Real& D,
Standard_Real& E,
Standard_Real& F) const
{
Standard_Real Xc = pos.Location().X();
Standard_Real Yc = pos.Location().Y();
A = 1.0;
B = 1.0;
C = 0.0;
D = - Xc;
E = - Yc;
F = Xc * Xc + Yc * Yc - radius * radius;
}
inline Standard_Boolean gp_Circ2d::Contains
(const gp_Pnt2d& P,
const Standard_Real LinearTolerance) const
{ return Distance(P) <= LinearTolerance; }
inline Standard_Real gp_Circ2d::Distance (const gp_Pnt2d& P) const
{
gp_XY Coord = P.XY();
Coord.Subtract (pos.Location().XY());
Standard_Real D = radius - Coord.Modulus();
if (D < 0) D = - D;
return D;
}
inline Standard_Real gp_Circ2d::SquareDistance (const gp_Pnt2d& P) const
{
gp_XY Coord = P.XY();
Coord.Subtract (pos.Location().XY());
Standard_Real D = radius - Coord.Modulus();
return D * D;
}
inline Standard_Real gp_Circ2d::Length() const
{ return 2.*Standard_PI*radius; }
inline const gp_Pnt2d& gp_Circ2d::Location () const
{return pos.Location(); }
inline Standard_Real gp_Circ2d::Radius() const
{ return radius; }
inline const gp_Ax22d& gp_Circ2d::Axis () const
{ return pos; }
inline const gp_Ax22d& gp_Circ2d::Position () const
{ return pos; }
inline gp_Ax2d gp_Circ2d::XAxis () const
{ return gp_Ax2d (pos.XAxis()); }
inline gp_Ax2d gp_Circ2d::YAxis () const
{ return gp_Ax2d (pos.YAxis()); }
inline void gp_Circ2d::Reverse()
{
gp_Dir2d Temp = pos.YDirection ();
Temp.Reverse ();
pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp));
}
inline gp_Circ2d gp_Circ2d::Reversed() const
{
gp_Circ2d C = *this;
gp_Dir2d Temp = pos.YDirection ();
Temp.Reverse ();
C.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp));
return C;
}
inline Standard_Boolean gp_Circ2d::IsDirect() const
{ return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; }
inline void gp_Circ2d::Rotate (const gp_Pnt2d& P,
const Standard_Real Ang)
{pos.Rotate (P, Ang);}
inline gp_Circ2d gp_Circ2d::Rotated (const gp_Pnt2d& P,
const Standard_Real Ang) const
{
gp_Circ2d C = *this;
C.pos.Rotate (P, Ang);
return C;
}
inline void gp_Circ2d::Scale (const gp_Pnt2d& P,
const Standard_Real S)
{
radius *= S;
if (radius < 0) radius = - radius;
pos.Scale(P, S);
}
inline gp_Circ2d gp_Circ2d::Scaled (const gp_Pnt2d& P,
const Standard_Real S) const
{
gp_Circ2d C = *this;
C.radius *= S;
if (C.radius < 0) C.radius = - C.radius;
C.pos.Scale(P, S);
return C;
}
inline void gp_Circ2d::Transform (const gp_Trsf2d& T)
{
radius *= T.ScaleFactor();
if (radius < 0) radius = - radius;
pos.Transform(T);
}
inline gp_Circ2d gp_Circ2d::Transformed (const gp_Trsf2d& T) const
{
gp_Circ2d C = *this;
C.radius *= T.ScaleFactor();
if (C.radius < 0) C.radius = - C.radius;
C.pos.Transform(T);
return C;
}
inline void gp_Circ2d::Translate (const gp_Vec2d& V)
{ pos.Translate(V); }
inline gp_Circ2d gp_Circ2d::Translated (const gp_Vec2d& V) const
{
gp_Circ2d C = *this;
C.pos.Translate(V);
return C;
}
inline void gp_Circ2d::Translate (const gp_Pnt2d& P1,
const gp_Pnt2d& P2)
{ pos.Translate(P1, P2); }
inline gp_Circ2d gp_Circ2d::Translated (const gp_Pnt2d& P1,
const gp_Pnt2d& P2) const
{
gp_Circ2d C = *this;
C.pos.Translate(P1, P2);
return C;
}

259
src/gp/gp_Cone.cdl Executable file
View File

@@ -0,0 +1,259 @@
---Copyright: Matra Datavision 1991
class Cone from gp inherits Storable
--- Purpose :
-- Defines an infinite conical surface.
-- A cone is defined by its half-angle at the apex and
-- positioned in space with a coordinate system (a gp_Ax3
-- object) and a "reference radius" where:
-- - the "main Axis" of the coordinate system is the axis of revolution of the cone,
-- - the plane defined by the origin, the "X Direction" and
-- the "Y Direction" of the coordinate system is the
-- reference plane of the cone; the intersection of the
-- cone with this reference plane is a circle of radius
-- equal to the reference radius,
-- if the half-angle is positive, the apex of the cone is on
-- the negative side of the "main Axis" of the coordinate
-- system. If the half-angle is negative, the apex is on the positive side.
-- This coordinate system is the "local coordinate system" of the cone.
-- Note: when a gp_Cone cone is converted into a
-- Geom_ConicalSurface cone, some implicit properties of
-- its local coordinate system are used explicitly:
-- - its origin, "X Direction", "Y Direction" and "main
-- Direction" are used directly to define the parametric
-- directions on the cone and the origin of the parameters,
-- - its implicit orientation (right-handed or left-handed)
-- gives the orientation (direct or indirect) of the
-- Geom_ConicalSurface cone.
-- See Also
-- gce_MakeCone which provides functions for more
-- complex cone constructions
-- Geom_ConicalSurface which provides additional
-- functions for constructing cones and works, in particular,
-- with the parametric equations of cones gp_Ax3
uses Ax1 from gp,
Ax2 from gp,
Ax3 from gp,
Dir from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard
is
Create returns Cone;
---C++:inline
--- Purpose : Creates an indefinite Cone.
Create (A3 : Ax3; Ang : Real; Radius : Real) returns Cone
---C++:inline
--- Purpose :
-- Creates an infinite conical surface. A3 locates the cone
-- in the space and defines the reference plane of the surface.
-- Ang is the conical surface semi-angle between 0 and PI/2 radians.
-- Radius is the radius of the circle in the reference plane of
-- the cone.
--- Raises ConstructionError
-- . if Radius is lower than 0.0
-- . Ang < Resolution from gp or Ang >= (PI/2) - Resolution.
raises ConstructionError;
SetAxis (me : in out; A1 : Ax1)
---C++:inline
--- Purpose : Changes the symmetry axis of the cone. Raises ConstructionError
-- the direction of A1 is parallel to the "XDirection"
-- of the coordinate system of the cone.
raises ConstructionError
is static;
SetLocation (me : in out; Loc : Pnt) is static;
---C++:inline
--- Purpose : Changes the location of the cone.
SetPosition (me : in out; A3 : Ax3) is static;
---C++:inline
--- Purpose :
-- Changes the local coordinate system of the cone.
-- This coordinate system defines the reference plane of the cone.
SetRadius (me : in out; R : Real)
---C++:inline
--- Purpose :
-- Changes the radius of the cone in the reference plane of
-- the cone.
raises ConstructionError
--- Purpose : Raised if R < 0.0
is static;
SetSemiAngle (me : in out; Ang : Real)
---C++:inline
--- Purpose :
-- Changes the semi-angle of the cone.
-- Ang is the conical surface semi-angle ]0,PI/2[.
-- Raises ConstructionError if Ang < Resolution from gp or Ang >= PI/2 - Resolution
raises ConstructionError
is static;
Apex (me) returns Pnt is static;
---C++:inline
--- Purpose :
-- Computes the cone's top. The Apex of the cone is on the
-- negative side of the symmetry axis of the cone.
UReverse (me : in out)
---C++:inline
---Purpose: Reverses the U parametrization of the cone
-- reversing the YAxis.
is static;
VReverse (me : in out)
---C++:inline
---Purpose: Reverses the V parametrization of the cone reversing the ZAxis.
is static;
Direct (me) returns Boolean from Standard
---C++:inline
---Purpose: Returns true if the local coordinate system of this cone is right-handed.
is static;
Axis (me) returns Ax1 is static;
---C++:inline
--- Purpose : returns the symmetry axis of the cone.
---C++: return const&
Coefficients (me; A1, A2, A3, B1, B2, B3, C1, C2, C3, D : out Real)
is static;
--- Purpose :
-- Computes the coefficients of the implicit equation of the quadric
-- in the absolute cartesian coordinates system :
-- A1.X**2 + A2.Y**2 + A3.Z**2 + 2.(B1.X.Y + B2.X.Z + B3.Y.Z) +
-- 2.(C1.X + C2.Y + C3.Z) + D = 0.0
Location (me) returns Pnt is static;
---C++:inline
--- Purpose : returns the "Location" point of the cone.
---C++: return const&
Position (me) returns Ax3 is static;
--- Purpose :
-- Returns the local coordinates system of the cone.
---C++: inline
---C++: return const&
RefRadius (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the radius of the cone in the reference plane.
SemiAngle (me) returns Real is static;
---C++: inline
---Purpose: Returns the half-angle at the apex of this cone.
XAxis (me) returns Ax1 is static;
---C++:inline
--- Purpose : Returns the XAxis of the reference plane.
YAxis (me) returns Ax1 is static;
---C++:inline
--- Purpose : Returns the YAxis of the reference plane.
Mirror (me : in out; P : Pnt) is static;
Mirrored (me; P : Pnt) returns Cone is static;
--- Purpose :
-- Performs the symmetrical transformation of a cone
-- with respect to the point P which is the center of the
-- symmetry.
Mirror (me : in out; A1 : Ax1) is static;
Mirrored (me; A1 : Ax1) returns Cone is static;
--- Purpose :
-- Performs the symmetrical transformation of a cone with
-- respect to an axis placement which is the axis of the
-- symmetry.
Mirror (me : in out; A2 : Ax2) is static;
Mirrored (me; A2 : Ax2) returns Cone is static;
--- Purpose :
-- Performs the symmetrical transformation of a cone with respect
-- to a plane. The axis placement A2 locates the plane of the
-- of the symmetry : (Location, XDirection, YDirection).
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
---C++: inline
Rotated (me; A1 : Ax1; Ang : Real) returns Cone is static;
---C++: inline
--- Purpose :
-- Rotates a cone. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt; S : Real) returns Cone is static;
---C++: inline
--- Purpose :
-- Scales a cone. S is the scaling value.
-- The absolute value of S is used to scale the cone
Transform (me : in out; T : Trsf) is static;
---C++: inline
Transformed (me; T : Trsf) returns Cone is static;
---C++: inline
--- Purpose :
-- Transforms a cone with the transformation T from class Trsf.
Translate (me : in out; V : Vec) is static;
---C++: inline
Translated (me; V : Vec) returns Cone is static;
---C++: inline
--- Purpose :
-- Translates a cone in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt) is static;
---C++: inline
Translated (me; P1, P2 : Pnt) returns Cone is static;
---C++: inline
--- Purpose :
-- Translates a cone from the point P1 to the point P2.
fields
pos : Ax3;
radius : Real;
semiAngle : Real;
end;

71
src/gp/gp_Cone.cxx Executable file
View File

@@ -0,0 +1,71 @@
//File gp_Cone.cxx JCV 09/03/91
// LPA, JCV 07/92 passage sur C1.
// JCV 07/92 Introduction de la method Dump
#include <gp_Cone.ixx>
void gp_Cone::Coefficients
(Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
Standard_Real& B1, Standard_Real& B2, Standard_Real& B3,
Standard_Real& C1, Standard_Real& C2, Standard_Real& C3,
Standard_Real& D) const
{
// Dans le repere du cone :
// X**2 + Y**2 - (radius + Z * Tan(semiAngle))**2 = 0.0
gp_Trsf T;
T.SetTransformation (pos);
Standard_Real KAng = Tan (semiAngle);
Standard_Real T11 = T.Value (1, 1);
Standard_Real T12 = T.Value (1, 2);
Standard_Real T13 = T.Value (1, 3);
Standard_Real T14 = T.Value (1, 4);
Standard_Real T21 = T.Value (2, 1);
Standard_Real T22 = T.Value (2, 2);
Standard_Real T23 = T.Value (2, 3);
Standard_Real T24 = T.Value (2, 4);
Standard_Real T31 = T.Value (3, 1) * KAng;
Standard_Real T32 = T.Value (3, 2) * KAng;
Standard_Real T33 = T.Value (3, 3) * KAng;
Standard_Real T34 = T.Value (3, 4) * KAng;
A1 = T11 * T11 + T21 * T21 - T31 * T31;
A2 = T12 * T12 + T22 * T22 - T32 * T32;
A3 = T13 * T13 + T23 * T23 - T33 * T33;
B1 = T11 * T12 + T21 * T22 - T31 * T32;
B2 = T11 * T13 + T21 * T23 - T31 * T33;
B3 = T12 * T13 + T22 * T23 - T32 * T33;
C1 = T11 * T14 + T21 * T24 - T31 * (radius + T34);
C2 = T12 * T14 + T22 * T24 - T32 * (radius + T34);
C3 = T13 * T14 + T23 * T24 - T33 * (radius + T34);
D = T14*T14 + T24*T24 - radius*radius - T34*T34 - 2.0*radius*T34;
}
void gp_Cone::Mirror (const gp_Pnt& P)
{ pos.Mirror (P); }
gp_Cone gp_Cone::Mirrored (const gp_Pnt& P) const
{
gp_Cone C = *this;
C.pos.Mirror (P);
return C;
}
void gp_Cone::Mirror (const gp_Ax1& A1)
{ pos.Mirror (A1); }
gp_Cone gp_Cone::Mirrored (const gp_Ax1& A1) const
{
gp_Cone C = *this;
C.pos.Mirror (A1);
return C;
}
void gp_Cone::Mirror (const gp_Ax2& A2)
{ pos.Mirror (A2); }
gp_Cone gp_Cone::Mirrored (const gp_Ax2& A2) const
{
gp_Cone C = *this;
C.pos.Mirror (A2);
return C;
}

157
src/gp/gp_Cone.lxx Executable file
View File

@@ -0,0 +1,157 @@
//File gp_Cone.lxx
#include <gp.hxx>
#include <Standard_ConstructionError.hxx>
inline gp_Cone::gp_Cone () :
radius (RealLast()),
semiAngle (Standard_PI * 0.25)
{ }
inline gp_Cone::gp_Cone (const gp_Ax3& A3,
const Standard_Real Ang,
const Standard_Real Radius) :
pos(A3),
radius (Radius),
semiAngle (Ang)
{
Standard_Real val = Ang;
if (val < 0) val = - val;
Standard_ConstructionError_Raise_if
(radius < 0. ||
val <= gp::Resolution() ||
Standard_PI * 0.5 - val <= gp::Resolution(), "");
}
inline void gp_Cone::SetAxis (const gp_Ax1& A1)
{ pos.SetAxis (A1); }
inline void gp_Cone::SetLocation (const gp_Pnt& Loc)
{ pos.SetLocation (Loc); }
inline void gp_Cone::SetPosition (const gp_Ax3& A3)
{ pos = A3; }
inline void gp_Cone::SetRadius (const Standard_Real R)
{
Standard_ConstructionError_Raise_if
(R < 0.0,"");
radius = R;
}
inline void gp_Cone::SetSemiAngle (const Standard_Real Ang)
{
Standard_Real val = Ang;
if (val < 0) val = - val;
Standard_ConstructionError_Raise_if
(val <= gp::Resolution() ||
Standard_PI * 0.5 - val <= gp::Resolution(),"");
semiAngle = Ang;
}
inline gp_Pnt gp_Cone::Apex () const
{
gp_XYZ Coord = pos.Direction ().XYZ ();
Coord.Multiply (-radius / Tan (semiAngle));
Coord.Add (pos.Location ().XYZ());
return gp_Pnt (Coord);
}
inline void gp_Cone::UReverse()
{ pos.YReverse(); }
inline void gp_Cone::VReverse()
{ pos.ZReverse(); semiAngle = -semiAngle; }
inline Standard_Boolean gp_Cone::Direct() const
{ return pos.Direct(); }
inline const gp_Ax1& gp_Cone::Axis () const
{ return pos.Axis(); }
inline const gp_Pnt& gp_Cone::Location () const
{ return pos.Location(); }
inline const gp_Ax3& gp_Cone::Position () const
{ return pos; }
inline Standard_Real gp_Cone::RefRadius () const
{ return radius; }
inline Standard_Real gp_Cone::SemiAngle () const
{ return semiAngle; }
inline gp_Ax1 gp_Cone::XAxis () const
{ return gp_Ax1 (pos.Location(), pos.XDirection()); }
inline gp_Ax1 gp_Cone::YAxis () const
{ return gp_Ax1 (pos.Location(), pos.YDirection()); }
inline void gp_Cone::Rotate (const gp_Ax1& A1,
const Standard_Real Ang)
{pos.Rotate (A1, Ang);}
inline gp_Cone gp_Cone::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Cone C = *this;
C.pos.Rotate (A1, Ang);
return C;
}
inline void gp_Cone::Scale (const gp_Pnt& P,
const Standard_Real S)
{
pos.Scale (P, S);
radius *= S;
if (radius < 0) radius = - radius;
}
inline gp_Cone gp_Cone::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Cone C = *this;
C.pos.Scale (P, S);
C.radius *= S;
if (C.radius < 0) C.radius = - C.radius;
return C;
}
inline void gp_Cone::Transform (const gp_Trsf& T)
{
pos.Transform (T);
radius *= T.ScaleFactor();
if (radius < 0) radius = - radius;
}
inline gp_Cone gp_Cone::Transformed (const gp_Trsf& T) const
{
gp_Cone C = *this;
C.pos.Transform (T);
C.radius *= T.ScaleFactor();
if (C.radius < 0) C.radius = - C.radius;
return C;
}
inline void gp_Cone::Translate (const gp_Vec& V)
{ pos.Translate (V); }
inline gp_Cone gp_Cone::Translated (const gp_Vec& V) const
{
gp_Cone C = *this;
C.pos.Translate (V);
return C;
}
inline void gp_Cone::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{ pos.Translate (P1, P2); }
inline gp_Cone gp_Cone::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Cone C = *this;
C.pos.Translate (P1, P2);
return C;
}

220
src/gp/gp_Cylinder.cdl Executable file
View File

@@ -0,0 +1,220 @@
---Copyright: Matra Datavision 1991
class Cylinder from gp inherits Storable
--- Purpose :
-- Describes an infinite cylindrical surface.
-- A cylinder is defined by its radius and positioned in space
-- with a coordinate system (a gp_Ax3 object), the "main
-- Axis" of which is the axis of the cylinder. This coordinate
-- system is the "local coordinate system" of the cylinder.
-- Note: when a gp_Cylinder cylinder is converted into a
-- Geom_CylindricalSurface cylinder, some implicit
-- properties of its local coordinate system are used explicitly:
-- - its origin, "X Direction", "Y Direction" and "main
-- Direction" are used directly to define the parametric
-- directions on the cylinder and the origin of the parameters,
-- - its implicit orientation (right-handed or left-handed)
-- gives an orientation (direct or indirect) to the
-- Geom_CylindricalSurface cylinder.
-- See Also
-- gce_MakeCylinder which provides functions for more
-- complex cylinder constructions
-- Geom_CylindricalSurface which provides additional
-- functions for constructing cylinders and works, in
-- particular, with the parametric equations of cylinders gp_Ax3
uses Ax1 from gp,
Ax2 from gp,
Ax3 from gp,
Dir from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard
is
Create returns Cylinder;
---C++: inline
--- Purpose : Creates a indefinite cylinder.
Create (A3 : Ax3; Radius : Real) returns Cylinder
---C++: inline
--- Purpose : Creates a cylinder of radius Radius, whose axis is the "main
-- Axis" of A3. A3 is the local coordinate system of the cylinder. Raises ConstructionErrord if R < 0.0
raises ConstructionError;
SetAxis (me : in out; A1 : Ax1)
---C++: inline
--- Purpose : Changes the symmetry axis of the cylinder. Raises ConstructionError if the direction of A1 is parallel to the "XDirection"
-- of the coordinate system of the cylinder.
raises ConstructionError
is static;
SetLocation (me : in out; Loc : Pnt) is static;
---C++:inline
--- Purpose : Changes the location of the surface.
SetPosition (me : in out; A3 : Ax3) is static;
---C++:inline
--- Purpose : Change the local coordinate system of the surface.
SetRadius (me : in out; R : Real)
---C++: inline
---Purpose: Modifies the radius of this cylinder.
-- Exceptions
-- Standard_ConstructionError if R is negative.
raises ConstructionError
is static;
UReverse (me : in out)
---C++:inline
---Purpose: Reverses the U parametrization of the cylinder
-- reversing the YAxis.
is static;
VReverse (me : in out)
---C++:inline
---Purpose: Reverses the V parametrization of the plane
-- reversing the Axis.
is static;
Direct (me) returns Boolean from Standard
---C++: inline
---Purpose: Returns true if the local coordinate system of this cylinder is right-handed.
is static;
Axis (me) returns Ax1 is static;
---C++: inline
--- Purpose : Returns the symmetry axis of the cylinder.
---C++: return const&
Coefficients (me; A1, A2, A3, B1, B2, B3, C1, C2, C3, D : out Real)
is static;
--- Purpose :
-- Computes the coefficients of the implicit equation of the quadric
-- in the absolute cartesian coordinate system :
-- A1.X**2 + A2.Y**2 + A3.Z**2 + 2.(B1.X.Y + B2.X.Z + B3.Y.Z) +
-- 2.(C1.X + C2.Y + C3.Z) + D = 0.0
Location (me) returns Pnt is static;
---C++: inline
--- Purpose : Returns the "Location" point of the cylinder.
---C++: return const&
Position (me) returns Ax3 is static;
--- Purpose :
-- Returns the local coordinate system of the cylinder.
---C++: inline
---C++: return const&
Radius (me) returns Real is static;
---C++: inline
--- Purpose : Returns the radius of the cylinder.
XAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose : Returns the axis X of the cylinder.
YAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose : Returns the axis Y of the cylinder.
Mirror (me : in out; P : Pnt) is static;
Mirrored (me; P : Pnt) returns Cylinder is static;
--- Purpose :
-- Performs the symmetrical transformation of a cylinder
-- with respect to the point P which is the center of the
-- symmetry.
Mirror (me : in out; A1 : Ax1) is static;
Mirrored (me; A1 : Ax1) returns Cylinder is static;
--- Purpose :
-- Performs the symmetrical transformation of a cylinder with
-- respect to an axis placement which is the axis of the
-- symmetry.
Mirror (me : in out; A2 : Ax2) is static;
Mirrored (me; A2 : Ax2) returns Cylinder is static;
--- Purpose :
-- Performs the symmetrical transformation of a cylinder with respect
-- to a plane. The axis placement A2 locates the plane of the
-- of the symmetry : (Location, XDirection, YDirection).
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
---C++: inline
Rotated (me; A1 : Ax1; Ang : Real) returns Cylinder is static;
---C++: inline
--- Purpose :
-- Rotates a cylinder. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt; S : Real) returns Cylinder is static;
---C++: inline
--- Purpose :
-- Scales a cylinder. S is the scaling value.
-- The absolute value of S is used to scale the cylinder
Transform (me : in out; T : Trsf) is static;
---C++: inline
Transformed (me; T : Trsf) returns Cylinder is static;
---C++: inline
--- Purpose :
-- Transforms a cylinder with the transformation T from class Trsf.
Translate (me : in out; V : Vec) is static;
---C++: inline
Translated (me; V : Vec) returns Cylinder is static;
---C++: inline
--- Purpose :
-- Translates a cylinder in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt) is static;
---C++: inline
Translated (me; P1, P2 : Pnt) returns Cylinder is static;
---C++: inline
--- Purpose :
-- Translates a cylinder from the point P1 to the point P2.
fields
pos : Ax3;
radius : Real;
end;

68
src/gp/gp_Cylinder.cxx Executable file
View File

@@ -0,0 +1,68 @@
//File gp_Cylinder.cxx JCV 09/03/91
// LPA, JCV 07/92 passage sur C1.
// JCV 07/92 Introduction de la method Dump
// LBO 08/93 passage aux Ax3
#include <gp_Cylinder.ixx>
#include <Standard_ConstructionError.hxx>
void gp_Cylinder::Coefficients
(Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
Standard_Real& B1, Standard_Real& B2, Standard_Real& B3,
Standard_Real& C1, Standard_Real& C2, Standard_Real& C3, Standard_Real& D) const
{
// Dans le repere local du cylindre :
// X**2 + Y**2 - radius = 0.0
gp_Trsf T;
T.SetTransformation (pos);
Standard_Real T11 = T.Value (1, 1);
Standard_Real T12 = T.Value (1, 2);
Standard_Real T13 = T.Value (1, 3);
Standard_Real T14 = T.Value (1, 4);
Standard_Real T21 = T.Value (2, 1);
Standard_Real T22 = T.Value (2, 2);
Standard_Real T23 = T.Value (2, 3);
Standard_Real T24 = T.Value (2, 4);
A1 = T11 * T11 + T21 * T21;
A2 = T12 * T12 + T22 * T22;
A3 = T13 * T13 + T23 * T23;
B1 = T11 * T12 + T21 * T22;
B2 = T11 * T13 + T21 * T23;
B3 = T12 * T13 + T22 * T23;
C1 = T11 * T14 + T21 * T24;
C2 = T12 * T14 + T22 * T24;
C3 = T13 * T14 + T23 * T24;
D = T14 * T14 + T24 * T24 - radius * radius;
}
void gp_Cylinder::Mirror (const gp_Pnt& P)
{ pos.Mirror (P); }
gp_Cylinder gp_Cylinder::Mirrored (const gp_Pnt& P) const
{
gp_Cylinder C = *this;
C.pos.Mirror (P);
return C;
}
void gp_Cylinder::Mirror (const gp_Ax1& A1)
{ pos.Mirror (A1); }
gp_Cylinder gp_Cylinder::Mirrored (const gp_Ax1& A1) const
{
gp_Cylinder C = *this;
C.pos.Mirror (A1);
return C;
}
void gp_Cylinder::Mirror (const gp_Ax2& A2)
{ pos.Mirror (A2); }
gp_Cylinder gp_Cylinder::Mirrored (const gp_Ax2& A2) const
{
gp_Cylinder C = *this;
C.pos.Mirror (A2);
return C;
}

122
src/gp/gp_Cylinder.lxx Executable file
View File

@@ -0,0 +1,122 @@
//File gp_Cylinder.lxx
#include <Standard_ConstructionError.hxx>
inline gp_Cylinder::gp_Cylinder ()
{ radius = RealLast(); }
inline gp_Cylinder::gp_Cylinder (const gp_Ax3& A3,
const Standard_Real Radius) :
pos(A3),
radius (Radius)
{ Standard_ConstructionError_Raise_if (Radius < 0.0,""); }
inline void gp_Cylinder::SetAxis (const gp_Ax1& A1)
{ pos.SetAxis (A1); }
inline void gp_Cylinder::SetLocation (const gp_Pnt& Loc)
{ pos.SetLocation (Loc); }
inline void gp_Cylinder::SetPosition (const gp_Ax3& A3)
{ pos = A3; }
inline void gp_Cylinder::SetRadius (const Standard_Real R)
{
Standard_ConstructionError_Raise_if (R < 0.0,"");
radius = R;
}
inline void gp_Cylinder::UReverse()
{ pos.YReverse(); }
inline void gp_Cylinder::VReverse()
{ pos.ZReverse(); }
inline Standard_Boolean gp_Cylinder::Direct() const
{ return pos.Direct(); }
inline const gp_Ax1& gp_Cylinder::Axis () const
{ return pos.Axis(); }
inline const gp_Pnt& gp_Cylinder::Location () const
{ return pos.Location(); }
inline const gp_Ax3& gp_Cylinder::Position () const
{ return pos; }
inline Standard_Real gp_Cylinder::Radius () const
{ return radius; }
inline gp_Ax1 gp_Cylinder::XAxis () const
{return gp_Ax1(pos.Location(), pos.XDirection());}
inline gp_Ax1 gp_Cylinder::YAxis () const
{return gp_Ax1(pos.Location(), pos.YDirection());}
inline void gp_Cylinder::Rotate (const gp_Ax1& A1,
const Standard_Real Ang)
{pos.Rotate(A1,Ang);}
inline gp_Cylinder gp_Cylinder::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Cylinder C = *this;
C.pos.Rotate (A1, Ang);
return C;
}
inline void gp_Cylinder::Scale (const gp_Pnt& P, const Standard_Real S)
{
pos.Scale (P, S);
radius *= S;
if (radius < 0) radius = - radius;
}
inline gp_Cylinder gp_Cylinder::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Cylinder C = *this;
C.pos.Scale (P, S);
C.radius *= S;
if (C.radius < 0) C.radius = - C.radius;
return C;
}
inline void gp_Cylinder::Transform (const gp_Trsf& T)
{
pos.Transform (T);
radius *= T.ScaleFactor();
if (radius < 0) radius = - radius;
}
inline gp_Cylinder gp_Cylinder::Transformed (const gp_Trsf& T) const
{
gp_Cylinder C = *this;
C.pos.Transform (T);
C.radius *= T.ScaleFactor();
if (C.radius < 0) C.radius = - C.radius;
return C;
}
inline void gp_Cylinder::Translate (const gp_Vec& V)
{ pos.Translate (V); }
inline gp_Cylinder gp_Cylinder::Translated (const gp_Vec& V) const
{
gp_Cylinder C = *this;
C.pos.Translate (V);
return C;
}
inline void gp_Cylinder::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{ pos.Translate (P1, P2); }
inline gp_Cylinder gp_Cylinder::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Cylinder C = *this;
C.pos.Translate (P1, P2);
return C;
}

307
src/gp/gp_Dir.cdl Executable file
View File

@@ -0,0 +1,307 @@
---Copyright: Matra Datavision 1991, 1992
class Dir from gp inherits Storable
---Purpose:
-- Describes a unit vector in 3D space. This unit vector is also called "Direction".
-- See Also
-- gce_MakeDir which provides functions for more complex
-- unit vector constructions
-- Geom_Direction which provides additional functions for
-- constructing unit vectors and works, in particular, with the
-- parametric equations of unit vectors.
uses Ax1 from gp,
Ax2 from gp,
Trsf from gp,
Vec from gp,
XYZ from gp
raises ConstructionError from Standard,
DomainError from Standard,
OutOfRange from Standard
is
Create returns Dir;
---C++:inline
--- Purpose : Creates a direction corresponding to X axis.
Create (V : Vec) returns Dir
---C++:inline
--- Purpose : Normalizes the vector V and creates a direction. Raises ConstructionError if V.Magnitude() <= Resolution.
raises ConstructionError;
Create (Coord : XYZ) returns Dir
---C++:inline
--- Purpose : Creates a direction from a triplet of coordinates. Raises ConstructionError if Coord.Modulus() <= Resolution from gp.
raises ConstructionError;
Create ( Xv, Yv, Zv : Real) returns Dir
---C++:inline
--- Purpose : Creates a direction with its 3 cartesian coordinates. Raises ConstructionError if Sqrt(Xv*Xv + Yv*Yv + Zv*Zv) <= Resolution
raises ConstructionError;
--- Purpose : Modification of the direction's coordinates
-- If Sqrt (X*X + Y*Y + Z*Z) <= Resolution from gp where
-- X, Y ,Z are the new coordinates it is not possible to
-- construct the direction and the method raises the
-- exception ConstructionError.
SetCoord (me: in out; Index : Integer; Xi : Real)
---C++:inline
---Purpose:
-- For this unit vector, assigns the value Xi to:
-- - the X coordinate if Index is 1, or
-- - the Y coordinate if Index is 2, or
-- - the Z coordinate if Index is 3,
-- and then normalizes it.
-- Warning
-- Remember that all the coordinates of a unit vector are
-- implicitly modified when any single one is changed directly.
-- Exceptions
-- Standard_OutOfRange if Index is not 1, 2, or 3.
-- Standard_ConstructionError if either of the following
-- is less than or equal to gp::Resolution():
-- - Sqrt(Xv*Xv + Yv*Yv + Zv*Zv), or
-- - the modulus of the number triple formed by the new
-- value Xi and the two other coordinates of this vector
-- that were not directly modified.
raises OutOfRange,
ConstructionError
is static;
SetCoord (me : in out; Xv, Yv, Zv : Real) raises ConstructionError is static;
---C++:inline
---Purpose: For this unit vector, assigns the values Xv, Yv and Zv to its three coordinates.
-- Remember that all the coordinates of a unit vector are
-- implicitly modified when any single one is changed directly.
SetX (me: in out; X : Real) raises ConstructionError is static;
---C++:inline
---Purpose: Assigns the given value to the X coordinate of this unit vector.
SetY (me: in out; Y : Real) raises ConstructionError is static;
---C++:inline
---Purpose: Assigns the given value to the Y coordinate of this unit vector.
SetZ (me: in out; Z : Real) raises ConstructionError is static;
---C++:inline
---Purpose: Assigns the given value to the Z coordinate of this unit vector.
SetXYZ (me: in out; Coord : XYZ) raises ConstructionError is static;
---C++:inline
---Purpose: Assigns the three coordinates of Coord to this unit vector.
Coord (me; Index : Integer) returns Real
---C++:inline
--- Purpose :
-- Returns the coordinate of range Index :
-- Index = 1 => X is returned
-- Index = 2 => Y is returned
-- Index = 3 => Z is returned
-- Exceptions
-- Standard_OutOfRange if Index is not 1, 2, or 3.
raises OutOfRange
is static;
Coord (me; Xv, Yv, Zv : out Real) is static;
---C++:inline
---Purpose: Returns for the unit vector its three coordinates Xv, Yv, and Zv.
X (me) returns Real is static;
---C++:inline
---Purpose: Returns the X coordinate for a unit vector.
Y (me) returns Real is static;
---C++:inline
---Purpose: Returns the Y coordinate for a unit vector.
Z (me) returns Real is static;
---C++:inline
---Purpose: Returns the Z coordinate for a unit vector.
XYZ (me) returns XYZ is static;
---C++: inline
---C++: return const&
--- Purpose : for this unit vector, returns its three coordinates as a number triplea.
IsEqual (me; Other : Dir; AngularTolerance : Real) returns Boolean
is static;
---C++:inline
--- Purpose :
-- Returns True if the angle between the two directions is
-- lower or equal to AngularTolerance.
IsNormal(me; Other : Dir; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- Returns True if the angle between this unit vector and the unit vector Other is equal to Pi/2 (normal).
IsOpposite (me; Other : Dir; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose:
-- Returns True if the angle between this unit vector and the unit vector Other is equal to Pi (opposite).
IsParallel (me; Other : Dir; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- Returns true if the angle between this unit vector and the
-- unit vector Other is equal to 0 or to Pi.
-- Note: the tolerance criterion is given by AngularTolerance.
Angle (me; Other : Dir) returns Real is static;
--- Purpose :
-- Computes the angular value in radians between <me> and
-- <Other>. This value is always positive in 3D space.
-- Returns the angle in the range [0, PI]
AngleWithRef (me; Other, VRef : Dir) returns Real
--- Purpose :
-- Computes the angular value between <me> and <Other>.
-- <VRef> is the direction of reference normal to <me> and <Other>
-- and its orientation gives the positive sense of rotation.
-- If the cross product <me> ^ <Other> has the same orientation
-- as <VRef> the angular value is positive else negative.
-- Returns the angular value in the range -PI and PI (in radians). Raises DomainError if <me> and <Other> are not parallel this exception is raised
-- when <VRef> is in the same plane as <me> and <Other>
-- The tolerance criterion is Resolution from package gp.
raises DomainError
is static;
Cross (me : in out; Right : Dir) raises ConstructionError is static;
--- Purpose : Computes the cross product between two directions
-- Raises the exception ConstructionError if the two directions
-- are parallel because the computed vector cannot be normalized
-- to create a direction.
---C++: inline
---C++: alias operator ^=
Crossed (me; Right : Dir) returns Dir raises ConstructionError is static;
--- Purpose : Computes the triple vector product.
-- <me> ^ (V1 ^ V2)
-- Raises the exception ConstructionError if V1 and V2 are parallel
-- or <me> and (V1^V2) are parallel because the computed vector
-- can't be normalized to create a direction.
---C++: inline
---C++: alias operator ^
CrossCross (me : in out; V1, V2 : Dir) raises ConstructionError is static;
--- Propose: Computes the double vector product this ^ (V1 ^ V2).
-- CrossCross assigns the result to this unit vector
-- Exceptions
-- Standard_ConstructionError if:
-- - V1 and V2 are parallel, or
-- - this unit vector and (V1 ^ V2) are parallel.
-- This is because, in these conditions, the computed vector
-- is null and cannot be normalized.
---C++: inline
CrossCrossed (me; V1, V2 : Dir) returns Dir raises ConstructionError
is static;
--- Purpose: Computes the double vector product this ^ (V1 ^ V2).
-- - CrossCrossed creates a new unit vector.
-- Exceptions
-- Standard_ConstructionError if:
-- - V1 and V2 are parallel, or
-- - this unit vector and (V1 ^ V2) are parallel.
-- This is because, in these conditions, the computed vector
-- is null and cannot be normalized.
---C++: inline
Dot (me; Other : Dir) returns Real is static;
--- Purpose : Computes the scalar product
---C++: inline
---C++: alias operator *
DotCross (me; V1, V2 : Dir) returns Real is static;
--- Purpose :
-- Computes the triple scalar product <me> * (V1 ^ V2).
-- Warnings :
-- The computed vector V1' = V1 ^ V2 is not normalized
-- to create a unitary vector. So this method never
-- raises an exception even if V1 and V2 are parallel.
---C++: inline
Reverse (me : in out) is static;
---C++: inline
Reversed (me) returns Dir is static;
--- Purpose : Reverses the orientation of a direction
---C++: inline
---C++: alias operator -
--- Purpose : geometric transformations
-- Performs the symmetrical transformation of a direction
-- with respect to the direction V which is the center of
-- the symmetry.]
Mirror (me : in out; V : Dir) is static;
Mirrored (me; V : Dir) returns Dir is static;
--- Purpose :
-- Performs the symmetrical transformation of a direction
-- with respect to the direction V which is the center of
-- the symmetry.
Mirror (me : in out; A1 : Ax1) is static;
Mirrored (me; A1 : Ax1) returns Dir is static;
--- Purpose :
-- Performs the symmetrical transformation of a direction
-- with respect to an axis placement which is the axis
-- of the symmetry.
Mirror (me : in out; A2 : Ax2) is static;
Mirrored (me; A2 : Ax2) returns Dir is static;
--- Purpose :
-- Performs the symmetrical transformation of a direction
-- with respect to a plane. The axis placement A2 locates
-- the plane of the symmetry : (Location, XDirection, YDirection).
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
---C++: inline
Rotated (me; A1 : Ax1; Ang : Real) returns Dir is static;
---C++: inline
--- Purpose :
-- Rotates a direction. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Transform (me : in out; T : Trsf) is static;
Transformed (me; T : Trsf) returns Dir is static;
--- Purpose :
-- Transforms a direction with a "Trsf" from gp.
-- Warnings :
-- If the scale factor of the "Trsf" T is negative then the
-- direction <me> is reversed.
---C++: inline
fields
coord : XYZ;
end;

126
src/gp/gp_Dir.cxx Executable file
View File

@@ -0,0 +1,126 @@
// File gp_Dir.cxx , JCV 01/10/90
// JCV 07/12/90 Modifs suite a l'introduction des classes XYZ et Mat dans gp
#include <gp_Dir.ixx>
Standard_Real gp_Dir::Angle (const gp_Dir& Other) const
{
// Commentaires :
// Au dessus de 45 degres l'arccos donne la meilleur precision pour le
// calcul de l'angle. Sinon il vaut mieux utiliser l'arcsin.
// Les erreurs commises sont loin d'etre negligeables lorsque l'on est
// proche de zero ou de 90 degres.
// En 3d les valeurs angulaires sont toujours positives et comprises entre
// 0 et PI
Standard_Real Cosinus = coord.Dot (Other.coord);
if (Cosinus > -0.70710678118655 && Cosinus < 0.70710678118655)
return acos (Cosinus);
else {
Standard_Real Sinus = (coord.Crossed (Other.coord)).Modulus ();
if(Cosinus < 0.0) return Standard_PI - asin (Sinus);
else return asin (Sinus);
}
}
Standard_Real gp_Dir::AngleWithRef (const gp_Dir& Other,
const gp_Dir& Vref) const
{
Standard_Real Ang;
gp_XYZ XYZ = coord.Crossed (Other.coord);
Standard_Real Cosinus = coord.Dot(Other.coord);
Standard_Real Sinus = XYZ.Modulus ();
if (Cosinus > -0.70710678118655 && Cosinus < 0.70710678118655)
Ang = acos (Cosinus);
else {
if(Cosinus < 0.0) Ang = Standard_PI - asin (Sinus);
else Ang = asin (Sinus);
}
if (XYZ.Dot (Vref.coord) >= 0.0) return Ang;
else return -Ang;
}
void gp_Dir::Mirror (const gp_Dir& V)
{
const gp_XYZ& XYZ = V.coord;
Standard_Real A = XYZ.X();
Standard_Real B = XYZ.Y();
Standard_Real C = XYZ.Z();
Standard_Real X = coord.X();
Standard_Real Y = coord.Y();
Standard_Real Z = coord.Z();
Standard_Real M1 = 2.0 * A * B;
Standard_Real M2 = 2.0 * A * C;
Standard_Real M3 = 2.0 * B * C;
Standard_Real XX = ((2.0 * A * A) - 1.0) * X + M1 * Y + M2 * Z;
Standard_Real YY = M1 * X + ((2.0 * B * B) - 1.0) * Y + M3 * Z;
Standard_Real ZZ = M2 * X + M3 * Y + ((2.0 * C * C) - 1.0) * Z;
coord.SetCoord(XX,YY,ZZ);
}
void gp_Dir::Mirror (const gp_Ax1& A1)
{
const gp_XYZ& XYZ = A1.Direction().coord;
Standard_Real A = XYZ.X();
Standard_Real B = XYZ.Y();
Standard_Real C = XYZ.Y();
Standard_Real X = coord.X();
Standard_Real Y = coord.Y();
Standard_Real Z = coord.Z();
Standard_Real M1 = 2.0 * A * B;
Standard_Real M2 = 2.0 * A * C;
Standard_Real M3 = 2.0 * B * C;
Standard_Real XX = ((2.0 * A * A) - 1.0) * X + M1 * Y + M2 * Z;
Standard_Real YY = M1 * X + ((2.0 * B * B) - 1.0) * Y + M3 * Z;
Standard_Real ZZ = M2 * X + M3 * Y + ((2.0 * C * C) - 1.0) * Z;
coord.SetCoord(XX,YY,ZZ);
}
void gp_Dir::Mirror (const gp_Ax2& A2)
{
gp_XYZ Z = A2.Direction().XYZ();
gp_XYZ MirXYZ = Z.Crossed (coord);
if (MirXYZ.Modulus() <= gp::Resolution())
{ coord.Reverse(); }
else {
Z.Cross (MirXYZ);
gp_Dir MirDirection (MirXYZ);
Mirror (MirDirection);
}
}
void gp_Dir::Transform (const gp_Trsf& T)
{
if (T.Form() == gp_Identity || T.Form() == gp_Translation) { }
else if (T.Form() == gp_PntMirror) { coord.Reverse(); }
else if (T.Form() == gp_Scale) {
if (T.ScaleFactor() < 0.0) { coord.Reverse(); }
}
else {
coord.Multiply (T.HVectorialPart());
Standard_Real D = coord.Modulus();
coord.Divide(D);
if (T.ScaleFactor() < 0.0) { coord.Reverse(); }
}
}
gp_Dir gp_Dir::Mirrored (const gp_Dir& V) const
{
gp_Dir Vres = *this;
Vres.Mirror (V);
return Vres;
}
gp_Dir gp_Dir::Mirrored (const gp_Ax1& A1) const
{
gp_Dir V = *this;
V.Mirror (A1);
return V;
}
gp_Dir gp_Dir::Mirrored (const gp_Ax2& A2) const
{
gp_Dir V = *this;
V.Mirror (A2);
return V;
}

242
src/gp/gp_Dir.lxx Executable file
View File

@@ -0,0 +1,242 @@
// File gp_Dir.lxx , JCV 01/10/90
#include <gp_Vec.hxx>
#include <gp_Trsf.hxx>
#include <Standard_ConstructionError.hxx>
#include <Standard_OutOfRange.hxx>
inline gp_Dir::gp_Dir () : coord(1.,0.,0.)
{
}
inline gp_Dir::gp_Dir (const gp_Vec& V)
{
const gp_XYZ& XYZ = V.XYZ();
Standard_Real X = XYZ.X();
Standard_Real Y = XYZ.Y();
Standard_Real Z = XYZ.Z();
Standard_Real D = sqrt(X * X + Y * Y + Z * Z);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
coord.SetZ(Z / D);
}
inline gp_Dir::gp_Dir (const gp_XYZ& XYZ)
{
Standard_Real X = XYZ.X();
Standard_Real Y = XYZ.Y();
Standard_Real Z = XYZ.Z();
Standard_Real D = sqrt(X * X + Y * Y + Z * Z);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
coord.SetZ(Z / D);
}
inline gp_Dir::gp_Dir (const Standard_Real Xv,
const Standard_Real Yv,
const Standard_Real Zv)
{
Standard_Real D = sqrt (Xv * Xv + Yv * Yv + Zv * Zv);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(Xv / D);
coord.SetY(Yv / D);
coord.SetZ(Zv / D);
}
inline void gp_Dir::SetCoord (const Standard_Integer Index,
const Standard_Real Xi)
{
Standard_Real X = coord.X();
Standard_Real Y = coord.Y();
Standard_Real Z = coord.Z();
Standard_OutOfRange_Raise_if (Index < 1 || Index > 3, " ");
if (Index == 1) X = Xi;
else if (Index == 2) Y = Xi;
else Z = Xi;
Standard_Real D = sqrt (X * X + Y * Y + Z * Z);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
coord.SetZ(Z / D);
}
inline void gp_Dir::SetCoord (const Standard_Real Xv,
const Standard_Real Yv,
const Standard_Real Zv) {
Standard_Real D = sqrt(Xv * Xv + Yv * Yv + Zv * Zv);
Standard_ConstructionError_Raise_if(D <= gp::Resolution(), "");
coord.SetX(Xv / D);
coord.SetY(Yv / D);
coord.SetZ(Zv / D);
}
inline void gp_Dir::SetX (const Standard_Real X)
{
Standard_Real Y = coord.Y();
Standard_Real Z = coord.Z();
Standard_Real D = sqrt (X * X + Y * Y + Z * Z);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
coord.SetZ(Z / D);
}
inline void gp_Dir::SetY (const Standard_Real Y)
{
Standard_Real Z = coord.Z();
Standard_Real X = coord.X();
Standard_Real D = sqrt (X * X + Y * Y + Z * Z);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
coord.SetZ(Z / D);
}
inline void gp_Dir::SetZ (const Standard_Real Z)
{
Standard_Real X = coord.X();
Standard_Real Y = coord.Y();
Standard_Real D = sqrt (X * X + Y * Y + Z * Z);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
coord.SetZ(Z / D);
}
inline void gp_Dir::SetXYZ (const gp_XYZ& XYZ)
{
Standard_Real X = XYZ.X();
Standard_Real Y = XYZ.Y();
Standard_Real Z = XYZ.Z();
Standard_Real D = sqrt(X * X + Y * Y + Z * Z);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
coord.SetZ(Z / D);
}
inline Standard_Real gp_Dir::Coord (const Standard_Integer Index) const
{ return coord.Coord (Index);}
inline void gp_Dir::Coord (Standard_Real& Xv,
Standard_Real& Yv,
Standard_Real& Zv) const
{ coord.Coord (Xv, Yv, Zv); }
inline Standard_Real gp_Dir::X() const
{ return coord.X() ; }
inline Standard_Real gp_Dir::Y() const
{ return coord.Y() ; }
inline Standard_Real gp_Dir::Z() const
{ return coord.Z() ; }
inline const gp_XYZ& gp_Dir::XYZ () const
{ return coord; }
inline Standard_Boolean gp_Dir::IsEqual
(const gp_Dir& Other,
const Standard_Real AngularTolerance) const
{ return Angle (Other) <= AngularTolerance; }
inline Standard_Boolean gp_Dir::IsNormal
(const gp_Dir& Other,
const Standard_Real AngularTolerance) const
{
Standard_Real Ang = Standard_PI / 2.0 - Angle (Other);
if (Ang < 0) Ang = - Ang;
return Ang <= AngularTolerance;
}
inline Standard_Boolean gp_Dir::IsOpposite
(const gp_Dir& Other,
const Standard_Real AngularTolerance) const
{ return Standard_PI - Angle (Other) <= AngularTolerance; }
inline Standard_Boolean gp_Dir::IsParallel
(const gp_Dir& Other,
const Standard_Real AngularTolerance) const
{
Standard_Real Ang = Angle (Other);
return Ang <= AngularTolerance || Standard_PI - Ang <= AngularTolerance;
}
inline void gp_Dir::Cross (const gp_Dir& Right)
{
coord.Cross (Right.coord);
Standard_Real D = coord.Modulus ();
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.Divide (D);
}
inline gp_Dir gp_Dir::Crossed (const gp_Dir& Right) const
{
gp_Dir V = *this;
V.coord.Cross (Right.coord);
Standard_Real D = V.coord.Modulus();
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
V.coord.Divide (D);
return V;
}
inline void gp_Dir::CrossCross (const gp_Dir& V1,
const gp_Dir& V2)
{
coord.CrossCross (V1.coord, V2.coord);
Standard_Real D = coord.Modulus();
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.Divide(D);
}
inline gp_Dir gp_Dir::CrossCrossed (const gp_Dir& V1,
const gp_Dir& V2) const
{
gp_Dir V = *this;
(V.coord).CrossCross (V1.coord, V2.coord);
Standard_Real D = V.coord.Modulus();
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
V.coord.Divide(D);
return V;
}
inline Standard_Real gp_Dir::Dot (const gp_Dir& Other) const
{ return coord.Dot (Other.coord); }
inline Standard_Real gp_Dir::DotCross (const gp_Dir& V1,
const gp_Dir& V2) const
{ return coord.Dot (V1.coord.Crossed (V2.coord)); }
inline void gp_Dir::Reverse ()
{ coord.Reverse(); }
inline gp_Dir gp_Dir::Reversed () const {
gp_Dir V = *this;
V.coord.Reverse ();
return V;
}
inline void gp_Dir::Rotate (const gp_Ax1& A1, const Standard_Real Ang)
{
gp_Trsf T;
T.SetRotation (A1, Ang);
coord.Multiply (T.HVectorialPart ());
}
inline gp_Dir gp_Dir::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Dir V = *this;
V.Rotate (A1, Ang);
return V;
}
inline gp_Dir gp_Dir::Transformed (const gp_Trsf& T) const
{
gp_Dir V = *this;
V.Transform (T);
return V;
}

283
src/gp/gp_Dir2d.cdl Executable file
View File

@@ -0,0 +1,283 @@
---Copyright: Matra Datavision 1991
class Dir2d from gp inherits Storable
---Purpose: Describes a unit vector in the plane (2D space). This unit
-- vector is also called "Direction".
-- See Also
-- gce_MakeDir2d which provides functions for more
-- complex unit vector constructions
-- Geom2d_Direction which provides additional functions
-- for constructing unit vectors and works, in particular, with
-- the parametric equations of unit vectors
uses Ax2d from gp,
Trsf2d from gp,
Vec2d from gp,
XY from gp
raises ConstructionError from Standard,
DomainError from Standard,
OutOfRange from Standard
is
Create returns Dir2d;
--- Purpose : Creates a direction corresponding to X axis.
---C++:inline
Create (V : Vec2d) returns Dir2d
--- Purpose : Normalizes the vector V and creates a Direction. Raises ConstructionError if V.Magnitude() <= Resolution from gp.
---C++:inline
raises ConstructionError;
Create (Coord : XY) returns Dir2d
--- Purpose : Creates a Direction from a doublet of coordinates. Raises ConstructionError if Coord.Modulus() <= Resolution from gp.
---C++:inline
raises ConstructionError;
Create ( Xv, Yv : Real) returns Dir2d
--- Purpose : Creates a Direction with its 2 cartesian coordinates. Raises ConstructionError if Sqrt(Xv*Xv + Yv*Yv) <= Resolution from gp.
---C++:inline
raises ConstructionError;
SetCoord (me: in out; Index : Integer; Xi : Real)
---C++:inline
--- Purpose :
-- For this unit vector, assigns:
-- the value Xi to:
-- - the X coordinate if Index is 1, or
-- - the Y coordinate if Index is 2, and then normalizes it.
-- Warning
-- Remember that all the coordinates of a unit vector are
-- implicitly modified when any single one is changed directly.
-- Exceptions
-- Standard_OutOfRange if Index is not 1 or 2.
-- Standard_ConstructionError if either of the following
-- is less than or equal to gp::Resolution():
-- - Sqrt(Xv*Xv + Yv*Yv), or
-- - the modulus of the number pair formed by the new
-- value Xi and the other coordinate of this vector that
-- was not directly modified.
-- Raises OutOfRange if Index != {1, 2}.
raises OutOfRange,
ConstructionError
is static;
SetCoord (me : in out; Xv, Yv : Real) raises ConstructionError is static;
---C++:inline
--- Purpose :
-- For this unit vector, assigns:
-- - the values Xv and Yv to its two coordinates,
-- Warning
-- Remember that all the coordinates of a unit vector are
-- implicitly modified when any single one is changed directly.
-- Exceptions
-- Standard_OutOfRange if Index is not 1 or 2.
-- Standard_ConstructionError if either of the following
-- is less than or equal to gp::Resolution():
-- - Sqrt(Xv*Xv + Yv*Yv), or
-- - the modulus of the number pair formed by the new
-- value Xi and the other coordinate of this vector that
-- was not directly modified.
-- Raises OutOfRange if Index != {1, 2}.
SetX (me: in out; X : Real) raises ConstructionError is static;
---C++:inline
---Purpose:
-- Assigns the given value to the X coordinate of this unit vector,
-- and then normalizes it.
-- Warning
-- Remember that all the coordinates of a unit vector are
-- implicitly modified when any single one is changed directly.
-- Exceptions
-- Standard_ConstructionError if either of the following
-- is less than or equal to gp::Resolution():
-- - the modulus of Coord, or
-- - the modulus of the number pair formed from the new
-- X or Y coordinate and the other coordinate of this
-- vector that was not directly modified.
SetY (me: in out; Y : Real) raises ConstructionError is static;
---C++:inline
---Purpose:
-- Assigns the given value to the Y coordinate of this unit vector,
-- and then normalizes it.
-- Warning
-- Remember that all the coordinates of a unit vector are
-- implicitly modified when any single one is changed directly.
-- Exceptions
-- Standard_ConstructionError if either of the following
-- is less than or equal to gp::Resolution():
-- - the modulus of Coord, or
-- - the modulus of the number pair formed from the new
-- X or Y coordinate and the other coordinate of this
-- vector that was not directly modified.
SetXY (me: in out; Coord : XY) raises ConstructionError is static;
---C++:inline
---Purpose:
-- Assigns:
-- - the two coordinates of Coord to this unit vector,
-- and then normalizes it.
-- Warning
-- Remember that all the coordinates of a unit vector are
-- implicitly modified when any single one is changed directly.
-- Exceptions
-- Standard_ConstructionError if either of the following
-- is less than or equal to gp::Resolution():
-- - the modulus of Coord, or
-- - the modulus of the number pair formed from the new
-- X or Y coordinate and the other coordinate of this
-- vector that was not directly modified.
Coord (me; Index : Integer) returns Real
---C++:inline
--- Purpose :
-- For this unit vector returns the coordinate of range Index :
-- Index = 1 => X is returned
-- Index = 2 => Y is returned
-- Raises OutOfRange if Index != {1, 2}.
raises OutOfRange
is static;
Coord (me; Xv, Yv : out Real) is static;
---C++:inline
---Purpose: For this unit vector returns its two coordinates Xv and Yv.
-- Raises OutOfRange if Index != {1, 2}.
X (me) returns Real is static;
---C++:inline
--- Purpose: For this unit vector, returns its X coordinate.
Y (me) returns Real is static;
---C++:inline
--- Purpose: For this unit vector, returns its Y coordinate.
XY (me) returns XY is static;
---C++: inline
---C++: return const&
--- Purpose: For this unit vector, returns its two coordinates as a number pair.
--- Purpose : Comparison between Directions
-- The precision value is an input data.
IsEqual (me; Other : Dir2d; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- Returns True if the two vectors have the same direction
-- i.e. the angle between this unit vector and the
-- unit vector Other is less than or equal to AngularTolerance.
IsNormal (me; Other : Dir2d; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- Returns True if the angle between this unit vector and the
-- unit vector Other is equal to Pi/2 or -Pi/2 (normal)
-- i.e. Abs(Abs(<me>.Angle(Other)) - PI/2.) <= AngularTolerance
IsOpposite (me; Other : Dir2d; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- Returns True if the angle between this unit vector and the
-- unit vector Other is equal to Pi or -Pi (opposite).
-- i.e. PI - Abs(<me>.Angle(Other)) <= AngularTolerance
IsParallel (me; Other : Dir2d; AngularTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose :
-- returns true if if the angle between this unit vector and unit
-- vector Other is equal to 0, Pi or -Pi.
-- i.e. Abs(Angle(<me>, Other)) <= AngularTolerance or
-- PI - Abs(Angle(<me>, Other)) <= AngularTolerance
Angle (me; Other : Dir2d) returns Real is static;
--- Purpose :
-- Computes the angular value in radians between <me> and
-- <Other>. Returns the angle in the range [-PI, PI].
Crossed (me; Right : Dir2d) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the cross product between two directions.
---C++: alias operator ^
Dot (me; Other : Dir2d) returns Real is static;
---C++: inline
--- Purpose : Computes the scalar product
---C++: alias operator *
Reverse (me : in out) is static;
---C++: inline
Reversed (me) returns Dir2d is static;
---C++: inline
---C++: alias operator -
--- Purpose : Reverses the orientation of a direction
Mirror (me : in out; V : Dir2d) is static;
Mirrored (me; V : Dir2d) returns Dir2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a direction
-- with respect to the direction V which is the center of
-- the symmetry.
Mirror (me : in out; A : Ax2d) is static;
Mirrored (me; A : Ax2d) returns Dir2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a direction
-- with respect to an axis placement which is the axis
-- of the symmetry.
Rotate (me : in out; Ang : Real) is static;
---C++: inline
Rotated (me; Ang : Real) returns Dir2d is static;
--- Purpose :
-- Rotates a direction. Ang is the angular value of
-- the rotation in radians.
---C++: inline
Transform (me : in out; T : Trsf2d) is static;
Transformed (me; T : Trsf2d) returns Dir2d is static;
---C++: inline
--- Purpose :
-- Transforms a direction with the "Trsf" T.
--- Warnings :
-- If the scale factor of the "Trsf" T is negative then the
-- direction <me> is reversed.
fields
coord : XY;
end;

83
src/gp/gp_Dir2d.cxx Executable file
View File

@@ -0,0 +1,83 @@
// File gp_Dir2d.cxx , REG 27/10/90 nouvelle version
// JCV 08/01/90 Modifs suite a l'introduction des classes XY et Mat2d dans gp
#include <gp_Dir2d.ixx>
Standard_Real gp_Dir2d::Angle (const gp_Dir2d& Other) const
{
// Commentaires :
// Au dessus de 45 degres l'arccos donne la meilleur precision pour le
// calcul de l'angle. Sinon il vaut mieux utiliser l'arcsin.
// Les erreurs commises sont loin d'etre negligeables lorsque l'on est
// proche de zero ou de 90 degres.
// En 2D les valeurs angulaires sont comprises entre -PI et PI
Standard_Real Cosinus = coord.Dot (Other.coord);
Standard_Real Sinus = coord.Crossed (Other.coord);
if (Cosinus > -0.70710678118655 && Cosinus < 0.70710678118655) {
if (Sinus > 0.0) return acos (Cosinus);
else return - acos (Cosinus);
}
else {
if (Cosinus > 0.0) return asin (Sinus);
else {
if (Sinus > 0.0) return Standard_PI - asin (Sinus);
else return -Standard_PI - asin (Sinus);
}
}
}
void gp_Dir2d::Mirror (const gp_Ax2d& A2)
{
const gp_XY& XY = A2.Direction().XY();
Standard_Real A = XY.X();
Standard_Real B = XY.Y();
Standard_Real X = coord.X();
Standard_Real Y = coord.Y();
Standard_Real M1 = 2.0 * A * B;
Standard_Real XX = ((2.0 * A * A) - 1.0) * X + M1 * Y;
Standard_Real YY = M1 * X + ((2.0 * B * B) - 1.0) * Y;
coord.SetCoord(XX,YY);
}
void gp_Dir2d::Transform (const gp_Trsf2d& T)
{
if (T.Form() == gp_Identity || T.Form() == gp_Translation) { }
else if (T.Form() == gp_PntMirror) { coord.Reverse(); }
else if (T.Form() == gp_Scale) {
if (T.ScaleFactor() < 0.0) { coord.Reverse(); }
}
else {
coord.Multiply (T.HVectorialPart());
Standard_Real D = coord.Modulus();
coord.Divide(D);
if (T.ScaleFactor() < 0.0) { coord.Reverse(); }
}
}
void gp_Dir2d::Mirror (const gp_Dir2d& V)
{
const gp_XY& XY = V.coord;
Standard_Real A = XY.X();
Standard_Real B = XY.Y();
Standard_Real X = coord.X();
Standard_Real Y = coord.Y();
Standard_Real M1 = 2.0 * A * B;
Standard_Real XX = ((2.0 * A * A) - 1.0) * X + M1 * Y;
Standard_Real YY = M1 * X + ((2.0 * B * B) - 1.0) * Y;
coord.SetCoord(XX,YY);
}
gp_Dir2d gp_Dir2d::Mirrored (const gp_Dir2d& V) const
{
gp_Dir2d Vres = *this;
Vres.Mirror (V);
return Vres;
}
gp_Dir2d gp_Dir2d::Mirrored (const gp_Ax2d& A) const
{
gp_Dir2d V = *this;
V.Mirror (A);
return V;
}

184
src/gp/gp_Dir2d.lxx Executable file
View File

@@ -0,0 +1,184 @@
// File gp_Dir2d.lxx , REG 27/10/90
// Modif JCV 08/01/91 introduction classe XY dans le package gp
#include <Standard_ConstructionError.hxx>
#include <Standard_OutOfRange.hxx>
#include <gp_XY.hxx>
#include <gp_Ax2d.hxx>
#include <gp_Trsf2d.hxx>
inline gp_Dir2d::gp_Dir2d() : coord (1.,0.)
{
}
inline gp_Dir2d::gp_Dir2d (const gp_Vec2d& V)
{
const gp_XY& XY = V.XY();
Standard_Real X = XY.X();
Standard_Real Y = XY.Y();
Standard_Real D = sqrt(X * X + Y * Y);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
}
inline gp_Dir2d::gp_Dir2d (const gp_XY& XY)
{
Standard_Real X = XY.X();
Standard_Real Y = XY.Y();
Standard_Real D = sqrt(X * X + Y * Y);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
}
inline gp_Dir2d::gp_Dir2d (const Standard_Real Xv,
const Standard_Real Yv)
{
Standard_Real D = sqrt (Xv * Xv + Yv * Yv);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(Xv / D);
coord.SetY(Yv / D);
}
inline void gp_Dir2d::SetCoord (const Standard_Integer Index,
const Standard_Real Xi)
{
Standard_Real X = coord.X();
Standard_Real Y = coord.Y();
Standard_OutOfRange_Raise_if (Index < 1 || Index > 2, " ");
if (Index == 1) X = Xi;
else Y = Xi;
Standard_Real D = sqrt (X * X + Y * Y);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
}
inline void gp_Dir2d::SetCoord (const Standard_Real Xv,
const Standard_Real Yv)
{
Standard_Real D = sqrt (Xv * Xv + Yv * Yv);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(Xv / D);
coord.SetY(Yv / D);
}
inline void gp_Dir2d::SetX (const Standard_Real X)
{
Standard_Real Y = coord.Y();
Standard_Real D = sqrt (X * X + Y * Y);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
}
inline void gp_Dir2d::SetY (const Standard_Real Y)
{
Standard_Real X = coord.X();
Standard_Real D = sqrt (X * X + Y * Y);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
}
inline void gp_Dir2d::SetXY (const gp_XY& XY)
{
Standard_Real X = XY.X();
Standard_Real Y = XY.Y();
Standard_Real D = sqrt(X * X + Y * Y);
Standard_ConstructionError_Raise_if (D <= gp::Resolution(), "");
coord.SetX(X / D);
coord.SetY(Y / D);
}
inline Standard_Real gp_Dir2d::Coord (const Standard_Integer Index) const
{ return coord.Coord(Index); }
inline void gp_Dir2d::Coord(Standard_Real& Xv, Standard_Real& Yv) const
{ coord.Coord (Xv, Yv); }
inline Standard_Real gp_Dir2d::X() const
{ return coord.X() ; }
inline Standard_Real gp_Dir2d::Y() const
{ return coord.Y() ; }
inline const gp_XY& gp_Dir2d::XY () const
{ return coord; }
inline Standard_Boolean gp_Dir2d::IsEqual
(const gp_Dir2d& Other,
const Standard_Real AngularTolerance) const
{
Standard_Real Ang = Angle(Other);
if (Ang < 0) Ang = - Ang;
return Ang <= AngularTolerance;
}
inline Standard_Boolean gp_Dir2d::IsNormal
(const gp_Dir2d& Other,
const Standard_Real AngularTolerance) const
{
Standard_Real Ang = Angle(Other);
if (Ang < 0) Ang = - Ang;
Ang = Standard_PI / 2.0 - Ang;
if (Ang < 0) Ang = - Ang;
return Ang <= AngularTolerance;
}
inline Standard_Boolean gp_Dir2d::IsOpposite
(const gp_Dir2d& Other,
const Standard_Real AngularTolerance) const
{
Standard_Real Ang = Angle(Other);
if (Ang < 0) Ang = - Ang;
return Standard_PI - Ang <= AngularTolerance;
}
inline Standard_Boolean gp_Dir2d::IsParallel
(const gp_Dir2d& Other,
const Standard_Real AngularTolerance) const
{
Standard_Real Ang = Angle(Other);
if (Ang < 0) Ang = - Ang;
return Ang <= AngularTolerance || Standard_PI - Ang <= AngularTolerance;
}
inline Standard_Real gp_Dir2d::Crossed (const gp_Dir2d& Right) const
{ return coord.Crossed (Right.coord); }
inline Standard_Real gp_Dir2d::Dot (const gp_Dir2d& Other) const
{ return coord.Dot (Other.coord); }
inline void gp_Dir2d::Reverse()
{ coord.Reverse(); }
inline gp_Dir2d gp_Dir2d::Reversed() const
{
gp_Dir2d V = *this;
V.coord.Reverse ();
return V;
}
inline void gp_Dir2d::Rotate (const Standard_Real Ang)
{
gp_Trsf2d T;
T.SetRotation (gp_Pnt2d (0.0, 0.0), Ang);
coord.Multiply (T.HVectorialPart());
}
inline gp_Dir2d gp_Dir2d::Rotated (const Standard_Real Ang) const
{
gp_Dir2d V = *this;
V.Rotate (Ang);
return V;
}
inline gp_Dir2d gp_Dir2d::Transformed (const gp_Trsf2d& T) const
{
gp_Dir2d V = *this;
V.Transform (T);
return V;
}

331
src/gp/gp_Elips.cdl Executable file
View File

@@ -0,0 +1,331 @@
---Copyright: Matra Datavision 1991, 1992
class Elips from gp inherits Storable
--- Purpose :
-- Describes an ellipse in 3D space.
-- An ellipse is defined by its major and minor radii and
-- positioned in space with a coordinate system (a gp_Ax2 object) as follows:
-- - the origin of the coordinate system is the center of the ellipse,
-- - its "X Direction" defines the major axis of the ellipse, and
-- - its "Y Direction" defines the minor axis of the ellipse.
-- Together, the origin, "X Direction" and "Y Direction" of
-- this coordinate system define the plane of the ellipse.
-- This coordinate system is the "local coordinate system"
-- of the ellipse. In this coordinate system, the equation of
-- the ellipse is:
-- X*X / (MajorRadius**2) + Y*Y / (MinorRadius**2) = 1.0
-- The "main Direction" of the local coordinate system gives
-- the normal vector to the plane of the ellipse. This vector
-- gives an implicit orientation to the ellipse (definition of the
-- trigonometric sense). We refer to the "main Axis" of the
-- local coordinate system as the "Axis" of the ellipse.
-- See Also
-- gce_MakeElips which provides functions for more
-- complex ellipse constructions
-- Geom_Ellipse which provides additional functions for
-- constructing ellipses and works, in particular, with the
-- parametric equations of ellipses
uses Ax1 from gp,
Ax2 from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard
is
Create returns Elips;
---C++:inline
--- Purpose : Creates an indefinite ellipse.
Create (A2 : Ax2; MajorRadius, MinorRadius : Real) returns Elips
---C++: inline
--- Purpose :
-- The major radius of the ellipse is on the "XAxis" and the
-- minor radius is on the "YAxis" of the ellipse. The "XAxis"
-- is defined with the "XDirection" of A2 and the "YAxis" is
-- defined with the "YDirection" of A2.
-- Warnings :
-- It is not forbidden to create an ellipse with MajorRadius =
-- MinorRadius.
-- Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.
raises ConstructionError;
SetAxis (me : in out; A1 : Ax1)
---C++:inline
--- Purpose :
-- Changes the axis normal to the plane of the ellipse.
-- It modifies the definition of this plane.
-- The "XAxis" and the "YAxis" are recomputed.
-- The local coordinate system is redefined so that:
-- - its origin and "main Direction" become those of the
-- axis A1 (the "X Direction" and "Y Direction" are then
-- recomputed in the same way as for any gp_Ax2), or
-- Raises ConstructionError if the direction of A1
-- is parallel to the direction of the "XAxis" of the ellipse.
raises ConstructionError
is static;
SetLocation (me : in out; P : Pnt) is static;
---C++: inline
--- Purpose :Modifies this ellipse, by redefining its local coordinate
-- so that its origin becomes P.
SetMajorRadius (me : in out; MajorRadius : Real)
---C++: inline
--- Purpose :
-- The major radius of the ellipse is on the "XAxis" (major axis)
-- of the ellipse.
-- Raises ConstructionError if MajorRadius < MinorRadius.
raises ConstructionError
is static;
SetMinorRadius (me : in out; MinorRadius : Real)
---C++: inline
--- Purpose :
-- The minor radius of the ellipse is on the "YAxis" (minor axis)
-- of the ellipse.
-- Raises ConstructionError if MinorRadius > MajorRadius or MinorRadius < 0.
raises ConstructionError
is static;
SetPosition (me : in out; A2 : Ax2) is static;
---C++: inline
--- Purpose : Modifies this ellipse, by redefining its local coordinate
-- so that it becomes A2e.
Area (me) returns Real is static;
--- Purpose : Computes the area of the Ellipse.
---C++: inline
Axis (me) returns Ax1 is static;
---C++: inline
--- Purpose:
-- Computes the axis normal to the plane of the ellipse.
---C++: return const&
Directrix1 (me) returns Ax1
---C++:inline
--- Purpose : Computes the first or second directrix of this ellipse.
-- These are the lines, in the plane of the ellipse, normal to
-- the major axis, at a distance equal to
-- MajorRadius/e from the center of the ellipse, where
-- e is the eccentricity of the ellipse.
-- The first directrix (Directrix1) is on the positive side of
-- the major axis. The second directrix (Directrix2) is on
-- the negative side.
-- The directrix is returned as an axis (gp_Ax1 object), the
-- origin of which is situated on the "X Axis" of the local
-- coordinate system of this ellipse.
-- Exceptions
-- Standard_ConstructionError if the eccentricity is null
-- (the ellipse has degenerated into a circle).
raises ConstructionError
is static;
Directrix2 (me) returns Ax1
---C++:inline
--- Purpose :
-- This line is obtained by the symmetrical transformation
-- of "Directrix1" with respect to the "YAxis" of the ellipse.
-- Exceptions
-- Standard_ConstructionError if the eccentricity is null
-- (the ellipse has degenerated into a circle).
raises ConstructionError
is static;
Eccentricity (me) returns Real
---C++:inline
--- Purpose :
-- Returns the eccentricity of the ellipse between 0.0 and 1.0
-- If f is the distance between the center of the ellipse and
-- the Focus1 then the eccentricity e = f / MajorRadius.
-- Raises ConstructionError if MajorRadius = 0.0
raises ConstructionError
is static;
Focal (me) returns Real is static;
---C++:inline
--- Purpose :
-- Computes the focal distance. It is the distance between the
-- two focus focus1 and focus2 of the ellipse.
Focus1( me) returns Pnt is static;
---C++:inline
--- Purpose :
-- Returns the first focus of the ellipse. This focus is on the
-- positive side of the "XAxis" of the ellipse.
Focus2 (me) returns Pnt is static;
---C++:inline
--- Purpose :
-- Returns the second focus of the ellipse. This focus is on the
-- negative side of the "XAxis" of the ellipse.
Location (me) returns Pnt is static;
---C++:inline
--- Purpose :
-- Returns the center of the ellipse. It is the "Location"
-- point of the coordinate system of the ellipse.
---C++: return const&
MajorRadius (me) returns Real is static;
--- Purpose : Returns the major radius of the ellipse.
---C++: inline
MinorRadius (me) returns Real is static;
--- Purpose : Returns the minor radius of the ellipse.
---C++: inline
Parameter (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns p = (1 - e * e) * MajorRadius where e is the eccentricity
-- of the ellipse.
-- Returns 0 if MajorRadius = 0
Position (me) returns Ax2 is static;
--- Purpose : Returns the coordinate system of the ellipse.
---C++: inline
---C++: return const&
XAxis (me) returns Ax1 is static;
---C++:inline
--- Purpose :
-- Returns the "XAxis" of the ellipse whose origin
-- is the center of this ellipse. It is the major axis of the
-- ellipse.
YAxis (me) returns Ax1 is static;
---C++:inline
--- Purpose :
-- Returns the "YAxis" of the ellipse whose unit vector is the "X Direction" or the "Y Direction"
-- of the local coordinate system of this ellipse.
-- This is the minor axis of the ellipse.
Mirror (me : in out; P : Pnt)
is static;
Mirrored (me; P : Pnt) returns Elips is static;
--- Purpose :
-- Performs the symmetrical transformation of an ellipse with
-- respect to the point P which is the center of the symmetry.
Mirror (me : in out; A1 : Ax1)
is static;
Mirrored (me; A1 : Ax1) returns Elips is static;
--- Purpose :
-- Performs the symmetrical transformation of an ellipse with
-- respect to an axis placement which is the axis of the symmetry.
Mirror (me : in out; A2 : Ax2)
is static;
Mirrored (me; A2 : Ax2) returns Elips is static;
--- Purpose :
-- Performs the symmetrical transformation of an ellipse with
-- respect to a plane. The axis placement A2 locates the plane
-- of the symmetry (Location, XDirection, YDirection).
Rotate (me : in out; A1 : Ax1; Ang : Real)
---C++: inline
is static;
Rotated (me; A1 : Ax1; Ang : Real) returns Elips is static;
---C++: inline
--- Purpose :
-- Rotates an ellipse. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt; S : Real) returns Elips is static;
---C++: inline
--- Purpose :
-- Scales an ellipse. S is the scaling value.
Transform (me : in out; T : Trsf) is static;
---C++: inline
Transformed (me; T : Trsf) returns Elips is static;
---C++: inline
--- Purpose :
-- Transforms an ellipse with the transformation T from class Trsf.
Translate (me : in out; V : Vec)
---C++: inline
is static;
Translated (me; V : Vec) returns Elips is static;
---C++: inline
--- Purpose :
-- Translates an ellipse in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt)
---C++: inline
is static;
Translated (me; P1, P2 : Pnt) returns Elips is static;
---C++: inline
--- Purpose :
-- Translates an ellipse from the point P1 to the point P2.
fields
pos : Ax2;
majorRadius : Real;
minorRadius : Real;
end;

35
src/gp/gp_Elips.cxx Executable file
View File

@@ -0,0 +1,35 @@
//File gp_Elips.cxx JCV 06/10/90
//Modif JCV 12/12/90
#include <gp_Elips.ixx>
void gp_Elips::Mirror (const gp_Pnt& P)
{ pos.Mirror(P); }
gp_Elips gp_Elips::Mirrored (const gp_Pnt& P) const
{
gp_Elips E = *this;
E.pos.Mirror (P);
return E;
}
void gp_Elips::Mirror (const gp_Ax1& A1)
{ pos.Mirror(A1); }
gp_Elips gp_Elips::Mirrored (const gp_Ax1& A1) const
{
gp_Elips E = *this;
E.pos.Mirror (A1);
return E;
}
void gp_Elips::Mirror (const gp_Ax2& A2)
{ pos.Mirror(A2); }
gp_Elips gp_Elips::Mirrored (const gp_Ax2& A2) const
{
gp_Elips E = *this;
E.pos.Mirror (A2);
return E;
}

210
src/gp/gp_Elips.lxx Executable file
View File

@@ -0,0 +1,210 @@
// File gp_Elips.lxx JCV 06/10/90
// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559
#include <gp.hxx>
#include <Standard_ConstructionError.hxx>
inline gp_Elips::gp_Elips () :
majorRadius (RealLast()),
minorRadius (RealSmall())
{ }
inline gp_Elips::gp_Elips (const gp_Ax2& A2,
const Standard_Real MajorRadius,
const Standard_Real MinorRadius) :
pos(A2),
majorRadius (MajorRadius),
minorRadius (MinorRadius)
{
Standard_ConstructionError_Raise_if
(MinorRadius < 0.0 || MajorRadius < MinorRadius,"");
}
inline Standard_Real gp_Elips::Area() const
{ return Standard_PI * majorRadius * minorRadius; }
inline Standard_Real gp_Elips::MajorRadius() const
{ return majorRadius; }
inline Standard_Real gp_Elips::MinorRadius() const
{ return minorRadius; }
inline Standard_Real gp_Elips::Parameter() const
{
if (majorRadius == 0.0) return 0.0;
else return (minorRadius * minorRadius) / majorRadius;
}
inline const gp_Ax2& gp_Elips::Position() const
{ return pos; }
inline const gp_Ax1& gp_Elips::Axis () const
{ return pos.Axis(); }
inline gp_Ax1 gp_Elips::Directrix1() const
{
Standard_Real E = Eccentricity();
Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "");
gp_XYZ Orig = pos.XDirection().XYZ();
Orig.Multiply (majorRadius/E);
Orig.Add (pos.Location().XYZ());
return gp_Ax1 (gp_Pnt(Orig), pos.YDirection());
}
inline gp_Ax1 gp_Elips::Directrix2() const
{
Standard_Real E = Eccentricity();
Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "");
gp_XYZ Orig = pos.XDirection().XYZ();
Orig.Multiply (-majorRadius/E);
Orig.Add (pos.Location().XYZ());
return gp_Ax1 (gp_Pnt(Orig), pos.YDirection());
}
inline Standard_Real gp_Elips::Eccentricity() const
{
if (majorRadius == 0.0) { return 0.0; }
else {
return sqrt(majorRadius * majorRadius -
minorRadius * minorRadius) / majorRadius;
}
}
inline Standard_Real gp_Elips::Focal() const
{
return 2.0 * sqrt(majorRadius * majorRadius -
minorRadius * minorRadius);
}
inline gp_Pnt gp_Elips::Focus1() const
{
Standard_Real C = sqrt(majorRadius * majorRadius -
minorRadius * minorRadius);
const gp_Pnt& PP = pos.Location ();
const gp_Dir& DD = pos.XDirection();
return gp_Pnt (PP.X() + C * DD.X(),
PP.Y() + C * DD.Y(),
PP.Z() + C * DD.Z());
}
inline gp_Pnt gp_Elips::Focus2() const
{
Standard_Real C = sqrt(majorRadius * majorRadius -
minorRadius * minorRadius);
const gp_Pnt& PP = pos.Location ();
const gp_Dir& DD = pos.XDirection();
return gp_Pnt (PP.X() - C * DD.X(),
PP.Y() - C * DD.Y(),
PP.Z() - C * DD.Z());
}
inline const gp_Pnt& gp_Elips::Location () const
{ return pos.Location(); }
inline gp_Ax1 gp_Elips::XAxis () const
{ return gp_Ax1 (pos.Location(), pos.XDirection()); }
inline gp_Ax1 gp_Elips::YAxis () const
{ return gp_Ax1 (pos.Location(), pos.YDirection()); }
inline void gp_Elips::SetAxis (const gp_Ax1& A1)
{ pos.SetAxis(A1); }
inline void gp_Elips::SetPosition (const gp_Ax2& A2)
{ pos = A2; }
inline void gp_Elips::SetLocation (const gp_Pnt& P)
{ pos.SetLocation (P); }
inline void gp_Elips::SetMajorRadius (const Standard_Real R)
{
Standard_ConstructionError_Raise_if(R < minorRadius,"");
majorRadius = R;
}
inline void gp_Elips::SetMinorRadius (const Standard_Real R)
{
Standard_ConstructionError_Raise_if(R < 0.0 || majorRadius < R,"");
minorRadius = R;
}
inline void gp_Elips::Rotate (const gp_Ax1& A1,
const Standard_Real Ang) { pos.Rotate(A1, Ang); }
inline gp_Elips gp_Elips::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Elips E = *this;
E.pos.Rotate(A1, Ang);
return E;
}
inline void gp_Elips::Scale (const gp_Pnt& P,
const Standard_Real S)
// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 Begin
// { pos.Scale(P, S); }
{
majorRadius *= S;
if (majorRadius < 0) majorRadius = - majorRadius;
minorRadius *= S;
if (minorRadius < 0) minorRadius = - minorRadius;
pos.Scale(P, S);
}
// Modified by skv - Fri Apr 8 10:28:10 2005 OCC8559 End
inline gp_Elips gp_Elips::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Elips E = *this;
E.majorRadius *= S;
if (E.majorRadius < 0) E.majorRadius = - E.majorRadius;
E.minorRadius *= S;
if (E.minorRadius < 0) E.minorRadius = - E.minorRadius;
E.pos.Scale(P, S);
return E;
}
inline void gp_Elips::Transform (const gp_Trsf& T)
{
majorRadius *= T.ScaleFactor();
if (majorRadius < 0) majorRadius = - majorRadius;
minorRadius *= T.ScaleFactor();
if (minorRadius < 0) minorRadius = - minorRadius;
pos.Transform(T);
}
inline gp_Elips gp_Elips::Transformed (const gp_Trsf& T) const
{
gp_Elips E = *this;
E.majorRadius *= T.ScaleFactor();
if (E.majorRadius < 0) E.majorRadius = - E.majorRadius;
E.minorRadius *= T.ScaleFactor();
if (E.minorRadius < 0) E.minorRadius = - E.minorRadius;
E.pos.Transform(T);
return E;
}
inline void gp_Elips::Translate (const gp_Vec& V)
{ pos.Translate(V); }
inline gp_Elips gp_Elips::Translated (const gp_Vec& V) const
{
gp_Elips E = *this;
E.pos.Translate(V);
return E;
}
inline void gp_Elips::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{ pos.Translate(P1, P2); }
inline gp_Elips gp_Elips::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Elips E = *this;
E.pos.Translate(P1, P2);
return E;
}

313
src/gp/gp_Elips2d.cdl Executable file
View File

@@ -0,0 +1,313 @@
---Copyright: Matra Datavision 1991, 1992
class Elips2d from gp inherits Storable
--- Purpose :
-- Describes an ellipse in the plane (2D space).
-- An ellipse is defined by its major and minor radii and
-- positioned in the plane with a coordinate system (a
-- gp_Ax22d object) as follows:
-- - the origin of the coordinate system is the center of the ellipse,
-- - its "X Direction" defines the major axis of the ellipse, and
-- - its "Y Direction" defines the minor axis of the ellipse.
-- This coordinate system is the "local coordinate system"
-- of the ellipse. Its orientation (direct or indirect) gives an
-- implicit orientation to the ellipse. In this coordinate
-- system, the equation of the ellipse is:
-- X*X / (MajorRadius**2) + Y*Y / (MinorRadius**2) = 1.0
-- See Also
-- gce_MakeElips2d which provides functions for more
-- complex ellipse constructions
-- Geom2d_Ellipse which provides additional functions for
-- constructing ellipses and works, in particular, with the
-- parametric equations of ellipses
uses Ax2d from gp,
Ax22d from gp,
Pnt2d from gp,
Trsf2d from gp,
Vec2d from gp
raises ConstructionError from Standard
is
Create returns Elips2d;
---C++:inline
--- Purpose : Creates an indefinite ellipse.
Create (MajorAxis : Ax2d;
MajorRadius, MinorRadius : Real;
Sense : Boolean from Standard = Standard_True)
returns Elips2d
---C++:inline
--- Purpose :
-- Creates an ellipse with the major axis, the major and the
-- minor radius. The location of the MajorAxis is the center
-- of the ellipse.
-- The sense of parametrization is given by Sense.
-- Warnings :
-- It is possible to create an ellipse with
-- MajorRadius = MinorRadius.
-- Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0
raises ConstructionError;
Create (A : Ax22d; MajorRadius, MinorRadius : Real)
returns Elips2d
--- Purpose : Creates an ellipse with radii MajorRadius and
-- MinorRadius, positioned in the plane by coordinate system A where:
-- - the origin of A is the center of the ellipse,
-- - the "X Direction" of A defines the major axis of
-- the ellipse, that is, the major radius MajorRadius
-- is measured along this axis, and
-- - the "Y Direction" of A defines the minor axis of
-- the ellipse, that is, the minor radius MinorRadius
-- is measured along this axis, and
-- - the orientation (direct or indirect sense) of A
-- gives the orientation of the ellipse.
-- Warnings :
-- It is possible to create an ellipse with
-- MajorRadius = MinorRadius.
-- Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0
raises ConstructionError;
SetLocation (me : in out; P : Pnt2d) is static;
--- Purpose : Modifies this ellipse, by redefining its local coordinate system so that
-- - its origin becomes P.
SetMajorRadius (me : in out; MajorRadius : Real)
--- Purpose : Changes the value of the major radius.
-- Raises ConstructionError if MajorRadius < MinorRadius.
raises ConstructionError
is static;
SetMinorRadius (me : in out; MinorRadius : Real)
--- Purpose : Changes the value of the minor radius.
-- Raises ConstructionError if MajorRadius < MinorRadius or MinorRadius < 0.0
raises ConstructionError
is static;
SetAxis (me : in out; A : Ax22d) is static;
--- Purpose : Modifies this ellipse, by redefining its local coordinate system so that
-- it becomes A.
SetXAxis (me : in out; A : Ax2d) is static;
--- Purpose : Modifies this ellipse, by redefining its local coordinate system so that
-- its origin and its "X Direction" become those
-- of the axis A. The "Y Direction" is then
-- recomputed. The orientation of the local coordinate
-- system is not modified.
SetYAxis (me : in out; A : Ax2d) is static;
--- Purpose : Modifies this ellipse, by redefining its local coordinate system so that
-- its origin and its "Y Direction" become those
-- of the axis A. The "X Direction" is then
-- recomputed. The orientation of the local coordinate
-- system is not modified.
Area (me) returns Real is static;
--- Purpose : Computes the area of the ellipse.
---C++: inline
Coefficients (me; A, B, C, D, E, F : out Real) is static;
--- Purpose :
-- Returns the coefficients of the implicit equation of the ellipse.
-- A * (X**2) + B * (Y**2) + 2*C*(X*Y) + 2*D*X + 2*E*Y + F = 0.
Directrix1 (me) returns Ax2d
---C++: inline
--- Purpose :
-- This directrix is the line normal to the XAxis of the ellipse
-- in the local plane (Z = 0) at a distance d = MajorRadius / e
-- from the center of the ellipse, where e is the eccentricity of
-- the ellipse.
-- This line is parallel to the "YAxis". The intersection point
-- between directrix1 and the "XAxis" is the location point of the
-- directrix1. This point is on the positive side of the "XAxis".
raises ConstructionError
--- Purpose :
-- Raised if Eccentricity = 0.0. (The ellipse degenerates into a
-- circle)
is static;
Directrix2 (me) returns Ax2d
---C++: inline
--- Purpose :
-- This line is obtained by the symmetrical transformation
-- of "Directrix1" with respect to the minor axis of the ellipse.
raises ConstructionError
--- Purpose :
-- Raised if Eccentricity = 0.0. (The ellipse degenerates into a
-- circle).
is static;
Eccentricity (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the eccentricity of the ellipse between 0.0 and 1.0
-- If f is the distance between the center of the ellipse and
-- the Focus1 then the eccentricity e = f / MajorRadius.
-- Returns 0 if MajorRadius = 0.
Focal (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the distance between the center of the ellipse
-- and focus1 or focus2.
Focus1 (me) returns Pnt2d is static;
---C++: inline
--- Purpose :
-- Returns the first focus of the ellipse. This focus is on the
-- positive side of the major axis of the ellipse.
Focus2 (me) returns Pnt2d is static;
---C++: inline
--- Purpose :
-- Returns the second focus of the ellipse. This focus is on the
-- negative side of the major axis of the ellipse.
Location (me) returns Pnt2d is static;
---C++:inline
--- Purpose : Returns the center of the ellipse.
---C++: return const&
MajorRadius (me) returns Real is static;
--- Purpose : Returns the major radius of the Ellipse.
---C++: inline
MinorRadius (me) returns Real is static;
--- Purpose : Returns the minor radius of the Ellipse.
---C++: inline
Parameter (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns p = (1 - e * e) * MajorRadius where e is the eccentricity
-- of the ellipse.
-- Returns 0 if MajorRadius = 0
Axis (me) returns Ax22d is static;
--- Purpose : Returns the major axis of the ellipse.
---C++: inline
---C++: return const&
XAxis (me) returns Ax2d is static;
---C++:inline
--- Purpose : Returns the major axis of the ellipse.
YAxis (me) returns Ax2d is static;
---C++:inline
--- Purpose : Returns the minor axis of the ellipse.
--- Purpose : Reverses the direction of the circle.
Reverse (me : in out) is static;
---C++:inline
Reversed (me) returns Elips2d is static;
---C++:inline
IsDirect (me) returns Boolean is static;
---C++:inline
--- Purpose : Returns true if the local coordinate system is direct
-- and false in the other case.
Mirror (me : in out; P : Pnt2d)
is static;
Mirrored (me; P : Pnt2d) returns Elips2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a ellipse with respect
-- to the point P which is the center of the symmetry
Mirror (me : in out; A : Ax2d)
is static;
Mirrored (me; A : Ax2d) returns Elips2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a ellipse with respect
-- to an axis placement which is the axis of the symmetry.
Rotate (me : in out; P : Pnt2d; Ang : Real)
is static;
Rotated (me; P : Pnt2d; Ang : Real) returns Elips2d is static;
Scale (me : in out; P : Pnt2d; S : Real) is static;
Scaled (me; P : Pnt2d; S : Real) returns Elips2d is static;
--- Purpose :
-- Scales a ellipse. S is the scaling value.
Transform (me : in out; T : Trsf2d)
is static;
Transformed (me; T : Trsf2d) returns Elips2d is static;
--- Purpose :
-- Transforms an ellipse with the transformation T from class Trsf2d.
Translate (me : in out; V : Vec2d) is static;
Translated (me; V : Vec2d) returns Elips2d is static;
--- Purpose :
-- Translates a ellipse in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt2d ) is static;
Translated (me; P1, P2 : Pnt2d) returns Elips2d is static;
--- Purpose :
-- Translates a ellipse from the point P1 to the point P2.
fields
pos : Ax22d;
majorRadius : Real;
minorRadius : Real;
end;

61
src/gp/gp_Elips2d.cxx Executable file
View File

@@ -0,0 +1,61 @@
//File gp_Elips2d.cxx FID 30/10/90
//Modif JCV 10/01/91
#include <gp_Elips2d.ixx>
void gp_Elips2d::Coefficients (Standard_Real& A,
Standard_Real& B,
Standard_Real& C,
Standard_Real& D,
Standard_Real& E,
Standard_Real& F) const
{
Standard_Real DMin = minorRadius * minorRadius;
Standard_Real DMaj = majorRadius * majorRadius;
if (DMin <= gp::Resolution() && DMaj <= gp::Resolution()) {
A = B = C = D = E = F = 0.0;
}
else {
gp_Trsf2d T;
T.SetTransformation (pos.XAxis());
Standard_Real T11 = T.Value (1, 1);
Standard_Real T12 = T.Value (1, 2);
Standard_Real T13 = T.Value (1, 3);
if (DMin <= gp::Resolution()) {
A = T11 * T11; B = T12 * T12; C = T11 * T12;
D = T11 * T13; E = T12 * T13; F = T13 * T13 - DMaj;
}
else {
Standard_Real T21 = T.Value (2, 1);
Standard_Real T22 = T.Value (2, 2);
Standard_Real T23 = T.Value (2, 3);
A = (T11 * T11 / DMaj) + (T21 * T21 / DMin);
B = (T12 * T12 / DMaj) + (T22 * T22 / DMin);
C = (T11 * T12 / DMaj) + (T21 * T22 / DMin);
D = (T11 * T13 / DMaj) + (T21 * T23 / DMin);
E = (T12 * T13 / DMaj) + (T22 * T23 / DMin);
F = (T13 * T13 / DMaj) + (T23 * T23 / DMin) - 1.0;
}
}
}
void gp_Elips2d::Mirror (const gp_Pnt2d& P)
{ pos.Mirror(P); }
gp_Elips2d gp_Elips2d::Mirrored (const gp_Pnt2d& P) const
{
gp_Elips2d E = *this;
E.pos.Mirror (P);
return E;
}
void gp_Elips2d::Mirror (const gp_Ax2d& A)
{ pos.Mirror(A); }
gp_Elips2d gp_Elips2d::Mirrored (const gp_Ax2d& A) const
{
gp_Elips2d E = *this;
E.pos.Mirror (A);
return E;
}

236
src/gp/gp_Elips2d.lxx Executable file
View File

@@ -0,0 +1,236 @@
//File gp_Elips2d.lxx
#include <gp_Trsf2d.hxx>
#include <gp.hxx>
#include <Standard_ConstructionError.hxx>
inline gp_Elips2d::gp_Elips2d() :
majorRadius(RealLast()),
minorRadius(RealSmall())
{ }
inline gp_Elips2d::gp_Elips2d (const gp_Ax2d& MajorAxis,
const Standard_Real MajorRadius,
const Standard_Real MinorRadius,
const Standard_Boolean Sense) :
majorRadius(MajorRadius),
minorRadius(MinorRadius)
{
pos = gp_Ax22d(MajorAxis,Sense);
Standard_ConstructionError_Raise_if
(MinorRadius < 0.0 || MajorRadius < MinorRadius,"");
}
inline gp_Elips2d::gp_Elips2d (const gp_Ax22d& A,
const Standard_Real MajorRadius,
const Standard_Real MinorRadius) :
pos(A),
majorRadius(MajorRadius),
minorRadius(MinorRadius)
{
Standard_ConstructionError_Raise_if
(MinorRadius < 0.0 || MajorRadius < MinorRadius,"");
}
inline void gp_Elips2d::SetLocation (const gp_Pnt2d& P)
{ pos.SetLocation(P);}
inline void gp_Elips2d::SetMajorRadius (const Standard_Real MajorRadius)
{
Standard_ConstructionError_Raise_if(MajorRadius < minorRadius,"");
majorRadius = MajorRadius;
}
inline void gp_Elips2d::SetMinorRadius (const Standard_Real MinorRadius)
{
Standard_ConstructionError_Raise_if
(MinorRadius < 0.0 || majorRadius < MinorRadius,"");
minorRadius = MinorRadius;
}
inline void gp_Elips2d::SetXAxis (const gp_Ax2d& A)
{ pos.SetXAxis(A); }
inline void gp_Elips2d::SetAxis (const gp_Ax22d& A)
{ pos.SetAxis(A); }
inline void gp_Elips2d::SetYAxis (const gp_Ax2d& A)
{ pos.SetYAxis(A); }
inline Standard_Real gp_Elips2d::Area() const
{ return Standard_PI * majorRadius * minorRadius; }
inline gp_Ax2d gp_Elips2d::Directrix1() const
{
Standard_Real E = Eccentricity();
Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "");
gp_XY Orig = pos.XDirection().XY();
Orig.Multiply (majorRadius/E);
Orig.Add (pos.Location().XY());
return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection()));
}
inline gp_Ax2d gp_Elips2d::Directrix2() const
{
Standard_Real E = Eccentricity();
Standard_ConstructionError_Raise_if (E <= gp::Resolution(), "");
gp_XY Orig = pos.XDirection().XY();
Orig.Multiply (-majorRadius/E);
Orig.Add (pos.Location().XY());
return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection()));
}
inline Standard_Real gp_Elips2d::Eccentricity() const
{
if (majorRadius == 0.0) { return 0.0; }
else {
return sqrt(majorRadius * majorRadius -
minorRadius * minorRadius) / majorRadius;
}
}
inline Standard_Real gp_Elips2d::Focal() const
{
return 2.0 * sqrt(majorRadius * majorRadius -
minorRadius * minorRadius);
}
inline gp_Pnt2d gp_Elips2d::Focus1() const
{
Standard_Real C = sqrt(majorRadius * majorRadius -
minorRadius * minorRadius);
const gp_Pnt2d& PP = pos.Location ();
const gp_Dir2d& DD = pos.XDirection();
return gp_Pnt2d (PP.X() + C * DD.X(),
PP.Y() + C * DD.Y());
}
inline gp_Pnt2d gp_Elips2d::Focus2() const
{
Standard_Real C = sqrt (majorRadius * majorRadius -
minorRadius * minorRadius);
const gp_Pnt2d& PP = pos.Location ();
const gp_Dir2d& DD = pos.XDirection();
return gp_Pnt2d (PP.X() - C * DD.X(),
PP.Y() - C * DD.Y());
}
inline const gp_Pnt2d& gp_Elips2d::Location () const
{ return pos.Location(); }
inline Standard_Real gp_Elips2d::MajorRadius() const
{ return majorRadius; }
inline Standard_Real gp_Elips2d::MinorRadius() const
{ return minorRadius; }
inline Standard_Real gp_Elips2d::Parameter () const
{
if (majorRadius == 0.0) return 0.0;
else return (minorRadius * minorRadius) / majorRadius;
}
inline const gp_Ax22d& gp_Elips2d::Axis () const
{ return pos; }
inline gp_Ax2d gp_Elips2d::YAxis () const
{ return pos.YAxis(); }
inline gp_Ax2d gp_Elips2d::XAxis () const
{ return pos.XAxis(); }
inline void gp_Elips2d::Reverse()
{
gp_Dir2d Temp = pos.YDirection ();
Temp.Reverse ();
pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp));
}
inline gp_Elips2d gp_Elips2d::Reversed() const
{
gp_Elips2d E = *this;
gp_Dir2d Temp = pos.YDirection ();
Temp.Reverse ();
E.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp));
return E;
}
inline Standard_Boolean gp_Elips2d::IsDirect() const
{ return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; }
inline void gp_Elips2d::Rotate (const gp_Pnt2d& P,
const Standard_Real Ang)
{ pos.Rotate (P, Ang); }
inline gp_Elips2d gp_Elips2d::Rotated (const gp_Pnt2d& P,
const Standard_Real Ang) const
{
gp_Elips2d E = *this;
E.pos.Rotate (P, Ang);
return E;
}
inline void gp_Elips2d::Scale (const gp_Pnt2d& P,
const Standard_Real S)
{
majorRadius *= S;
if (majorRadius < 0) majorRadius = - majorRadius;
minorRadius *= S;
if (minorRadius < 0) minorRadius = - minorRadius;
pos.Scale(P, S);
}
inline gp_Elips2d gp_Elips2d::Scaled (const gp_Pnt2d& P,
const Standard_Real S) const
{
gp_Elips2d E = *this;
E.majorRadius *= S;
if (E.majorRadius < 0) E.majorRadius = - E.majorRadius;
E.minorRadius *= S;
if (E.minorRadius < 0) E.minorRadius = - E.minorRadius;
E.pos.Scale(P, S);
return E;
}
inline void gp_Elips2d::Transform(const gp_Trsf2d& T)
{
Standard_Real TSca = T.ScaleFactor();
if(TSca<0.0) TSca=-TSca;
majorRadius *= TSca;
minorRadius *= TSca;
pos.Transform(T);
}
inline gp_Elips2d gp_Elips2d::Transformed (const gp_Trsf2d& T) const
{
gp_Elips2d E = *this;
E.majorRadius *= T.ScaleFactor();
if (E.majorRadius < 0) E.majorRadius = - E.majorRadius;
E.minorRadius *= T.ScaleFactor();
if (E.minorRadius < 0) E.minorRadius = - E.minorRadius;
E.pos.Transform(T);
return E;
}
inline void gp_Elips2d::Translate (const gp_Vec2d& V)
{ pos.Translate(V); }
inline gp_Elips2d gp_Elips2d::Translated (const gp_Vec2d& V) const
{
gp_Elips2d E = *this;
E.pos.Translate(V);
return E;
}
inline void gp_Elips2d::Translate (const gp_Pnt2d& P1,
const gp_Pnt2d& P2)
{ pos.Translate(P1, P2); }
inline gp_Elips2d gp_Elips2d::Translated (const gp_Pnt2d& P1,
const gp_Pnt2d& P2) const
{
gp_Elips2d E = *this;
E.pos.Translate(P1, P2);
return E;
}

282
src/gp/gp_GTrsf.cdl Executable file
View File

@@ -0,0 +1,282 @@
---Copyright: Matra Datavision 1991, 1992
class GTrsf from gp inherits Storable
--- Purpose :
-- Defines a non-persistent transformation in 3D space.
-- This transformation is a general transformation.
-- It can be a Trsf from gp, an affinity, or you can define
-- your own transformation giving the matrix of transformation.
--
-- With a Gtrsf you can transform only a triplet of coordinates
-- XYZ. It is not possible to transform other geometric objects
-- because these transformations can change the nature of non-
-- elementary geometric objects.
-- The transformation GTrsf can be represented as follow :
--
-- V1 V2 V3 T XYZ XYZ
-- | a11 a12 a13 a14 | | x | | x'|
-- | a21 a22 a23 a24 | | y | | y'|
-- | a31 a32 a33 a34 | | z | = | z'|
-- | 0 0 0 1 | | 1 | | 1 |
--
-- where {V1, V2, V3} define the vectorial part of the
-- transformation and T defines the translation part of the
-- transformation.
-- Warning
-- A GTrsf transformation is only applicable to
-- coordinates. Be careful if you apply such a
-- transformation to all points of a geometric object, as
-- this can change the nature of the object and thus
-- render it incoherent!
-- Typically, a circle is transformed into an ellipse by an
-- affinity transformation. To avoid modifying the nature of
-- an object, use a gp_Trsf transformation instead, as
-- objects of this class respect the nature of geometric objects.
uses Ax1 from gp,
Ax2 from gp,
Mat from gp,
Trsf from gp,
Vec from gp,
XYZ from gp,
TrsfForm from gp
raises ConstructionError from Standard,
OutOfRange from Standard
is
Create returns GTrsf;
---C++: inline
--- Purpose : Returns the Identity transformation.
Create (T : Trsf) returns GTrsf;
---C++: inline
--- Purpose :
-- Converts the gp_Trsf transformation T into a
-- general transformation, i.e. Returns a GTrsf with
-- the same matrix of coefficients as the Trsf T.
Create (M : Mat; V : XYZ) returns GTrsf;
---C++: inline
--- Purpose :
-- Creates a transformation based on the matrix M and the
-- vector V where M defines the vectorial part of
-- the transformation, and V the translation part, or
SetAffinity (me : in out; A1 : Ax1; Ratio : Real) is static;
---C++: inline
--- Purpose : Changes this transformation into an affinity of ratio Ratio
-- with respect to the axis A1.
-- Note: an affinity is a point-by-point transformation that
-- transforms any point P into a point P' such that if H is
-- the orthogonal projection of P on the axis A1 or the
-- plane A2, the vectors HP and HP' satisfy:
-- HP' = Ratio * HP.
SetAffinity (me : in out; A2 : Ax2; Ratio : Real) is static;
---C++: inline
--- Purpose : Changes this transformation into an affinity of ratio Ratio
-- with respect to the plane defined by the origin, the "X Direction" and
-- the "Y Direction" of coordinate system A2.
-- Note: an affinity is a point-by-point transformation that
-- transforms any point P into a point P' such that if H is
-- the orthogonal projection of P on the axis A1 or the
-- plane A2, the vectors HP and HP' satisfy:
-- HP' = Ratio * HP.
SetValue (me : in out; Row, Col : Integer; Value : Real)
---C++: inline
--- Purpose :
-- Replaces the coefficient (Row, Col) of the matrix representing
-- this transformation by Value. Raises OutOfRange
-- if Row < 1 or Row > 3 or Col < 1 or Col > 4
raises OutOfRange
is static;
SetVectorialPart (me : in out; Matrix : Mat) is static;
---C++: inline
--- Purpose : Replaces the vectorial part of this transformation by Matrix.
SetTranslationPart (me : in out; Coord : XYZ) is static;
--- Purpose : Replaces the translation part of
-- this transformation by the coordinates of the number triple Coord.
SetTrsf (me : in out; T : Trsf) is static;
---C++: inline
--- Purpose : Assigns the vectorial and translation parts of T to this transformation.
IsNegative (me) returns Boolean is static;
---C++: inline
--- Purpose :
-- Returns true if the determinant of the vectorial part of
-- this transformation is negative.
IsSingular (me) returns Boolean is static;
---C++: inline
--- Purpose :
-- Returns true if this transformation is singular (and
-- therefore, cannot be inverted).
-- Note: The Gauss LU decomposition is used to invert the
-- transformation matrix. Consequently, the transformation
-- is considered as singular if the largest pivot found is less
-- than or equal to gp::Resolution().
-- Warning
-- If this transformation is singular, it cannot be inverted.
Form (me) returns TrsfForm is static;
--- Purpose :
-- Returns the nature of the transformation. It can be an
-- identity transformation, a rotation, a translation, a mirror
-- transformation (relative to a point, an axis or a plane), a
-- scaling transformation, a compound transformation or
-- some other type of transformation.
SetForm (me:in out) is static;
--- Purpose :
-- verify and set the shape of the GTrsf Other or CompoundTrsf
-- Ex :
-- myGTrsf.SetValue(row1,col1,val1);
-- myGTrsf.SetValue(row2,col2,val2);
-- ...
-- myGTrsf.SetForm();
TranslationPart (me) returns XYZ is static;
--- Purpose : Returns the translation part of the GTrsf.
---C++: inline
---C++: return const&
VectorialPart (me) returns Mat is static;
--- Purpose :
-- Computes the vectorial part of the GTrsf. The returned Matrix
-- is a 3*3 matrix.
---C++: inline
---C++: return const&
Value (me; Row, Col : Integer) returns Real
--- Purpose :
-- Returns the coefficients of the global matrix of transformation.
-- Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 4
---C++: inline
---C++: alias operator()
raises OutOfRange
is static;
Invert (me : in out) raises ConstructionError is static;
Inverted (me) returns GTrsf raises ConstructionError is static;
---C++: inline
--- Purpose :
-- Computes the reverse transformation.
-- Raises an exception if the matrix of the transformation
-- is not inversible.
Multiply (me : in out; T : GTrsf) is static;
--- Purpose :
-- Computes the transformation composed from T and <me>.
-- In a C++ implementation you can also write Tcomposed = <me> * T.
--- Example :
-- GTrsf T1, T2, Tcomp; ...............
-- //composition :
-- Tcomp = T2.Multiplied(T1); // or (Tcomp = T2 * T1)
-- // transformation of a point
-- XYZ P(10.,3.,4.);
-- XYZ P1(P);
-- Tcomp.Transforms(P1); //using Tcomp
-- XYZ P2(P);
-- T1.Transforms(P2); //using T1 then T2
-- T2.Transforms(P2); // P1 = P2 !!!
-- C++: alias operator *=
Multiplied (me; T : GTrsf) returns GTrsf is static;
--- Purpose :
-- Computes the transformation composed with <me> and T.
-- <me> = T * <me>
---C++: inline
-- C++: alias operator *
PreMultiply (me : in out; T : GTrsf) is static;
---Purpose:
-- Computes the product of the transformation T and this
-- transformation and assigns the result to this transformation.
-- this = T * this
Power (me : in out; N : Integer) raises ConstructionError is static;
Powered (me; N : Integer) returns GTrsf raises ConstructionError is static;
---C++: inline
--- Purpose :
-- Computes:
-- - the product of this transformation multiplied by itself
-- N times, if N is positive, or
-- - the product of the inverse of this transformation
-- multiplied by itself |N| times, if N is negative.
-- If N equals zero, the result is equal to the Identity
-- transformation.
-- I.e.: <me> * <me> * .......* <me>, N time.
-- if N =0 <me> = Identity
-- if N < 0 <me> = <me>.Inverse() *...........* <me>.Inverse().
--
-- Raises an exception if N < 0 and if the matrix of the
-- transformation not inversible.
Transforms (me; Coord : in out XYZ) is static;
---C++: inline
Transforms (me; X, Y, Z : in out Real) is static;
---C++: inline
--- Purpose : Transforms a triplet XYZ with a GTrsf.
Trsf (me) returns Trsf raises ConstructionError is static;
---C++: inline
fields
matrix : Mat;
loc : XYZ;
shape : TrsfForm;
scale : Real;
end;

144
src/gp/gp_GTrsf.cxx Executable file
View File

@@ -0,0 +1,144 @@
// File gp_GTrsf.cxx JCV 14/12/90
#define No_Standard_OutOfRange
#include <gp_GTrsf.ixx>
#include <gp_Mat.hxx>
void gp_GTrsf::SetTranslationPart (const gp_XYZ& Coord)
{
loc = Coord;
if (Form() == gp_CompoundTrsf || Form() == gp_Other ||
Form() == gp_Translation) { }
else if (Form() == gp_Identity) { shape = gp_Translation; }
else { shape = gp_CompoundTrsf; }
}
void gp_GTrsf::Invert ()
{
if (shape == gp_Other) {
matrix.Invert() ;
loc.Multiply (matrix);
loc.Reverse();
}
else {
gp_Trsf T = Trsf();
T.Invert ();
SetTrsf (T);
}
}
void gp_GTrsf::Multiply (const gp_GTrsf& T)
{
if (Form() == gp_Other || T.Form() == gp_Other) {
shape = gp_Other;
loc.Add (T.loc.Multiplied (matrix));
matrix.Multiply(T.matrix);
}
else {
gp_Trsf T1 = Trsf();
gp_Trsf T2 = T.Trsf();
T1.Multiply(T2);
matrix = T1.matrix;
loc = T1.loc;
scale = T1.scale;
shape = T1.shape;
}
}
void gp_GTrsf::Power (const Standard_Integer N)
{
if (N == 0) {
scale = 1.;
shape = gp_Identity;
matrix.SetIdentity();
loc = gp_XYZ (0.,0.,0.);
}
else if (N == 1) { }
else if (N == -1) { Invert(); }
else {
if (shape == gp_Other) {
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_XYZ Temploc = loc;
// Standard_Real Tempscale = scale;
gp_Mat Tempmatrix (matrix);
while (1) {
if (IsOdd(Npower)) {
loc.Add (Temploc.Multiplied (matrix));
matrix.Multiply (Tempmatrix);
}
if (Npower == 1) { break; }
Temploc.Add (Temploc.Multiplied (Tempmatrix));
Tempmatrix.Multiply (Tempmatrix);
Npower = Npower/2;
}
}
else {
gp_Trsf T = Trsf ();
T.Power (N);
SetTrsf (T);
}
}
}
void gp_GTrsf::PreMultiply (const gp_GTrsf& T)
{
if (Form() == gp_Other || T.Form() == gp_Other) {
shape = gp_Other;
loc.Multiply (T.matrix);
loc.Add (T.loc);
matrix.PreMultiply(T.matrix);
}
else {
gp_Trsf T1 = Trsf();
gp_Trsf T2 = T.Trsf();
T1.PreMultiply(T2);
matrix = T1.matrix;
loc = T1.loc;
scale = T1.scale;
shape = T1.shape;
}
}
void gp_GTrsf::SetForm()
{
Standard_Real tol = 1.e-12; // Precision::Angular();
//
// don t trust the initial values !
//
gp_Mat M(matrix);
Standard_Real s = M.Determinant();
Standard_Real As = s;
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As < gp::Resolution(),"gp_GTrsf::SetForm, null determinant");
if (s > 0)
s = Pow(s,1./3.);
else
s = -Pow(-s,1./3.);
M.Divide(s);
// check if the matrix is an uniform matrix
// the transposition should be the invert.
gp_Mat TM(M);
TM.Transpose();
TM.Multiply(M);
gp_Mat anIdentity ;
anIdentity.SetIdentity() ;
TM.Subtract(anIdentity);
if (shape==gp_Other) shape = gp_CompoundTrsf;
Standard_Integer i, j;
for (i=1; i<=3; i++) {
for (j=1; j<=3; j++) {
As = TM.Value(i,j);
if (As < 0) As = - As;
if (As > tol) {
shape = gp_Other;
return;
}
}
}
}

176
src/gp/gp_GTrsf.lxx Executable file
View File

@@ -0,0 +1,176 @@
// File gp_GTrsf.lxx JCV 14/12/1990
#include <gp_Ax2.hxx>
#include <gp_Ax1.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_ConstructionError.hxx>
inline gp_GTrsf::gp_GTrsf ()
{
shape = gp_Identity;
matrix.SetScale (1.0);
loc.SetCoord (0.0, 0.0, 0.0);
scale = 1.0;
}
inline gp_GTrsf::gp_GTrsf (const gp_Trsf& T)
{
shape = T.Form();
matrix = T.matrix;
loc = T.TranslationPart();
scale = T.ScaleFactor();
}
inline gp_GTrsf::gp_GTrsf (const gp_Mat& M,
const gp_XYZ& V) : matrix(M), loc(V)
{
shape = gp_Other;
scale = 0.0;
}
inline void gp_GTrsf::SetAffinity (const gp_Ax1& A1,
const Standard_Real Ratio)
{
shape = gp_Other;
scale = 0.0;
matrix.SetDot (A1.Direction().XYZ());
matrix.Multiply (1.0 - Ratio);
matrix.SetDiagonal (matrix.Value (1,1) + Ratio,
matrix.Value (2,2) + Ratio,
matrix.Value (3,3) + Ratio);
loc = A1.Location().XYZ();
loc.Reverse ();
loc.Multiply (matrix);
loc.Add (A1.Location().XYZ());
}
//=======================================================================
//function : SetAffinity
//history : AGV 2-05-06: Correct the implementation
//=======================================================================
inline void gp_GTrsf::SetAffinity (const gp_Ax2& A2,
const Standard_Real Ratio)
{
shape = gp_Other;
scale = 0.0;
matrix.SetDot (A2.Direction().XYZ());
matrix.Multiply (Ratio - 1.);
loc = A2.Location().XYZ();
loc.Reverse ();
loc.Multiply (matrix);
matrix.SetDiagonal (matrix.Value (1,1) +1.,
matrix.Value (2,2) +1.,
matrix.Value (3,3) +1.);
}
inline void gp_GTrsf::SetValue (const Standard_Integer Row,
const Standard_Integer Col,
const Standard_Real Value)
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 3 || Col < 1 || Col > 4, " ");
if (Col == 4) {
loc.SetCoord (Row, Value);
if (shape == gp_Identity) shape = gp_Translation;
return;
}
else {
if (!(shape == gp_Other) && !(scale == 1.0)) matrix.Multiply (scale);
matrix.SetValue (Row, Col, Value);
shape = gp_Other;
scale = 0.0;
return;
}
}
inline void gp_GTrsf::SetVectorialPart (const gp_Mat& Matrix)
{
matrix = Matrix;
shape = gp_Other;
scale = 0.0;
}
inline void gp_GTrsf::SetTrsf (const gp_Trsf& T)
{
shape = T.shape;
matrix = T.matrix;
loc = T.loc;
scale = T.scale;
}
inline Standard_Boolean gp_GTrsf::IsNegative () const
{ return matrix.Determinant() < 0.0; }
inline Standard_Boolean gp_GTrsf::IsSingular () const
{ return matrix.IsSingular(); }
inline gp_TrsfForm gp_GTrsf::Form () const
{ return shape; }
inline const gp_XYZ& gp_GTrsf::TranslationPart () const
{ return loc; }
inline const gp_Mat& gp_GTrsf::VectorialPart () const
{ return matrix; }
inline Standard_Real gp_GTrsf::Value (const Standard_Integer Row,
const Standard_Integer Col) const
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 3 || Col < 1 || Col > 4, " ");
if (Col == 4) return loc.Coord (Row);
if (shape == gp_Other) return matrix.Value (Row, Col);
return scale * matrix.Value (Row, Col);
}
inline gp_GTrsf gp_GTrsf::Inverted () const
{
gp_GTrsf T = *this;
T.Invert ();
return T;
}
inline gp_GTrsf gp_GTrsf::Multiplied (const gp_GTrsf& T) const
{
gp_GTrsf Tres = *this;
Tres.Multiply (T);
return Tres;
}
inline gp_GTrsf gp_GTrsf::Powered (const Standard_Integer N) const
{
gp_GTrsf T = *this;
T.Power (N);
return T;
}
inline void gp_GTrsf::Transforms (gp_XYZ& Coord) const
{
Coord.Multiply (matrix);
if (!(shape == gp_Other) && !(scale == 1.0)) Coord.Multiply (scale);
Coord.Add(loc);
}
inline void gp_GTrsf::Transforms (Standard_Real& X,
Standard_Real& Y,
Standard_Real& Z) const
{
gp_XYZ Triplet (X, Y, Z);
Triplet.Multiply (matrix);
if (!(shape == gp_Other) && !(scale == 1.0)) Triplet.Multiply (scale);
Triplet.Add(loc);
Triplet.Coord (X, Y, Z);
}
inline gp_Trsf gp_GTrsf::Trsf () const
{
gp_Trsf T;
Standard_ConstructionError_Raise_if
(Form() == gp_Other,"");
T.shape = shape;
T.scale = scale;
T.matrix = matrix;
T.loc = loc;
return T;
}

266
src/gp/gp_GTrsf2d.cdl Executable file
View File

@@ -0,0 +1,266 @@
---Copyright: Matra Datavision 1991, 1992
class GTrsf2d from gp inherits Storable
--- Purpose :
-- Defines a non persistent transformation in 2D space.
-- This transformation is a general transformation.
-- It can be a Trsf2d from package gp, an affinity, or you can
-- define your own transformation giving the corresponding
-- matrix of transformation.
--
-- With a GTrsf2d you can transform only a doublet of coordinates
-- XY. It is not possible to transform other geometric objects
-- because these transformations can change the nature of non-
-- elementary geometric objects.
-- A GTrsf2d is represented with a 2 rows * 3 columns matrix :
--
-- V1 V2 T XY XY
-- | a11 a12 a14 | | x | | x'|
-- | a21 a22 a24 | | y | | y'|
-- | 0 0 1 | | 1 | | 1 |
--
-- where {V1, V2} defines the vectorial part of the
-- transformation and T defines the translation part of
-- the transformation.
-- Warning
-- A GTrsf2d transformation is only applicable on
-- coordinates. Be careful if you apply such a
-- transformation to all the points of a geometric object,
-- as this can change the nature of the object and thus
-- render it incoherent!
-- Typically, a circle is transformed into an ellipse by an
-- affinity transformation. To avoid modifying the nature of
-- an object, use a gp_Trsf2d transformation instead, as
-- objects of this class respect the nature of geometric objects.
uses Ax2d from gp,
Mat2d from gp,
Trsf2d from gp,
Vec2d from gp,
XY from gp,
TrsfForm from gp
raises ConstructionError from Standard,
OutOfRange from Standard
is
Create returns GTrsf2d;
---C++: inline
--- Purpose : returns identity transformation.
Create (T : Trsf2d) returns GTrsf2d;
---C++: inline
--- Purpose : Converts the gp_Trsf2d transformation T into a
-- general transformation.
Create (M : Mat2d; V : XY) returns GTrsf2d;
---C++: inline
--- Purpose : Creates a transformation based on the matrix M and the
-- vector V where M defines the vectorial part of the
-- transformation, and V the translation part.
SetAffinity (me : in out; A : Ax2d; Ratio : Real) is static;
--- Purpose :
-- Changes this transformation into an affinity of ratio Ratio
-- with respect to the axis A.
-- Note: An affinity is a point-by-point transformation that
-- transforms any point P into a point P' such that if H is
-- the orthogonal projection of P on the axis A, the vectors
-- HP and HP' satisfy: HP' = Ratio * HP.
SetValue (me : in out; Row, Col : Integer; Value : Real)
---C++: inline
--- Purpose :
-- Replaces the coefficient (Row, Col) of the matrix representing
-- this transformation by Value,
-- Raises OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 3
raises OutOfRange
is static;
SetTranslationPart (me : in out; Coord : XY) is static;
--- Purpose : Replacesthe translation part of this
-- transformation by the coordinates of the number pair Coord.
SetTrsf2d (me : in out; T : Trsf2d) is static;
---C++: inline
--- Purpose :
-- Assigns the vectorial and translation parts of T to this transformation.
SetVectorialPart (me : in out; Matrix : Mat2d) is static;
---C++: inline
--- Purpose :
-- Replaces the vectorial part of this transformation by Matrix.
IsNegative (me) returns Boolean is static;
---C++: inline
--- Purpose :
-- Returns true if the determinant of the vectorial part of
-- this transformation is negative.
IsSingular (me) returns Boolean is static;
---C++: inline
--- Purpose : Returns true if this transformation is singular (and
-- therefore, cannot be inverted).
-- Note: The Gauss LU decomposition is used to invert the
-- transformation matrix. Consequently, the transformation
-- is considered as singular if the largest pivot found is less
-- than or equal to gp::Resolution().
-- Warning
-- If this transformation is singular, it cannot be inverted.
Form (me) returns TrsfForm is static;
---C++: inline
--- Purpose :
-- Returns the nature of the transformation. It can be
-- an identity transformation, a rotation, a translation, a mirror
-- transformation (relative to a point or axis), a scaling
-- transformation, a compound transformation or some
-- other type of transformation.
TranslationPart (me) returns XY is static;
--- Purpose : Returns the translation part of the GTrsf2d.
---C++: inline
---C++: return const&
VectorialPart (me) returns Mat2d is static;
--- Purpose :
-- Computes the vectorial part of the GTrsf2d. The returned
-- Matrix is a 2*2 matrix.
---C++: inline
---C++: return const&
Value (me; Row, Col : Integer) returns Real
--- Purpose :
-- Returns the coefficients of the global matrix of transformation.
--- Raised OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 3
---C++: inline
---C++: alias operator()
raises OutOfRange
is static;
Invert (me : in out) raises ConstructionError is static;
Inverted (me) returns GTrsf2d raises ConstructionError is static;
---C++: inline
--- Purpose :
-- Computes the reverse transformation.
-- Raised an exception if the matrix of the transformation
-- is not inversible.
Multiply (me : in out; T : GTrsf2d) is static;
---C++: alias operator *=
Multiplied (me; T : GTrsf2d) returns GTrsf2d is static;
---C++: inline
---C++: alias operator *
--- Purpose :
-- Computes the transformation composed with T and <me>.
-- In a C++ implementation you can also write Tcomposed = <me> * T.
-- Example :
-- GTrsf2d T1, T2, Tcomp; ...............
-- //composition :
-- Tcomp = T2.Multiplied(T1); // or (Tcomp = T2 * T1)
-- // transformation of a point
-- XY P(10.,3.);
-- XY P1(P);
-- Tcomp.Transforms(P1); //using Tcomp
-- XY P2(P);
-- T1.Transforms(P2); //using T1 then T2
-- T2.Transforms(P2); // P1 = P2 !!!
PreMultiply (me : in out; T : GTrsf2d) is static;
--- Purpose :
-- Computes the product of the transformation T and this
-- transformation, and assigns the result to this transformation:
-- this = T * this
Power (me : in out; N : Integer) raises ConstructionError is static;
Powered (me; N : Integer) returns GTrsf2d raises ConstructionError is static;
---C++: inline
--- Purpose :
-- Computes the following composition of transformations
-- <me> * <me> * .......* <me>, N time.
-- if N = 0 <me> = Identity
-- if N < 0 <me> = <me>.Inverse() *...........* <me>.Inverse().
--
-- Raises an exception if N < 0 and if the matrix of the
-- transformation is not inversible.
Transforms (me; Coord : in out XY) is static;
---C++: inline
Transformed(me; Coord : in XY from gp)
returns XY from gp
is static;
---C++: inline
Transforms (me; X, Y : in out Real) is static;
---C++: inline
---Purpose:
-- Applies this transformation to the coordinates:
-- - of the number pair Coord, or
-- - X and Y.
--
-- Note:
-- - Transforms modifies X, Y, or the coordinate pair Coord, while
-- - Transformed creates a new coordinate pair.
Trsf2d (me) returns Trsf2d raises ConstructionError is static;
---Purpose:
-- Converts this transformation into a gp_Trsf2d transformation.
-- Exceptions
-- Standard_ConstructionError if this transformation
-- cannot be converted, i.e. if its form is gp_Other.
fields
matrix : Mat2d;
loc : XY;
shape : TrsfForm;
scale : Real;
end;

160
src/gp/gp_GTrsf2d.cxx Executable file
View File

@@ -0,0 +1,160 @@
// File gp_GTrsf2d.cxx JCV 08/01/91
#include <gp_GTrsf2d.ixx>
#include <Standard_ConstructionError.hxx>
#include <Precision.hxx>
void gp_GTrsf2d::SetAffinity (const gp_Ax2d& A,
const Standard_Real Ratio)
{
shape = gp_Other;
scale = 0.0;
Standard_Real a = A.Direction().X();
Standard_Real b = A.Direction().Y();
matrix.SetValue (1, 1, (1.0 - Ratio)*a*a + Ratio);
matrix.SetValue (2, 2, (1.0 - Ratio)*b*b + Ratio);
matrix.SetValue (1, 2, (1.0 - Ratio)*a*b);
matrix.SetValue (2, 1, matrix.Value (1, 2));
loc = A.Location().XY();
loc.Reverse();
loc.Multiply (matrix);
loc.Add (A.Location().XY());
}
void gp_GTrsf2d::SetTranslationPart (const gp_XY& Coord)
{
loc = Coord;
if (Form() == gp_CompoundTrsf || Form() == gp_Other ||
Form() == gp_Translation) { }
else if (Form() == gp_Identity) { shape = gp_Translation; }
else { shape = gp_CompoundTrsf; }
}
void gp_GTrsf2d::Invert ()
{
if (shape == gp_Other) {
matrix.Invert();
loc.Multiply (matrix);
loc.Reverse();
}
else {
gp_Trsf2d T = Trsf2d ();
T.Invert ();
SetTrsf2d (T);
}
}
void gp_GTrsf2d::Multiply (const gp_GTrsf2d& T)
{
if (Form() == gp_Other || T.Form() == gp_Other) {
shape = gp_Other;
loc.Add (T.loc.Multiplied (matrix));
matrix.Multiply(T.matrix);
}
else {
gp_Trsf2d T1 = Trsf2d();
gp_Trsf2d T2 = T.Trsf2d();
T1.Multiply(T2);
matrix = T1.matrix;
loc = T1.loc;
scale = T1.scale;
shape = T1.shape;
}
}
void gp_GTrsf2d::Power (const Standard_Integer N)
{
if (N == 0) {
scale = 1.0;
shape = gp_Identity;
matrix.SetIdentity();
loc = gp_XY (0., 0.);
}
else if (N == 1) { }
else if (N == -1) { Invert(); }
else {
if (N < 0) { Invert(); }
if (shape == gp_Other) {
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_XY Temploc = loc;
// Standard_Real Tempscale = scale;
gp_Mat2d Tempmatrix (matrix);
while (1) {
if (IsOdd(Npower)) {
loc.Add (Temploc.Multiplied (matrix));
matrix.Multiply (Tempmatrix);
}
if (Npower == 1) { break; }
Temploc.Add (Temploc.Multiplied (Tempmatrix));
Tempmatrix.Multiply (Tempmatrix);
Npower = Npower/2;
}
}
else {
gp_Trsf2d T = Trsf2d ();
T.Power (N);
SetTrsf2d (T);
}
}
}
void gp_GTrsf2d::PreMultiply (const gp_GTrsf2d& T)
{
if (Form() == gp_Other || T.Form() == gp_Other) {
shape = gp_Other;
loc.Multiply (T.matrix);
loc.Add (T.loc);
matrix.PreMultiply(T.matrix);
}
else {
gp_Trsf2d T1 = Trsf2d();
gp_Trsf2d T2 = T.Trsf2d();
T1.PreMultiply(T2);
matrix = T1.matrix;
loc = T1.loc;
scale = T1.scale;
shape = T1.shape;
}
}
gp_Trsf2d gp_GTrsf2d::Trsf2d () const
{
gp_Trsf2d T;
Standard_Real value;
#ifndef No_Exception
Standard_Real tolerance = Precision::Angular() ;
Standard_Real tol2 = 2. * tolerance;
#endif
Standard_ConstructionError_Raise_if
(Form() == gp_Other," gp_GTrsf2d::Trsf2d() - non-orthogonal GTrsf2d (0)");
//Test of orthogonality
value = (matrix.Value(1,1) * matrix.Value(1,1) +
matrix.Value(2,1) * matrix.Value(2,1)) ;
Standard_ConstructionError_Raise_if
(Abs(value - 1.) > tol2," gp_GTrsf2d::Trsf2d() - non-orthogonal GTrsf2d (1)");
value = (matrix.Value(1,2) * matrix.Value(1,2) +
matrix.Value(2,2) * matrix.Value(2,2));
Standard_ConstructionError_Raise_if
(Abs(value - 1.) > tol2," gp_GTrsf2d::Trsf2d() - non-orthogonal GTrsf2d (2)");
value = (matrix.Value(1,1) * matrix.Value(1,2) +
matrix.Value(2,1) * matrix.Value(2,2));
Standard_ConstructionError_Raise_if
(Abs(value) > tolerance," gp_GTrsf2d::Trsf2d() - non-orthogonal GTrsf2d (3)");
//
T.matrix = matrix ;
T.shape = shape;
T.scale = scale ;
T.loc = loc;
return T;
}

119
src/gp/gp_GTrsf2d.lxx Executable file
View File

@@ -0,0 +1,119 @@
// File gp_GTrsf2d.lxx JCV 08/01/1991
#include <gp_Trsf2d.hxx>
#include <Standard_OutOfRange.hxx>
inline gp_GTrsf2d::gp_GTrsf2d ()
{
shape = gp_Identity;
matrix.SetScale (1.0);
loc.SetCoord (0.0, 0.0);
scale = 1.0;
}
inline gp_GTrsf2d::gp_GTrsf2d (const gp_Trsf2d& T)
{
shape = T.shape;
matrix = T.matrix;
loc = T.loc;
scale = T.scale;
}
inline gp_GTrsf2d::gp_GTrsf2d (const gp_Mat2d& M,
const gp_XY& V) :
matrix(M),
loc(V)
{ shape = gp_Other; scale = 0.0; }
inline void gp_GTrsf2d::SetValue (const Standard_Integer Row,
const Standard_Integer Col,
const Standard_Real Value)
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 2 || Col < 1 || Col > 3, " ");
if (Col == 3) loc.SetCoord (Row, Value);
else matrix.SetValue (Row, Col, Value);
shape = gp_Other;
}
inline void gp_GTrsf2d::SetTrsf2d (const gp_Trsf2d& T)
{
shape = T.shape;
matrix = T.matrix;
loc = T.loc;
scale = T.scale;
}
inline void gp_GTrsf2d::SetVectorialPart (const gp_Mat2d& Matrix)
{ matrix = Matrix; shape = gp_Other; scale = 0.0; }
inline Standard_Boolean gp_GTrsf2d::IsNegative () const
{ return matrix.Determinant() < 0.0; }
inline Standard_Boolean gp_GTrsf2d::IsSingular () const
{ return matrix.IsSingular(); }
inline const gp_Mat2d& gp_GTrsf2d::VectorialPart () const
{ return matrix; }
inline Standard_Real gp_GTrsf2d::Value (const Standard_Integer Row,
const Standard_Integer Col) const
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 2 || Col < 1 || Col > 3, " ");
if (Col == 3) return loc.Coord (Row);
if (shape == gp_Other) return matrix.Value (Row, Col);
return scale * matrix.Value (Row, Col);
}
inline gp_TrsfForm gp_GTrsf2d::Form () const
{ return shape; }
inline const gp_XY& gp_GTrsf2d::TranslationPart () const
{ return loc; }
inline gp_GTrsf2d gp_GTrsf2d::Inverted () const
{
gp_GTrsf2d T = *this;
T.Invert ();
return T;
}
inline gp_GTrsf2d gp_GTrsf2d::Multiplied (const gp_GTrsf2d& T) const
{
gp_GTrsf2d Tres = *this;
Tres.Multiply (T);
return Tres;
}
inline gp_GTrsf2d gp_GTrsf2d::Powered (const Standard_Integer N) const
{
gp_GTrsf2d T = *this;
T.Power (N);
return T;
}
inline void gp_GTrsf2d::Transforms (gp_XY& Coord) const
{
Coord.Multiply (matrix);
if (!(shape == gp_Other) && !(scale == 1.0)) Coord.Multiply (scale);
Coord.Add(loc);
}
inline gp_XY gp_GTrsf2d::Transformed(const gp_XY& Coord) const
{
gp_XY newCoord = Coord;
Transforms(newCoord);
return newCoord;
}
inline void gp_GTrsf2d::Transforms (Standard_Real& X,
Standard_Real& Y) const
{
gp_XY Doublet (X, Y);
Doublet.Multiply (matrix);
if (!(shape == gp_Other) && !(scale == 1.0)) Doublet.Multiply (scale);
Doublet.Add(loc);
Doublet.Coord (X, Y);
}

387
src/gp/gp_Hypr.cdl Executable file
View File

@@ -0,0 +1,387 @@
---Copyright: Matra Datavision 1991, 1992
class Hypr from gp inherits Storable
--- Purpose : Describes a branch of a hyperbola in 3D space.
-- A hyperbola is defined by its major and minor radii and
-- positioned in space with a coordinate system (a gp_Ax2
-- object) of which:
-- - the origin is the center of the hyperbola,
-- - the "X Direction" defines the major axis of the
-- hyperbola, and
-- - the "Y Direction" defines the minor axis of the hyperbola.
-- The origin, "X Direction" and "Y Direction" of this
-- coordinate system together define the plane of the
-- hyperbola. This coordinate system is the "local
-- coordinate system" of the hyperbola. In this coordinate
-- system, the equation of the hyperbola is:
-- X*X/(MajorRadius**2)-Y*Y/(MinorRadius**2) = 1.0
-- The branch of the hyperbola described is the one located
-- on the positive side of the major axis.
-- The "main Direction" of the local coordinate system is a
-- normal vector to the plane of the hyperbola. This vector
-- gives an implicit orientation to the hyperbola. We refer to
-- the "main Axis" of the local coordinate system as the
-- "Axis" of the hyperbola.
-- The following schema shows the plane of the hyperbola,
-- and in it, the respective positions of the three branches of
-- hyperbolas constructed with the functions OtherBranch,
-- ConjugateBranch1, and ConjugateBranch2:
--
-- ^YAxis
-- |
-- FirstConjugateBranch
-- |
-- Other | Main
-- --------------------- C ------------------------------>XAxis
-- Branch | Branch
-- |
-- |
-- SecondConjugateBranch
-- | ^YAxis
-- Warning
-- The major radius can be less than the minor radius.
-- See Also
-- gce_MakeHypr which provides functions for more
-- complex hyperbola constructions
-- Geom_Hyperbola which provides additional functions for
-- constructing hyperbolas and works, in particular, with the
-- parametric equations of hyperbolas
uses Ax1 from gp,
Ax2 from gp,
Pln from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard,
DomainError from Standard
is
Create returns Hypr;
---C++: inline
--- Purpose : Creates of an indefinite hyperbola.
Create (A2 : Ax2; MajorRadius, MinorRadius : Real) returns Hypr
---C++: inline
--- Purpose : Creates a hyperbola with radii MajorRadius and
-- MinorRadius, positioned in the space by the
-- coordinate system A2 such that:
-- - the origin of A2 is the center of the hyperbola,
-- - the "X Direction" of A2 defines the major axis of
-- the hyperbola, that is, the major radius
-- MajorRadius is measured along this axis, and
-- - the "Y Direction" of A2 defines the minor axis of
-- the hyperbola, that is, the minor radius
-- MinorRadius is measured along this axis.
-- Note: This class does not prevent the creation of a
-- hyperbola where:
-- - MajorAxis is equal to MinorAxis, or
-- - MajorAxis is less than MinorAxis.
-- Exceptions
-- Standard_ConstructionError if MajorAxis or MinorAxis is negative.
-- Raises ConstructionError if MajorRadius < 0.0 or MinorRadius < 0.0
raises ConstructionError;
--- Purpose : Raised if MajorRadius < 0.0 or MinorRadius < 0.0
SetAxis (me : in out; A1 : Ax1)
---C++: inline
--- Purpose : Modifies this hyperbola, by redefining its local coordinate
-- system so that:
-- - its origin and "main Direction" become those of the
-- axis A1 (the "X Direction" and "Y Direction" are then
-- recomputed in the same way as for any gp_Ax2).
-- Raises ConstructionError if the direction of A1 is parallel to the direction of
-- the "XAxis" of the hyperbola.
raises ConstructionError
is static;
SetLocation (me : in out; P : Pnt) is static;
---C++: inline
--- Purpose : Modifies this hyperbola, by redefining its local coordinate
-- system so that its origin becomes P.
SetMajorRadius (me : in out; MajorRadius : Real)
---C++: inline
--- Purpose:
-- Modifies the major radius of this hyperbola.
-- Exceptions
-- Standard_ConstructionError if MajorRadius is negative.
raises ConstructionError
is static;
SetMinorRadius (me : in out; MinorRadius : Real)
---C++: inline
--- Purpose:
-- Modifies the minor radius of this hyperbola.
-- Exceptions
-- Standard_ConstructionError if MinorRadius is negative.
raises ConstructionError
is static;
SetPosition (me : in out; A2 : Ax2) is static;
---C++: inline
--- Purpose : Modifies this hyperbola, by redefining its local coordinate
-- system so that it becomes A2.
Asymptote1 (me) returns Ax1
---C++: inline
--- Purpose :
-- In the local coordinate system of the hyperbola the equation of
-- the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the
-- equation of the first asymptote is Y = (B/A)*X
-- where A is the major radius and B is the minor radius. Raises ConstructionError if MajorRadius = 0.0
raises ConstructionError
is static;
Asymptote2 (me) returns Ax1
---C++: inline
--- Purpose :
-- In the local coordinate system of the hyperbola the equation of
-- the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the
-- equation of the first asymptote is Y = -(B/A)*X.
-- where A is the major radius and B is the minor radius. Raises ConstructionError if MajorRadius = 0.0
raises ConstructionError
is static;
Axis (me) returns Ax1 is static;
---C++: inline
--- Purpose : Returns the axis passing through the center,
-- and normal to the plane of this hyperbola.
---C++: return const&
ConjugateBranch1 (me) returns Hypr is static;
---C++: inline
--- Purpose :
-- Computes the branch of hyperbola which is on the positive side of the
-- "YAxis" of <me>.
ConjugateBranch2 (me) returns Hypr is static;
---C++: inline
--- Purpose :
-- Computes the branch of hyperbola which is on the negative side of the
-- "YAxis" of <me>.
Directrix1 (me) returns Ax1 is static;
---C++: inline
--- Purpose :
-- This directrix is the line normal to the XAxis of the hyperbola
-- in the local plane (Z = 0) at a distance d = MajorRadius / e
-- from the center of the hyperbola, where e is the eccentricity of
-- the hyperbola.
-- This line is parallel to the "YAxis". The intersection point
-- between the directrix1 and the "XAxis" is the "Location" point
-- of the directrix1. This point is on the positive side of the
-- "XAxis".
Directrix2 (me) returns Ax1 is static;
---C++: inline
--- Purpose :
-- This line is obtained by the symmetrical transformation
-- of "Directrix1" with respect to the "YAxis" of the hyperbola.
Eccentricity (me) returns Real
---C++: inline
--- Purpose :
-- Returns the excentricity of the hyperbola (e > 1).
-- If f is the distance between the location of the hyperbola
-- and the Focus1 then the eccentricity e = f / MajorRadius. Raises DomainError if MajorRadius = 0.0
raises DomainError
is static;
Focal (me) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the focal distance. It is the distance between the
-- the two focus of the hyperbola.
Focus1 (me) returns Pnt is static;
---C++: inline
--- Purpose :
-- Returns the first focus of the hyperbola. This focus is on the
-- positive side of the "XAxis" of the hyperbola.
Focus2 (me) returns Pnt is static;
---C++: inline
--- Purpose :
-- Returns the second focus of the hyperbola. This focus is on the
-- negative side of the "XAxis" of the hyperbola.
Location (me) returns Pnt is static;
---C++: inline
--- Purpose :
-- Returns the location point of the hyperbola. It is the
-- intersection point between the "XAxis" and the "YAxis".
---C++: return const&
MajorRadius (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the major radius of the hyperbola. It is the radius
-- on the "XAxis" of the hyperbola.
MinorRadius (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the minor radius of the hyperbola. It is the radius
-- on the "YAxis" of the hyperbola.
OtherBranch (me) returns Hypr is static;
---C++: inline
--- Purpose :
-- Returns the branch of hyperbola obtained by doing the
-- symmetrical transformation of <me> with respect to the
-- "YAxis" of <me>.
Parameter (me) returns Real
---C++: inline
--- Purpose :
-- Returns p = (e * e - 1) * MajorRadius where e is the
-- eccentricity of the hyperbola.
--- Raises DomainError if MajorRadius = 0.0
raises DomainError
is static;
Position (me) returns Ax2 is static;
--- Purpose : Returns the coordinate system of the hyperbola.
---C++: inline
---C++: return const&
XAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose : Computes an axis, whose
-- - the origin is the center of this hyperbola, and
-- - the unit vector is the "X Direction"
-- of the local coordinate system of this hyperbola.
-- These axes are, the major axis (the "X
-- Axis") and of this hyperboReturns the "XAxis" of the hyperbola.
YAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose : Computes an axis, whose
-- - the origin is the center of this hyperbola, and
-- - the unit vector is the "Y Direction"
-- of the local coordinate system of this hyperbola.
-- These axes are the minor axis (the "Y Axis") of this hyperbola
Mirror (me : in out; P : Pnt) is static;
Mirrored (me; P : Pnt) returns Hypr is static;
--- Purpose :
-- Performs the symmetrical transformation of an hyperbola with
-- respect to the point P which is the center of the symmetry.
Mirror (me : in out; A1 : Ax1) is static;
Mirrored (me; A1 : Ax1) returns Hypr is static;
--- Purpose :
-- Performs the symmetrical transformation of an hyperbola with
-- respect to an axis placement which is the axis of the symmetry.
Mirror (me : in out; A2 : Ax2) is static;
Mirrored (me; A2 : Ax2) returns Hypr is static;
--- Purpose :
-- Performs the symmetrical transformation of an hyperbola with
-- respect to a plane. The axis placement A2 locates the plane
-- of the symmetry (Location, XDirection, YDirection).
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
---C++: inline
Rotated (me; A1 : Ax1; Ang : Real) returns Hypr is static;
---C++: inline
--- Purpose :
-- Rotates an hyperbola. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt; S : Real) returns Hypr is static;
---C++: inline
--- Purpose :
-- Scales an hyperbola. S is the scaling value.
Transform (me : in out; T : Trsf) is static;
---C++: inline
Transformed (me; T : Trsf) returns Hypr is static;
---C++: inline
--- Purpose :
-- Transforms an hyperbola with the transformation T from
-- class Trsf.
Translate (me : in out; V : Vec) is static;
---C++: inline
Translated (me; V : Vec) returns Hypr is static;
---C++: inline
--- Purpose :
-- Translates an hyperbola in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate(me : in out; P1, P2 : Pnt) is static;
---C++: inline
Translated (me; P1, P2 : Pnt) returns Hypr is static;
---C++: inline
--- Purpose :
-- Translates an hyperbola from the point P1 to the point P2.
fields
pos : Ax2;
majorRadius : Real;
minorRadius : Real;
end;

35
src/gp/gp_Hypr.cxx Executable file
View File

@@ -0,0 +1,35 @@
//File gp_Hypr.cxx JCV 12/10/90
// Modif jcv 14/12/90 suite a la premiere revue de projet
#include <gp_Hypr.ixx>
void gp_Hypr::Mirror (const gp_Pnt& P)
{ pos.Mirror(P); }
gp_Hypr gp_Hypr::Mirrored (const gp_Pnt& P) const
{
gp_Hypr H = *this;
H.pos.Mirror(P);
return H;
}
void gp_Hypr::Mirror (const gp_Ax1& A1)
{ pos.Mirror(A1); }
gp_Hypr gp_Hypr::Mirrored (const gp_Ax1& A1) const
{
gp_Hypr H = *this;
H.pos.Mirror(A1);
return H;
}
void gp_Hypr::Mirror (const gp_Ax2& A2)
{ pos.Mirror(A2); }
gp_Hypr gp_Hypr::Mirrored (const gp_Ax2& A2) const
{
gp_Hypr H = *this;
H.pos.Mirror(A2);
return H;
}

244
src/gp/gp_Hypr.lxx Executable file
View File

@@ -0,0 +1,244 @@
//file Hypr.lxx JCV/12/10/90
#include <gp.hxx>
#include <Standard_DomainError.hxx>
#include <Standard_ConstructionError.hxx>
inline gp_Hypr::gp_Hypr () :
majorRadius(RealLast()),
minorRadius(RealFirst())
{ }
inline gp_Hypr::gp_Hypr (const gp_Ax2& A2,
const Standard_Real MajorRadius,
const Standard_Real MinorRadius):
pos(A2),
majorRadius(MajorRadius),
minorRadius(MinorRadius)
{
Standard_ConstructionError_Raise_if
(MinorRadius < 0.0 || MajorRadius < 0.0,"");
}
inline void gp_Hypr::SetAxis (const gp_Ax1& A1)
{ pos.SetAxis (A1); }
inline void gp_Hypr::SetLocation (const gp_Pnt& P)
{ pos = gp_Ax2 (P, pos.Direction(), pos.XDirection()); }
inline void gp_Hypr::SetMajorRadius (const Standard_Real R)
{
Standard_ConstructionError_Raise_if(R < 0.0,"");
majorRadius = R;
}
inline void gp_Hypr::SetMinorRadius (const Standard_Real R)
{
Standard_ConstructionError_Raise_if(R < 0.0,"");
minorRadius = R;
}
inline void gp_Hypr::SetPosition (const gp_Ax2& A2)
{ pos = A2; }
inline gp_Ax1 gp_Hypr::Asymptote1 () const
{
Standard_ConstructionError_Raise_if
(majorRadius <= gp::Resolution(), "");
gp_Vec V1 = gp_Vec (pos.YDirection());
V1.Multiply (minorRadius / majorRadius);
gp_Vec V = gp_Vec (pos.XDirection());
V.Add (V1);
return gp_Ax1(pos.Location(), gp_Dir(V));
}
inline gp_Ax1 gp_Hypr::Asymptote2 () const
{
Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), "");
gp_Vec V1 = gp_Vec (pos.YDirection());
V1.Multiply (-minorRadius / majorRadius);
gp_Vec V = gp_Vec (pos.XDirection());
V.Add (V1);
return gp_Ax1( pos.Location(), gp_Dir(V));
}
inline const gp_Ax1& gp_Hypr::Axis () const
{ return pos.Axis(); }
inline gp_Hypr gp_Hypr::ConjugateBranch1 () const
{
return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), pos.YDirection()),
minorRadius,
majorRadius);
}
inline gp_Hypr gp_Hypr::ConjugateBranch2 () const
{
gp_Dir D = pos.YDirection();
D.Reverse ();
return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), D),
minorRadius,
majorRadius);
}
inline gp_Ax1 gp_Hypr::Directrix1 () const
{
Standard_Real E = Eccentricity();
gp_XYZ Orig = pos.XDirection().XYZ();
Orig.Multiply (majorRadius/E);
Orig.Add (pos.Location().XYZ());
return gp_Ax1 (gp_Pnt(Orig), pos.YDirection());
}
inline gp_Ax1 gp_Hypr::Directrix2 () const
{
Standard_Real E = Eccentricity();
gp_XYZ Orig = pos.XDirection().XYZ();
Orig.Multiply (-majorRadius/E);
Orig.Add (pos.Location().XYZ());
return gp_Ax1 (gp_Pnt(Orig), pos.YDirection());
}
inline Standard_Real gp_Hypr::Eccentricity () const
{
Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), "");
return sqrt(majorRadius * majorRadius +
minorRadius * minorRadius) / majorRadius;
}
inline Standard_Real gp_Hypr::Focal () const
{
return 2.0 * sqrt(majorRadius * majorRadius +
minorRadius * minorRadius);
}
inline gp_Pnt gp_Hypr::Focus1 () const
{
Standard_Real C = sqrt(majorRadius * majorRadius +
minorRadius * minorRadius);
const gp_Pnt& PP = pos.Location ();
const gp_Dir& DD = pos.XDirection();
return gp_Pnt (PP.X() + C * DD.X(),
PP.Y() + C * DD.Y(),
PP.Z() + C * DD.Z());
}
inline gp_Pnt gp_Hypr::Focus2 () const
{
Standard_Real C = sqrt(majorRadius * majorRadius +
minorRadius * minorRadius);
const gp_Pnt& PP = pos.Location ();
const gp_Dir& DD = pos.XDirection();
return gp_Pnt (PP.X() - C * DD.X(),
PP.Y() - C * DD.Y(),
PP.Z() - C * DD.Z());
}
inline const gp_Pnt& gp_Hypr::Location () const
{ return pos.Location(); }
inline Standard_Real gp_Hypr::MajorRadius() const
{ return majorRadius; }
inline Standard_Real gp_Hypr::MinorRadius() const
{ return minorRadius; }
inline gp_Hypr gp_Hypr::OtherBranch () const
{
gp_Dir D = pos.XDirection ();
D.Reverse ();
return gp_Hypr (gp_Ax2(pos.Location(), pos.Direction(), D),
majorRadius, minorRadius);
}
inline Standard_Real gp_Hypr::Parameter() const
{
Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), "");
return (minorRadius * minorRadius) / majorRadius;
}
inline const gp_Ax2& gp_Hypr::Position() const
{ return pos; }
inline gp_Ax1 gp_Hypr::XAxis () const
{return gp_Ax1 (pos.Location(), pos.XDirection());}
inline gp_Ax1 gp_Hypr::YAxis () const
{return gp_Ax1 (pos.Location(), pos.YDirection());}
inline void gp_Hypr::Rotate (const gp_Ax1& A1,
const Standard_Real Ang)
{ pos.Rotate(A1, Ang); }
inline gp_Hypr gp_Hypr::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Hypr H = *this;
H.pos.Rotate(A1, Ang);
return H;
}
inline void gp_Hypr::Scale (const gp_Pnt& P,
const Standard_Real S)
{
majorRadius *= S;
if (majorRadius < 0) majorRadius = - majorRadius;
minorRadius *= S;
if (minorRadius < 0) minorRadius = - minorRadius;
pos.Scale(P, S);
}
inline gp_Hypr gp_Hypr::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Hypr H = *this;
H.majorRadius *= S;
if (H.majorRadius < 0) H.majorRadius = - H.majorRadius;
H.minorRadius *= S;
if (H.minorRadius < 0) H.minorRadius = - H.minorRadius;
H.pos.Scale(P, S);
return H;
}
inline void gp_Hypr::Transform (const gp_Trsf& T)
{
majorRadius *= T.ScaleFactor();
if (majorRadius < 0) majorRadius = - majorRadius;
minorRadius *= T.ScaleFactor();
if (minorRadius < 0) minorRadius = - minorRadius;
pos.Transform(T);
}
inline gp_Hypr gp_Hypr::Transformed (const gp_Trsf& T) const
{
gp_Hypr H = *this;
H.majorRadius *= T.ScaleFactor();
if (H.majorRadius < 0) H.majorRadius = - H.majorRadius;
H.minorRadius *= T.ScaleFactor();
if (H.minorRadius < 0) H.minorRadius = - H.minorRadius;
H.pos.Transform(T);
return H;
}
inline void gp_Hypr::Translate (const gp_Vec& V)
{ pos.Translate(V); }
inline gp_Hypr gp_Hypr::Translated (const gp_Vec& V) const
{
gp_Hypr H = *this;
H.pos.Translate(V);
return H;
}
inline void gp_Hypr::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{pos.Translate(P1,P2);}
inline gp_Hypr gp_Hypr::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Hypr H = *this;
H.pos.Translate(P1, P2);
return H;
}

415
src/gp/gp_Hypr2d.cdl Executable file
View File

@@ -0,0 +1,415 @@
---Copyright: Matra Datavision 1991, 1992
class Hypr2d from gp inherits Storable
---Purpose:
-- Describes a branch of a hyperbola in the plane (2D space).
-- A hyperbola is defined by its major and minor radii, and
-- positioned in the plane with a coordinate system (a
-- gp_Ax22d object) of which:
-- - the origin is the center of the hyperbola,
-- - the "X Direction" defines the major axis of the hyperbola, and
-- - the "Y Direction" defines the minor axis of the hyperbola.
-- This coordinate system is the "local coordinate system"
-- of the hyperbola. The orientation of this coordinate
-- system (direct or indirect) gives an implicit orientation to
-- the hyperbola. In this coordinate system, the equation of
-- the hyperbola is:
-- X*X/(MajorRadius**2)-Y*Y/(MinorRadius**2) = 1.0
-- The branch of the hyperbola described is the one located
-- on the positive side of the major axis.
-- The following schema shows the plane of the hyperbola,
-- and in it, the respective positions of the three branches of
-- hyperbolas constructed with the functions OtherBranch,
-- ConjugateBranch1, and ConjugateBranch2:
-- ^YAxis
-- |
-- FirstConjugateBranch
-- |
-- Other | Main
-- --------------------- C ------------------------------>XAxis
-- Branch | Branch
-- |
-- |
-- SecondConjugateBranch
-- |
--
-- Warning
-- The major radius can be less than the minor radius.
-- See Also
-- gce_MakeHypr2d which provides functions for more
-- complex hyperbola constructions
-- Geom2d_Hyperbola which provides additional functions
-- for constructing hyperbolas and works, in particular, with
-- the parametric equations of hyperbolas
uses Ax2d from gp,
Ax22d from gp,
Pnt2d from gp,
Trsf2d from gp,
Vec2d from gp
raises ConstructionError from Standard,
DomainError from Standard
is
Create returns Hypr2d;
---C++: inline
--- Purpose : Creates of an indefinite hyperbola.
Create (MajorAxis : Ax2d;
MajorRadius, MinorRadius : Real;
Sense : Boolean from Standard = Standard_True)
returns Hypr2d
--- Purpose :
-- Creates a hyperbola with radii MajorRadius and
-- MinorRadius, centered on the origin of MajorAxis
-- and where the unit vector of MajorAxis is the "X
-- Direction" of the local coordinate system of the
-- hyperbola. This coordinate system is direct if Sense
-- is true (the default value), and indirect if Sense is false.
-- Warnings :
-- It is yet possible to create an Hyperbola with
-- MajorRadius <= MinorRadius.
-- Raises ConstructionError if MajorRadius < 0.0 or MinorRadius < 0.0
raises ConstructionError;
Create (A : Ax22d; MajorRadius, MinorRadius : Real)
returns Hypr2d
---C++: inline
--- Purpose :
-- a hyperbola with radii MajorRadius and
-- MinorRadius, positioned in the plane by coordinate system A where:
-- - the origin of A is the center of the hyperbola,
-- - the "X Direction" of A defines the major axis of
-- the hyperbola, that is, the major radius
-- MajorRadius is measured along this axis, and
-- - the "Y Direction" of A defines the minor axis of
-- the hyperbola, that is, the minor radius
-- MinorRadius is measured along this axis, and
-- - the orientation (direct or indirect sense) of A
-- gives the implicit orientation of the hyperbola.
-- Warnings :
-- It is yet possible to create an Hyperbola with
-- MajorRadius <= MinorRadius.
-- Raises ConstructionError if MajorRadius < 0.0 or MinorRadius < 0.0
raises ConstructionError;
SetLocation (me : in out; P : Pnt2d) is static;
---C++: inline
--- Purpose : Modifies this hyperbola, by redefining its local
-- coordinate system so that its origin becomes P.
SetMajorRadius (me : in out; MajorRadius : Real)
raises ConstructionError
---C++: inline
---Purpose: Modifies the major or minor radius of this hyperbola.
-- Exceptions
-- Standard_ConstructionError if MajorRadius or
-- MinorRadius is negative.
is static;
SetMinorRadius (me : in out; MinorRadius : Real)
raises ConstructionError
---C++: inline
---Purpose: Modifies the major or minor radius of this hyperbola.
-- Exceptions
-- Standard_ConstructionError if MajorRadius or
-- MinorRadius is negative.
is static;
SetAxis (me : in out; A : Ax22d) is static;
---C++: inline
--- Purpose : Modifies this hyperbola, by redefining its local
-- coordinate system so that it becomes A.
SetXAxis (me : in out; A : Ax2d) is static;
---C++: inline
--- Purpose :
-- Changes the major axis of the hyperbola. The minor axis is
-- recomputed and the location of the hyperbola too.
SetYAxis (me : in out; A : Ax2d) is static;
---C++: inline
--- Purpose :
-- Changes the minor axis of the hyperbola.The minor axis is
-- recomputed and the location of the hyperbola too.
Asymptote1 (me) returns Ax2d
---C++: inline
--- Purpose :
-- In the local coordinate system of the hyperbola the equation of
-- the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the
-- equation of the first asymptote is Y = (B/A)*X
-- where A is the major radius of the hyperbola and B the minor
-- radius of the hyperbola.
-- Raises ConstructionError if MajorRadius = 0.0
raises ConstructionError
is static;
Asymptote2 (me) returns Ax2d
---C++: inline
--- Purpose :
-- In the local coordinate system of the hyperbola the equation of
-- the hyperbola is (X*X)/(A*A) - (Y*Y)/(B*B) = 1.0 and the
-- equation of the first asymptote is Y = -(B/A)*X
-- where A is the major radius of the hyperbola and B the minor
-- radius of the hyperbola.
-- Raises ConstructionError if MajorRadius = 0.0
raises ConstructionError
is static;
Coefficients (me; A, B, C, D, E, F : out Real) is static;
--- Purpose :
-- Computes the coefficients of the implicit equation of
-- the hyperbola :
-- A * (X**2) + B * (Y**2) + 2*C*(X*Y) + 2*D*X + 2*E*Y + F = 0.
ConjugateBranch1 (me) returns Hypr2d is static;
---C++: inline
--- Purpose :
-- Computes the branch of hyperbola which is on the positive side of the
-- "YAxis" of <me>.
ConjugateBranch2 (me) returns Hypr2d is static;
---C++: inline
--- Purpose :
-- Computes the branch of hyperbola which is on the negative side of the
-- "YAxis" of <me>.
Directrix1 (me) returns Ax2d is static;
---C++: inline
--- Purpose :
-- Computes the directrix which is the line normal to the XAxis of the hyperbola
-- in the local plane (Z = 0) at a distance d = MajorRadius / e
-- from the center of the hyperbola, where e is the eccentricity of
-- the hyperbola.
-- This line is parallel to the "YAxis". The intersection point
-- between the "Directrix1" and the "XAxis" is the "Location" point
-- of the "Directrix1".
-- This point is on the positive side of the "XAxis".
Directrix2 (me) returns Ax2d is static;
---C++: inline
--- Purpose :
-- This line is obtained by the symmetrical transformation
-- of "Directrix1" with respect to the "YAxis" of the hyperbola.
Eccentricity (me) returns Real
---C++: inline
--- Purpose :
-- Returns the excentricity of the hyperbola (e > 1).
-- If f is the distance between the location of the hyperbola
-- and the Focus1 then the eccentricity e = f / MajorRadius. Raises DomainError if MajorRadius = 0.0.
raises DomainError
is static;
Focal (me) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the focal distance. It is the distance between the
-- "Location" of the hyperbola and "Focus1" or "Focus2".
Focus1 (me) returns Pnt2d is static;
---C++: inline
--- Purpose :
-- Returns the first focus of the hyperbola. This focus is on the
-- positive side of the "XAxis" of the hyperbola.
Focus2 (me) returns Pnt2d is static;
---C++: inline
--- Purpose :
-- Returns the second focus of the hyperbola. This focus is on the
-- negative side of the "XAxis" of the hyperbola.
Location (me) returns Pnt2d is static;
---C++: inline
--- Purpose :
-- Returns the location point of the hyperbola.
-- It is the intersection point between the "XAxis" and
-- the "YAxis".
---C++: return const&
MajorRadius (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the major radius of the hyperbola (it is the radius
-- corresponding to the "XAxis" of the hyperbola).
MinorRadius (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the minor radius of the hyperbola (it is the radius
-- corresponding to the "YAxis" of the hyperbola).
OtherBranch (me) returns Hypr2d is static;
---C++: inline
--- Purpose :
-- Returns the branch of hyperbola obtained by doing the
-- symmetrical transformation of <me> with respect to the
-- "YAxis" of <me>.
Parameter (me) returns Real
---C++: inline
--- Purpose :
-- Returns p = (e * e - 1) * MajorRadius where e is the
-- eccentricity of the hyperbola.
-- Raises DomainError if MajorRadius = 0.0
raises DomainError
is static;
Axis (me) returns Ax22d is static;
--- Purpose : Returns the axisplacement of the hyperbola.
---C++: inline
---C++: return const&
XAxis (me) returns Ax2d is static;
--- Purpose : Computes an axis whose
-- - the origin is the center of this hyperbola, and
-- - the unit vector is the "X Direction" or "Y Direction"
-- respectively of the local coordinate system of this hyperbola
-- Returns the major axis of the hyperbola.
YAxis (me) returns Ax2d is static;
---C++: inline
--- Purpose : Computes an axis whose
-- - the origin is the center of this hyperbola, and
-- - the unit vector is the "X Direction" or "Y Direction"
-- respectively of the local coordinate system of this hyperbola
-- Returns the minor axis of the hyperbola.
Reverse (me : in out) is static;
---C++: inline
Reversed (me) returns Hypr2d is static;
---C++: inline
---Purpose: Reverses the orientation of the local coordinate system
-- of this hyperbola (the "Y Axis" is reversed). Therefore,
-- the implicit orientation of this hyperbola is reversed.
-- Note:
-- - Reverse assigns the result to this hyperbola, while
-- - Reversed creates a new one.
IsDirect (me) returns Boolean is static;
---C++: inline
--- Purpose : Returns true if the local coordinate system is direct
-- and false in the other case.
Mirror (me : in out; P : Pnt2d) is static;
Mirrored (me; P : Pnt2d) returns Hypr2d is static;
--- Purpose :
-- Performs the symmetrical transformation of an hyperbola with
-- respect to the point P which is the center of the symmetry.
Mirror (me : in out; A : Ax2d) is static;
Mirrored (me; A : Ax2d) returns Hypr2d is static;
--- Purpose :
-- Performs the symmetrical transformation of an hyperbola with
-- respect to an axis placement which is the axis of the symmetry.
Rotate (me : in out; P : Pnt2d; Ang : Real) is static;
---C++: inline
Rotated (me; P : Pnt2d; Ang : Real) returns Hypr2d is static;
---C++: inline
--- Purpose :
-- Rotates an hyperbola. P is the center of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt2d; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt2d; S : Real) returns Hypr2d is static;
---C++: inline
--- Purpose :
-- Scales an hyperbola. <S> is the scaling value.
-- If <S> is positive only the location point is
-- modified. But if <S> is negative the "XAxis" is
-- reversed and the "YAxis" too.
Transform (me : in out; T : Trsf2d) is static;
---C++: inline
Transformed (me; T : Trsf2d) returns Hypr2d is static;
---C++: inline
--- Purpose :
-- Transforms an hyperbola with the transformation T from
-- class Trsf2d.
Translate (me : in out; V : Vec2d) is static;
---C++: inline
Translated (me; V : Vec2d) returns Hypr2d is static;
---C++: inline
--- Purpose :
-- Translates an hyperbola in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt2d) is static;
---C++: inline
Translated (me; P1, P2 : Pnt2d) returns Hypr2d is static;
---C++: inline
--- Purpose :
-- Translates an hyperbola from the point P1 to the point P2.
fields
pos : Ax22d;
majorRadius : Real;
minorRadius : Real;
end;

62
src/gp/gp_Hypr2d.cxx Executable file
View File

@@ -0,0 +1,62 @@
//File gp_Hypr2d.cxx JCV 10/01/91
#define No_Standard_OutOfRange
#include <gp_Hypr2d.ixx>
void gp_Hypr2d::Coefficients (Standard_Real& A,
Standard_Real& B,
Standard_Real& C,
Standard_Real& D,
Standard_Real& E,
Standard_Real& F) const
{
Standard_Real DMin = minorRadius * minorRadius;
Standard_Real DMaj = majorRadius * majorRadius;
if (DMin <= gp::Resolution() && DMaj <= gp::Resolution()) {
A = B = C = D = E = F = 0.0;
}
else {
gp_Trsf2d T;
T.SetTransformation (pos.XAxis());
Standard_Real T11 = T.Value (1, 1);
Standard_Real T12 = T.Value (1, 2);
Standard_Real T13 = T.Value (1, 3);
if (DMin <= gp::Resolution()) {
A = T11 * T11; B = T12 * T12; C = T11 * T12;
D = T11 * T13; E = T12 * T13; F = T13 * T13 - DMaj;
}
else {
Standard_Real T21 = T.Value (2, 1);
Standard_Real T22 = T.Value (2, 2);
Standard_Real T23 = T.Value (2, 3);
A = (T11 * T11 / DMaj) - (T21 * T21 / DMin);
B = (T12 * T12 / DMaj) - (T22 * T22 / DMin);
C = (T11 * T12 / DMaj) - (T21 * T22 / DMin);
D = (T11 * T13 / DMaj) - (T21 * T23 / DMin);
E = (T12 * T13 / DMaj) - (T22 * T23 / DMin);
F = (T13 * T13 / DMaj) - (T23 * T23 / DMin) - 1.0;
}
}
}
void gp_Hypr2d::Mirror (const gp_Pnt2d& P)
{ pos.Mirror(P); }
gp_Hypr2d gp_Hypr2d::Mirrored (const gp_Pnt2d& P) const
{
gp_Hypr2d H = *this;
H.pos.Mirror (P);
return H;
}
void gp_Hypr2d::Mirror (const gp_Ax2d& A)
{ pos.Mirror(A); }
gp_Hypr2d gp_Hypr2d::Mirrored (const gp_Ax2d& A) const
{
gp_Hypr2d H = *this;
H.pos.Mirror (A);
return H;
}

269
src/gp/gp_Hypr2d.lxx Executable file
View File

@@ -0,0 +1,269 @@
//File gp_Hypr2d.lxx
// LPA et JCV 07/92 mise a jour des methodes inline pour passage sur C1
#include <gp.hxx>
#include <Standard_DomainError.hxx>
#include <Standard_ConstructionError.hxx>
inline gp_Hypr2d::gp_Hypr2d () :
majorRadius(RealLast()),
minorRadius(RealLast())
{ }
inline gp_Hypr2d::gp_Hypr2d (const gp_Ax22d& A,
const Standard_Real MajorRadius,
const Standard_Real MinorRadius) :
pos(A),
majorRadius(MajorRadius),
minorRadius(MinorRadius)
{
Standard_ConstructionError_Raise_if
(MinorRadius < 0.0 || MajorRadius < 0.0,"");
}
inline gp_Hypr2d::gp_Hypr2d (const gp_Ax2d& MajorAxis,
const Standard_Real MajorRadius,
const Standard_Real MinorRadius,
const Standard_Boolean Sense) :
majorRadius(MajorRadius),
minorRadius(MinorRadius)
{
pos = gp_Ax22d(MajorAxis,Sense);
Standard_ConstructionError_Raise_if
(MinorRadius < 0.0 || MajorRadius < 0.0,"");
}
inline void gp_Hypr2d::SetLocation (const gp_Pnt2d& P)
{ pos.SetLocation (P); }
inline void gp_Hypr2d::SetMajorRadius (const Standard_Real MajorRadius)
{
Standard_ConstructionError_Raise_if(MajorRadius < 0.0,"");
majorRadius = MajorRadius;
}
inline void gp_Hypr2d::SetMinorRadius (const Standard_Real MinorRadius)
{
Standard_ConstructionError_Raise_if(MinorRadius < 0.0,"");
minorRadius = MinorRadius;
}
inline void gp_Hypr2d::SetAxis (const gp_Ax22d& A)
{ pos.SetAxis(A); }
inline void gp_Hypr2d::SetXAxis (const gp_Ax2d& A)
{ pos.SetXAxis(A); }
inline void gp_Hypr2d::SetYAxis (const gp_Ax2d& A)
{ pos.SetYAxis(A); }
inline gp_Ax2d gp_Hypr2d::Asymptote1() const
{
Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), "");
gp_Dir2d Vdir = pos.XDirection();
gp_XY Coord1 (pos.YDirection().XY());
gp_XY Coord2 = Coord1.Multiplied (minorRadius / majorRadius);
Coord1.Add (Coord2);
Vdir.SetXY (Coord1);
return gp_Ax2d (pos.Location(), Vdir);
}
inline gp_Ax2d gp_Hypr2d::Asymptote2() const {
Standard_ConstructionError_Raise_if (majorRadius <= gp::Resolution(), "");
gp_Vec2d Vdir = pos.XDirection();
gp_XY Coord1 (pos.YDirection().XY());
gp_XY Coord2 = Coord1.Multiplied (-minorRadius / majorRadius);
Coord1.Add (Coord2);
Vdir.SetXY (Coord1);
return gp_Ax2d (pos.Location(), Vdir);
}
inline gp_Hypr2d gp_Hypr2d::ConjugateBranch1() const
{
gp_Dir2d V (pos.YDirection());
Standard_Boolean sign = (pos.XDirection().Crossed(pos.YDirection())) >= 0.0;
return gp_Hypr2d (gp_Ax2d (pos.Location(),V), minorRadius, majorRadius,sign);
}
inline gp_Hypr2d gp_Hypr2d::ConjugateBranch2() const
{
gp_Dir2d V (pos.YDirection().Reversed());
Standard_Boolean sign = (pos.XDirection().Crossed(pos.YDirection())) >= 0.0;
return gp_Hypr2d (gp_Ax2d(pos.Location(),V),minorRadius, majorRadius,sign);
}
inline gp_Ax2d gp_Hypr2d::Directrix1() const
{
Standard_Real E = Eccentricity();
gp_XY Orig = pos.XDirection().XY();
Orig.Multiply (majorRadius/E);
Orig.Add (pos.Location().XY());
return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection()));
}
inline gp_Ax2d gp_Hypr2d::Directrix2() const
{
Standard_Real E = Eccentricity();
gp_XY Orig = pos.XDirection().XY();
Orig.Multiply (Parameter()/E);
Orig.Add (Focus1().XY());
return gp_Ax2d (gp_Pnt2d(Orig),gp_Dir2d (pos.YDirection()));
}
inline Standard_Real gp_Hypr2d::Eccentricity() const
{
Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), "");
return sqrt(majorRadius * majorRadius +
minorRadius * minorRadius) / majorRadius;
}
inline Standard_Real gp_Hypr2d::Focal() const
{
return 2.0 * sqrt (majorRadius * majorRadius +
minorRadius * minorRadius);
}
inline gp_Pnt2d gp_Hypr2d::Focus1() const
{
Standard_Real C = sqrt (majorRadius * majorRadius +
minorRadius * minorRadius);
return gp_Pnt2d (pos.Location().X() + C * pos.XDirection().X(),
pos.Location().Y() + C * pos.XDirection().Y());
}
inline gp_Pnt2d gp_Hypr2d::Focus2() const
{
Standard_Real C = sqrt (majorRadius * majorRadius +
minorRadius * minorRadius);
return gp_Pnt2d (pos.Location().X() - C * pos.XDirection().X(),
pos.Location().Y() - C * pos.XDirection().Y());
}
inline const gp_Pnt2d& gp_Hypr2d::Location () const
{ return pos.Location(); }
inline Standard_Real gp_Hypr2d::MajorRadius() const
{ return majorRadius; }
inline Standard_Real gp_Hypr2d::MinorRadius() const
{ return minorRadius; }
inline gp_Hypr2d gp_Hypr2d::OtherBranch() const
{
Standard_Boolean sign = (pos.XDirection().Crossed(pos.YDirection())) >= 0.0;
return gp_Hypr2d (gp_Ax2d (pos.Location(),pos.XDirection().Reversed()),
majorRadius,minorRadius,sign);
}
inline Standard_Real gp_Hypr2d::Parameter() const
{
Standard_DomainError_Raise_if (majorRadius <= gp::Resolution(), "");
return (minorRadius * minorRadius) / majorRadius;
}
inline const gp_Ax22d& gp_Hypr2d::Axis () const
{ return pos; }
inline gp_Ax2d gp_Hypr2d::XAxis () const
{ return pos.XAxis(); }
inline gp_Ax2d gp_Hypr2d::YAxis () const
{ return pos.YAxis(); }
inline void gp_Hypr2d::Reverse()
{
gp_Dir2d Temp = pos.YDirection ();
Temp.Reverse ();
pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp));
}
inline gp_Hypr2d gp_Hypr2d::Reversed() const
{
gp_Hypr2d H = *this;
gp_Dir2d Temp = pos.YDirection ();
Temp.Reverse ();
H.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp));
return H;
}
inline Standard_Boolean gp_Hypr2d::IsDirect() const
{ return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; }
inline void gp_Hypr2d::Rotate (const gp_Pnt2d& P,
const Standard_Real Ang)
{pos.Rotate (P,Ang);}
inline gp_Hypr2d gp_Hypr2d::Rotated (const gp_Pnt2d& P,
const Standard_Real Ang) const
{
gp_Hypr2d H = *this;
H.pos.Rotate (P, Ang);
return H;
}
inline void gp_Hypr2d::Scale (const gp_Pnt2d& P,
const Standard_Real S)
{
majorRadius *= S;
if (majorRadius < 0) majorRadius = - majorRadius;
minorRadius *= S;
if (minorRadius < 0) minorRadius = - minorRadius;
pos.Scale(P, S);
}
inline gp_Hypr2d gp_Hypr2d::Scaled (const gp_Pnt2d& P,
const Standard_Real S) const
{
gp_Hypr2d H = *this;
H.majorRadius *= S;
if (H.majorRadius < 0) H.majorRadius = - H.majorRadius;
H.minorRadius *= S;
if (H.minorRadius < 0) H.minorRadius = - H.minorRadius;
H.pos.Scale(P, S);
return H;
}
inline void gp_Hypr2d::Transform (const gp_Trsf2d& T)
{
majorRadius *= T.ScaleFactor();
if (majorRadius < 0) majorRadius = - majorRadius;
minorRadius *= T.ScaleFactor();
if (minorRadius < 0) minorRadius = - minorRadius;
pos.Transform(T);
}
inline gp_Hypr2d gp_Hypr2d::Transformed (const gp_Trsf2d& T) const
{
gp_Hypr2d H = *this;
H.majorRadius *= T.ScaleFactor();
if (H.majorRadius < 0) H.majorRadius = - H.majorRadius;
H.minorRadius *= T.ScaleFactor();
if (H.minorRadius < 0) H.minorRadius = - H.minorRadius;
H.pos.Transform(T);
return H;
}
inline void gp_Hypr2d::Translate (const gp_Vec2d& V)
{ pos.Translate(V); }
inline gp_Hypr2d gp_Hypr2d::Translated (const gp_Vec2d& V) const
{
gp_Hypr2d H = *this;
H.pos.Translate(V);
return H;
}
inline void gp_Hypr2d::Translate (const gp_Pnt2d& P1,
const gp_Pnt2d& P2)
{
pos.Translate(P1, P2);
}
inline gp_Hypr2d gp_Hypr2d::Translated (const gp_Pnt2d& P1,
const gp_Pnt2d& P2) const
{
gp_Hypr2d H = *this;
H.pos.Translate(P1, P2);
return H;
}

242
src/gp/gp_Lin.cdl Executable file
View File

@@ -0,0 +1,242 @@
---Copyright: Matra Datavision 1991, 1992
class Lin from gp inherits Storable
---Purpose:
-- Describes a line in 3D space.
-- A line is positioned in space with an axis (a gp_Ax1
-- object) which gives it an origin and a unit vector.
-- A line and an axis are similar objects, thus, we can
-- convert one into the other. A line provides direct access
-- to the majority of the edit and query functions available
-- on its positioning axis. In addition, however, a line has
-- specific functions for computing distances and positions.
-- See Also
-- gce_MakeLin which provides functions for more complex
-- line constructions
-- Geom_Line which provides additional functions for
-- constructing lines and works, in particular, with the
-- parametric equations of lines
uses Ax1 from gp,
Ax2 from gp,
Dir from gp,
Trsf from gp,
Vec from gp,
Pnt from gp
raises ConstructionError from Standard
is
Create returns Lin;
---C++:inline
--- Purpose : Creates a Line corresponding to Z axis of the
-- reference coordinate system.
Create (A1 : Ax1) returns Lin;
---C++:inline
--- Purpose : Creates a line defined by axis A1.
Create (P : Pnt; V : Dir) returns Lin;
--- Purpose : Creates a line passing through point P and parallel to
-- vector V (P and V are, respectively, the origin and
-- the unit vector of the positioning axis of the line).
Reverse (me : in out)
---C++:inline
is static;
Reversed (me) returns Lin is static;
---C++:inline
--- Purpose : Reverses the direction of the line.
-- Note:
-- - Reverse assigns the result to this line, while
-- - Reversed creates a new one.
SetDirection (me : in out; V : Dir) is static;
---C++:inline
--- Purpose : Changes the direction of the line.
SetLocation (me : in out; P : Pnt) is static;
---C++:inline
--- Purpose : Changes the location point (origin) of the line.
SetPosition (me : in out; A1 : Ax1) is static;
---C++:inline
--- Purpose :
-- Complete redefinition of the line.
-- The "Location" point of <A1> is the origin of the line.
-- The "Direction" of <A1> is the direction of the line.
Direction (me) returns Dir is static;
---C++:inline
--- Purpose : Returns the direction of the line.
---C++: return const&
Location (me) returns Pnt is static;
---C++:inline
--- Purpose :
-- Returns the location point (origin) of the line.
---C++: return const&
Position (me) returns Ax1 is static;
--- Purpose :
-- Returns the axis placement one axis whith the same
-- location and direction as <me>.
---C++: inline
---C++: return const&
Angle (me; Other : Lin) returns Real is static;
---C++: inline
--- Purpose : Computes the angle between two lines in radians.
Contains (me; P : Pnt; LinearTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose : Returns true if this line contains the point P, that is, if the
-- distance between point P and this line is less than or
-- equal to LinearTolerance..
Distance (me; P : Pnt) returns Real is static;
---C++: inline
--- Purpose : Computes the distance between <me> and the point P.
Distance (me; Other : Lin) returns Real is static;
--- Purpose : Computes the distance between two lines.
SquareDistance (me; P : Pnt) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the square distance between <me> and the point P.
SquareDistance (me; Other : Lin) returns Real is static;
---C++: inline
--- Purpose : Computes the square distance between two lines.
Normal (me; P : Pnt) returns Lin
---C++: inline
--- Purpose :
-- Computes the line normal to the direction of <me>, passing
-- through the point P. Raises ConstructionError
-- if the distance between <me> and the point P is lower
-- or equal to Resolution from gp because there is an infinity of
-- solutions in 3D space.
raises ConstructionError
is static;
Mirror (me : in out; P : Pnt)
is static;
Mirrored (me; P : Pnt) returns Lin
is static;
--- Purpose :
-- Performs the symmetrical transformation of a line
-- with respect to the point P which is the center of
-- the symmetry.
Mirror (me : in out; A1 : Ax1)
is static;
Mirrored (me; A1 : Ax1) returns Lin is static;
--- Purpose :
-- Performs the symmetrical transformation of a line
-- with respect to an axis placement which is the axis
-- of the symmetry.
Mirror (me : in out; A2 : Ax2)
is static;
Mirrored (me; A2 : Ax2) returns Lin is static;
--- Purpose :
-- Performs the symmetrical transformation of a line
-- with respect to a plane. The axis placement <A2>
-- locates the plane of the symmetry :
-- (Location, XDirection, YDirection).
Rotate(me : in out; A1 : Ax1; Ang : Real)
---C++: inline
is static;
Rotated (me; A1 : Ax1; Ang : Real) returns Lin is static;
---C++: inline
--- Purpose :
-- Rotates a line. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real)
---C++: inline
is static;
Scaled (me; P : Pnt; S : Real) returns Lin is static;
---C++: inline
--- Purpose :
-- Scales a line. S is the scaling value.
-- The "Location" point (origin) of the line is modified.
-- The "Direction" is reversed if the scale is negative.
Transform (me : in out; T : Trsf)
---C++: inline
is static;
Transformed (me; T : Trsf) returns Lin is static;
---C++: inline
--- Purpose :
-- Transforms a line with the transformation T from class Trsf.
Translate (me : in out; V : Vec)
---C++: inline
is static;
Translated (me; V : Vec) returns Lin is static;
---C++: inline
--- Purpose :
-- Translates a line in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt) is static;
---C++: inline
Translated (me; P1, P2 : Pnt) returns Lin is static;
---C++: inline
--- Purpose :
-- Translates a line from the point P1 to the point P2.
fields
pos : Ax1;
end;

51
src/gp/gp_Lin.cxx Executable file
View File

@@ -0,0 +1,51 @@
// File gp_Lin.cxx, JCV O3/06/90
// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
// JCV 1/10/90 Changement de nom du package vgeom -> gp
// JCV 12/12/90 modifs suite a la premiere revue de projet
#include <gp_Lin.ixx>
Standard_Real gp_Lin::Distance (const gp_Lin& Other) const
{
if (pos.IsParallel (Other.pos, gp::Resolution())) {
return Other.Distance(pos.Location());
}
else {
gp_Dir dir(pos.Direction().Crossed(Other.pos.Direction()));
Standard_Real D = gp_Vec (pos.Location(),Other.pos.Location())
.Dot(gp_Vec(dir));
if (D < 0) D = - D;
return D;
}
}
void gp_Lin::Mirror (const gp_Pnt& P)
{ pos.Mirror(P); }
gp_Lin gp_Lin::Mirrored (const gp_Pnt& P) const
{
gp_Lin L = *this;
L.pos.Mirror (P);
return L;
}
void gp_Lin::Mirror (const gp_Ax1& A1)
{ pos.Mirror(A1); }
gp_Lin gp_Lin::Mirrored (const gp_Ax1& A1) const
{
gp_Lin L = *this;
L.pos.Mirror (A1);
return L;
}
void gp_Lin::Mirror (const gp_Ax2& A2)
{ pos.Mirror(A2); }
gp_Lin gp_Lin::Mirrored (const gp_Ax2& A2) const
{
gp_Lin L = *this;
L.pos.Mirror (A2);
return L;
}

137
src/gp/gp_Lin.lxx Executable file
View File

@@ -0,0 +1,137 @@
// File gp_Lin.lxx , JCV 03/06/90
// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
inline gp_Lin::gp_Lin ()
{ }
inline gp_Lin::gp_Lin (const gp_Ax1& A1) : pos (A1)
{ }
inline gp_Lin::gp_Lin (const gp_Pnt& P,
const gp_Dir& V) : pos (P, V)
{ }
inline void gp_Lin::Reverse()
{ pos.Reverse(); }
inline gp_Lin gp_Lin::Reversed() const {
gp_Lin L = *this;
L.pos.Reverse();
return L;
}
inline void gp_Lin::SetDirection (const gp_Dir& V)
{ pos.SetDirection(V); }
inline void gp_Lin::SetLocation (const gp_Pnt& P)
{ pos.SetLocation(P); }
inline void gp_Lin::SetPosition (const gp_Ax1& A1)
{ pos = A1; }
inline const gp_Dir& gp_Lin::Direction() const
{ return pos.Direction(); }
inline const gp_Pnt& gp_Lin::Location() const
{ return pos.Location(); }
inline const gp_Ax1& gp_Lin::Position() const
{ return pos; }
inline Standard_Real gp_Lin::Angle (const gp_Lin& Other) const
{ return pos.Direction().Angle (Other.pos.Direction()); }
inline Standard_Boolean gp_Lin::Contains
(const gp_Pnt& P,
const Standard_Real LinearTolerance) const
{ return Distance(P) <= LinearTolerance; }
inline Standard_Real gp_Lin::Distance (const gp_Pnt& P) const {
gp_XYZ Coord = P.XYZ();
Coord.Subtract ((pos.Location()).XYZ());
Coord.Cross ((pos.Direction()).XYZ());
return Coord.Modulus();
}
inline Standard_Real gp_Lin::SquareDistance (const gp_Pnt& P) const
{
const gp_Pnt& Loc = pos.Location();
gp_Vec V (P.X() - Loc.X(),
P.Y() - Loc.Y(),
P.Z() - Loc.Z());
V.Cross (pos.Direction());
return V.SquareMagnitude ();
}
inline Standard_Real gp_Lin::SquareDistance (const gp_Lin& Other) const
{
Standard_Real D = Distance (Other);
return D * D;
}
inline gp_Lin gp_Lin::Normal (const gp_Pnt& P) const
{
const gp_Pnt& Loc = pos.Location();
gp_Dir V (P.X() - Loc.X(),
P.Y() - Loc.Y(),
P.Z() - Loc.Z());
V = pos.Direction().CrossCrossed(V, pos.Direction());
return gp_Lin (P, V);
}
inline void gp_Lin::Rotate (const gp_Ax1& A1,
const Standard_Real Ang)
{ pos.Rotate(A1, Ang); }
inline gp_Lin gp_Lin::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Lin L = *this;
L.pos.Rotate (A1, Ang);
return L;
}
inline void gp_Lin::Scale (const gp_Pnt& P,
const Standard_Real S)
{ pos.Scale(P, S); }
inline gp_Lin gp_Lin::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Lin L = *this;
L.pos.Scale (P, S);
return L;
}
inline void gp_Lin::Transform (const gp_Trsf& T)
{ pos.Transform(T); }
inline gp_Lin gp_Lin::Transformed (const gp_Trsf& T) const
{
gp_Lin L = *this;
L.pos.Transform (T);
return L;
}
inline void gp_Lin::Translate (const gp_Vec& V)
{ pos.Translate(V); }
inline gp_Lin gp_Lin::Translated (const gp_Vec& V) const
{
gp_Lin L = *this;
L.pos.Translate (V);
return L;
}
inline void gp_Lin::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{pos.Translate (P1, P2);}
inline gp_Lin gp_Lin::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Lin L = *this;
L.pos.Translate (gp_Vec(P1, P2));
return L;
}

244
src/gp/gp_Lin2d.cdl Executable file
View File

@@ -0,0 +1,244 @@
---Copyright: Matra Datavision 1991, 1992
class Lin2d from gp inherits Storable
---Purpose: Describes a line in 2D space.
-- A line is positioned in the plane with an axis (a gp_Ax2d
-- object) which gives the line its origin and unit vector. A
-- line and an axis are similar objects, thus, we can convert
-- one into the other.
-- A line provides direct access to the majority of the edit
-- and query functions available on its positioning axis. In
-- addition, however, a line has specific functions for
-- computing distances and positions.
-- See Also
-- GccAna and Geom2dGcc packages which provide
-- functions for constructing lines defined by geometric
-- constraints
-- gce_MakeLin2d which provides functions for more
-- complex line constructions
-- Geom2d_Line which provides additional functions for
-- constructing lines and works, in particular, with the
-- parametric equations of lines
uses Ax2d from gp,
Dir2d from gp,
Pnt2d from gp,
Trsf2d from gp,
Vec2d from gp
raises ConstructionError from Standard
is
Create returns Lin2d;
---C++:inline
--- Purpose : Creates a Line corresponding to X axis of the
-- reference coordinate system.
Create (A : Ax2d) returns Lin2d;
---C++:inline
--- Purpose : Creates a line located with A.
Create (P : Pnt2d; V : Dir2d) returns Lin2d;
---C++:inline
--- Purpose :
-- <P> is the location point (origin) of the line and
-- <V> is the direction of the line.
Create (A, B, C : Real) returns Lin2d
--- Purpose :
-- Creates the line from the equation A*X + B*Y + C = 0.0 Raises ConstructionError if Sqrt(A*A + B*B) <= Resolution from gp.
raises ConstructionError;
--- Purpose : Raised if Sqrt(A*A + B*B) <= Resolution from gp.
Reverse (me : in out)
---C++:inline
is static;
Reversed (me) returns Lin2d is static;
---C++:inline
---Purpose:
-- Reverses the positioning axis of this line.
-- Note:
-- - Reverse assigns the result to this line, while
-- - Reversed creates a new one.
SetDirection (me : in out; V : Dir2d)
---C++:inline
is static;
--- Purpose : Changes the direction of the line.
SetLocation(me : in out; P : Pnt2d)
---C++:inline
is static;
--- Purpose : Changes the origin of the line.
SetPosition (me : in out; A : Ax2d) is static;
---C++:inline
--- Purpose :
-- Complete redefinition of the line.
-- The "Location" point of <A> is the origin of the line.
-- The "Direction" of <A> is the direction of the line.
Coefficients (me; A, B, C : out Real) is static;
---C++:inline
--- Purpose :
-- Returns the normalized coefficients of the line :
-- A * X + B * Y + C = 0.
Direction (me) returns Dir2d is static;
---C++:inline
--- Purpose : Returns the direction of the line.
---C++: return const&
Location (me) returns Pnt2d is static;
---C++:inline
--- Purpose : Returns the location point (origin) of the line.
---C++: return const&
Position (me) returns Ax2d is static;
--- Purpose :
-- Returns the axis placement one axis whith the same
-- location and direction as <me>.
---C++: inline
---C++: return const&
Angle (me; Other : Lin2d) returns Real is static;
---C++: inline
--- Purpose : Computes the angle between two lines in radians.
Contains (me; P : Pnt2d; LinearTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose : Returns true if this line contains the point P, that is, if the
-- distance between point P and this line is less than or
-- equal to LinearTolerance.
Distance (me; P : Pnt2d) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the distance between <me> and the point <P>.
Distance (me; Other : Lin2d) returns Real is static;
---C++: inline
--- Purpose : Computes the distance between two lines.
SquareDistance (me; P : Pnt2d) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the square distance between <me> and the point
-- <P>.
SquareDistance (me; Other : Lin2d) returns Real is static;
---C++: inline
--- Purpose : Computes the square distance between two lines.
Normal (me; P : Pnt2d) returns Lin2d is static;
---C++: inline
--- Purpose :
-- Computes the line normal to the direction of <me>,
-- passing through the point <P>.
Mirror (me : in out; P : Pnt2d)
is static;
Mirrored (me; P : Pnt2d) returns Lin2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a line
-- with respect to the point <P> which is the center
-- of the symmetry
Mirror (me : in out; A : Ax2d)
is static;
Mirrored (me; A : Ax2d) returns Lin2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a line
-- with respect to an axis placement which is the axis
-- of the symmetry.
Rotate(me : in out; P : Pnt2d; Ang : Real)
---C++:inline
is static;
Rotated (me; P : Pnt2d; Ang : Real) returns Lin2d is static;
---C++:inline
--- Purpose :
-- Rotates a line. P is the center of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt2d; S : Real)
is static;
Scaled (me; P : Pnt2d; S : Real) returns Lin2d is static;
---C++:inline
--- Purpose :
-- Scales a line. S is the scaling value. Only the
-- origin of the line is modified.
Transform (me : in out; T : Trsf2d)
---C++:inline
is static;
Transformed (me; T : Trsf2d) returns Lin2d is static;
---C++:inline
--- Purpose :
-- Transforms a line with the transformation T from class Trsf2d.
Translate (me : in out; V : Vec2d)
---C++:inline
is static;
Translated (me; V : Vec2d) returns Lin2d is static;
---C++:inline
--- Purpose :
-- Translates a line in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt2d) is static;
---C++:inline
Translated (me; P1, P2 : Pnt2d) returns Lin2d is static;
---C++:inline
--- Purpose :
-- Translates a line from the point P1 to the point P2.
fields
pos : Ax2d;
end;

79
src/gp/gp_Lin2d.cxx Executable file
View File

@@ -0,0 +1,79 @@
// File gp_Lin2d.cxx, JCV O3/04/90
// File gp_Lin2d.cxx, FID 30/06/90 reprise complete
// JCV 10/01/91 modifs suite a la deuxieme revue de projet
// AGV 03/04/07 bug correction: "pos" origin too far when A is very small
#define No_Standard_OutOfRange
#include <gp_Lin2d.ixx>
#include <gp.hxx>
//=======================================================================
//function : gp_Lin2d
//purpose :
//=======================================================================
gp_Lin2d::gp_Lin2d (const Standard_Real A,
const Standard_Real B,
const Standard_Real C)
{
const Standard_Real Norm2 = A * A + B * B;
Standard_ConstructionError_Raise_if (Norm2 <= gp::Resolution(), " ");
const gp_Pnt2d P (-A*C/Norm2, -B*C/Norm2);
const gp_Dir2d V (-B, A);
// gp_Pnt2d P;
// Standard_Real Norm = sqrt(A * A + B * B);
// Standard_ConstructionError_Raise_if (Norm <= gp::Resolution(), " ");
// Standard_Real A1 = A/Norm;
// Standard_Real B1 = B/Norm;
// Standard_Real C1 = C/Norm;
// gp_Dir2d V = gp_Dir2d (-B1, A1);
// Standard_Real AA1 = A1;
// if (AA1 < 0) AA1 = - AA1;
// if (AA1 > gp::Resolution()) P.SetCoord (-C1 / A1, 0.0);
// else P.SetCoord (0.0, -C1 / B1);
pos = gp_Ax2d(P, V);
}
//=======================================================================
//function : Mirror
//purpose :
//=======================================================================
void gp_Lin2d::Mirror (const gp_Pnt2d& P)
{ pos.Mirror(P); }
//=======================================================================
//function : Mirrored
//purpose :
//=======================================================================
gp_Lin2d gp_Lin2d::Mirrored (const gp_Pnt2d& P) const
{
gp_Lin2d L = *this;
L.pos.Mirror(P);
return L;
}
//=======================================================================
//function : Mirror
//purpose :
//=======================================================================
void gp_Lin2d::Mirror (const gp_Ax2d& A)
{ pos.Mirror(A); }
//=======================================================================
//function : Mirrored
//purpose :
//=======================================================================
gp_Lin2d gp_Lin2d::Mirrored (const gp_Ax2d& A) const
{
gp_Lin2d L = *this;
L.pos.Mirror(A);
return L;
}

154
src/gp/gp_Lin2d.lxx Executable file
View File

@@ -0,0 +1,154 @@
inline gp_Lin2d::gp_Lin2d ()
{ }
inline gp_Lin2d::gp_Lin2d (const gp_Ax2d& A) : pos(A)
{ }
inline gp_Lin2d::gp_Lin2d (const gp_Pnt2d& P,
const gp_Dir2d& V) : pos(P, V)
{ }
inline void gp_Lin2d::Reverse()
{ pos.Reverse(); }
inline gp_Lin2d gp_Lin2d::Reversed() const
{
gp_Lin2d L = *this;
L.pos.Reverse ();
return L;
}
inline void gp_Lin2d::SetDirection (const gp_Dir2d& V)
{ pos.SetDirection (V); }
inline void gp_Lin2d::SetLocation (const gp_Pnt2d& P)
{ pos.SetLocation (P); }
inline void gp_Lin2d::SetPosition (const gp_Ax2d& A)
{ pos = A; }
inline void gp_Lin2d::Coefficients (Standard_Real& A,
Standard_Real& B,
Standard_Real& C) const
{
A = pos.Direction().Y();
B = - pos.Direction().X();
C = -(A * pos.Location().X() + B * pos.Location().Y());
}
inline const gp_Dir2d& gp_Lin2d::Direction() const
{ return pos.Direction(); }
inline const gp_Pnt2d& gp_Lin2d::Location() const
{ return pos.Location(); }
inline const gp_Ax2d& gp_Lin2d::Position() const
{ return pos; }
inline Standard_Real gp_Lin2d::Angle (const gp_Lin2d& Other) const
{ return pos.Direction().Angle (Other.pos.Direction()); }
inline Standard_Boolean gp_Lin2d::Contains
(const gp_Pnt2d& P,
const Standard_Real LinearTolerance) const
{ return Distance(P) <= LinearTolerance; }
inline Standard_Real gp_Lin2d::Distance (const gp_Pnt2d& P) const
{
gp_XY Coord = P.XY();
Coord.Subtract ((pos.Location()).XY());
Standard_Real val = Coord.Crossed (pos.Direction().XY());
if (val < 0) val = - val;
return val;
}
inline Standard_Real gp_Lin2d::Distance (const gp_Lin2d& Other) const
{
Standard_Real D = 0.0;
if (pos.IsParallel (Other.pos, gp::Resolution()))
D = Other.Distance(pos.Location());
return D;
}
inline Standard_Real gp_Lin2d::SquareDistance (const gp_Pnt2d& P) const
{
gp_XY Coord = P.XY();
Coord.Subtract ((pos.Location()).XY());
Standard_Real D = Coord.Crossed (pos.Direction().XY());
return D * D;
}
inline Standard_Real gp_Lin2d::SquareDistance (const gp_Lin2d& Other) const
{
Standard_Real D = 0.0;
if (pos.IsParallel (Other.pos, gp::Resolution())) {
D = Other.Distance(pos.Location());
D *= D;return D * D;
}
return D;
}
inline gp_Lin2d gp_Lin2d::Normal (const gp_Pnt2d& P) const
{
return gp_Lin2d
(gp_Ax2d
(P,gp_Dir2d
(-(pos.Direction().Y()), pos.Direction().X())));
}
inline void gp_Lin2d::Rotate (const gp_Pnt2d& P, const Standard_Real Ang)
{ pos.Rotate (P, Ang); }
inline gp_Lin2d gp_Lin2d::Rotated (const gp_Pnt2d& P,
const Standard_Real Ang) const
{
gp_Lin2d L = *this;
L.pos.Rotate (P, Ang);
return L;
}
inline void gp_Lin2d::Scale (const gp_Pnt2d& P, const Standard_Real S)
{ pos.Scale(P, S); }
inline gp_Lin2d gp_Lin2d::Scaled (const gp_Pnt2d& P,
const Standard_Real S) const
{
gp_Lin2d L = *this;
L.pos.Scale(P, S);
return L;
}
inline void gp_Lin2d::Transform (const gp_Trsf2d& T)
{ pos.Transform(T); }
inline gp_Lin2d gp_Lin2d::Transformed (const gp_Trsf2d& T) const
{
gp_Lin2d L = *this;
L.pos.Transform(T);
return L;
}
inline void gp_Lin2d::Translate (const gp_Vec2d& V)
{ pos.Translate(V); }
inline gp_Lin2d gp_Lin2d::Translated (const gp_Vec2d& V) const
{
gp_Lin2d L = *this;
L.pos.Translate(V);
return L;
}
inline void gp_Lin2d::Translate (const gp_Pnt2d& P1,
const gp_Pnt2d& P2)
{ pos.Translate(P1, P2); }
inline gp_Lin2d gp_Lin2d::Translated (const gp_Pnt2d& P1,
const gp_Pnt2d& P2) const
{
gp_Lin2d L = *this;
L.pos.Translate (gp_Vec2d(P1, P2));
return L;
}

288
src/gp/gp_Mat.cdl Executable file
View File

@@ -0,0 +1,288 @@
---Copyright: Matra Datavision 1991
class Mat from gp inherits Storable
---Purpose:
-- Describes a three column, three row matrix. This sort of
-- object is used in various vectorial or matrix computations.
uses XYZ from gp,
Address from Standard
raises ConstructionError from Standard,
OutOfRange from Standard
is
Create returns Mat;
--- Purpose : creates a matrix with null coefficients.
---C++: inline
Create(a11,a12,a13,a21,a22,a23,a31,a32,a33: Real from Standard);
---C++: inline
Create (Col1, Col2, Col3 : XYZ) returns Mat;
--- Purpose : Creates a matrix.
-- Col1, Col2, Col3 are the 3 columns of the matrix.
SetCol (me : in out; Col : Integer; Value : XYZ)
--- Purpose : Assigns the three coordinates of Value to the column of index
-- Col of this matrix.
-- Raises OutOfRange if Col < 1 or Col > 3.
raises OutOfRange
is static;
SetCols (me : in out; Col1, Col2, Col3 : XYZ) is static;
--- Purpose : Assigns the number triples Col1, Col2, Col3 to the three
-- columns of this matrix.
SetCross (me : in out; Ref : XYZ) is static;
--- Purpose :
-- Modifies the matrix M so that applying it to any number
-- triple (X, Y, Z) produces the same result as the cross
-- product of Ref and the number triple (X, Y, Z):
-- i.e.: M * {X,Y,Z}t = Ref.Cross({X, Y ,Z})
-- this matrix is anti symmetric. To apply this matrix to the
-- triplet {XYZ} is the same as to do the cross product between the
-- triplet Ref and the triplet {XYZ}.
-- Note: this matrix is anti-symmetric.
SetDiagonal (me : in out; X1, X2, X3 : Real) is static;
---C++: inline
--- Purpose :
-- Modifies the main diagonal of the matrix.
-- <me>.Value (1, 1) = X1
-- <me>.Value (2, 2) = X2
-- <me>.Value (3, 3) = X3
-- The other coefficients of the matrix are not modified.
SetDot (me : in out; Ref : XYZ) is static;
--- Purpose :
-- Modifies this matrix so that applying it to any number
-- triple (X, Y, Z) produces the same result as the scalar
-- product of Ref and the number triple (X, Y, Z):
-- this * (X,Y,Z) = Ref.(X,Y,Z)
-- Note: this matrix is symmetric.
SetIdentity (me : in out) is static;
---C++: inline
--- Purpose : Modifies this matrix so that it represents the Identity matrix.
SetRotation (me : in out; Axis : XYZ; Ang : Real)
--- Purpose :
-- Modifies this matrix so that it represents a rotation. Ang is the angular value in
-- radians and the XYZ axis gives the direction of the
-- rotation.
-- Raises ConstructionError if XYZ.Modulus() <= Resolution()
raises ConstructionError
is static;
SetRow (me : in out; Row : Integer; Value : XYZ)
--- Purpose : Assigns the three coordinates of Value to the row of index
-- Row of this matrix. Raises OutOfRange if Row < 1 or Row > 3.
raises OutOfRange
is static;
SetRows (me : in out; Row1, Row2, Row3 : XYZ) is static;
--- Purpose : Assigns the number triples Row1, Row2, Row3 to the three
-- rows of this matrix.
SetScale (me : in out; S : Real) is static;
---C++: inline
--- Purpose :
-- Modifies the the matrix so that it represents
-- a scaling transformation, where S is the scale factor. :
-- | S 0.0 0.0 |
-- <me> = | 0.0 S 0.0 |
-- | 0.0 0.0 S |
SetValue (me : in out; Row, Col : Integer; Value : Real)
---C++: inline
--- Purpose : Assigns <Value> to the coefficient of row Row, column Col of this matrix.
-- Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 3
raises OutOfRange
is static;
Column (me; Col : Integer) returns XYZ
--- Purpose : Returns the column of Col index.
-- Raises OutOfRange if Col < 1 or Col > 3
raises OutOfRange
is static;
Determinant (me) returns Real is static;
---C++: inline
--- Purpose : Computes the determinant of the matrix.
Diagonal (me) returns XYZ is static;
--- Purpose : Returns the main diagonal of the matrix.
Row (me; Row : Integer) returns XYZ
--- Purpose : returns the row of Row index.
-- Raises OutOfRange if Row < 1 or Row > 3
raises OutOfRange
is static;
Value (me; Row, Col : Integer) returns Real
---C++: inline
---C++: return const &
---C++: alias operator()
--- Purpose : Returns the coefficient of range (Row, Col)
-- Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 3
raises OutOfRange
--
is static;
ChangeValue (me : in out; Row, Col : Integer) returns Real
---C++: inline
---C++: return &
---C++: alias operator()
--- Purpose : Returns the coefficient of range (Row, Col)
-- Raises OutOfRange if Row < 1 or Row > 3 or Col < 1 or Col > 3
raises OutOfRange
--
is static;
IsSingular (me) returns Boolean is static;
---C++: inline
--- Purpose :
-- The Gauss LU decomposition is used to invert the matrix
-- (see Math package) so the matrix is considered as singular if
-- the largest pivot found is lower or equal to Resolution from gp.
Add (me : in out; Other : Mat) is static;
---C++: inline
---C++: alias operator +=
Added (me; Other : Mat) returns Mat is static;
---C++: inline
---C++: alias operator +
--- Purpose : Computes the sum of this matrix and
-- the matrix Other for each coefficient of the matrix :
-- <me>.Coef(i,j) + <Other>.Coef(i,j)
Divide (me : in out; Scalar : Real) is static;
---C++: inline
---C++: alias operator /=
Divided (me; Scalar : Real) returns Mat is static;
---C++: inline
---C++: alias operator /
--- Purpose : Divides all the coefficients of the matrix by Scalar
Invert (me : in out) raises ConstructionError is static;
Inverted (me) returns Mat raises ConstructionError is static;
--- Purpose :
-- Inverses the matrix and raises if the matrix is singular.
-- - Invert assigns the result to this matrix, while
-- - Inverted creates a new one.
-- Warning
-- The Gauss LU decomposition is used to invert the matrix.
-- Consequently, the matrix is considered as singular if the
-- largest pivot found is less than or equal to gp::Resolution().
-- Exceptions
-- Standard_ConstructionError if this matrix is singular,
-- and therefore cannot be inverted.
Multiplied (me; Other : Mat) returns Mat is static;
---C++: inline
---C++: alias operator *
--- Purpose :
-- Computes the product of two matrices <me> * <Other>
Multiply (me : in out; Other : Mat) is static;
---C++: inline
---C++: alias operator *=
---Purpose: Computes the product of two matrices <me> = <Other> * <me>.
PreMultiply (me : in out; Other : Mat) is static;
---C++: inline
--Purpose :
-- Modifies this matrix by premultiplying it by the matrix
-- Other:
-- this = Other * this
-- Computes the product of two matrices <me> = <Other> * <me>.
Multiplied (me; Scalar : Real) returns Mat is static;
---C++: inline
---C++: alias operator *
Multiply (me : in out; Scalar : Real) is static;
---C++: inline
---C++: alias operator *=
--- Purpose :
-- Multiplies all the coefficients of the matrix by Scalar
Power (me : in out; N : Integer) raises ConstructionError is static;
Powered (me; N : Integer) returns Mat raises ConstructionError is static;
---C++: inline
--- Purpose :
-- Computes <me> = <me> * <me> * .......* <me>, N time.
-- if N = 0 <me> = Identity
-- if N < 0 <me> = <me>.Invert() *...........* <me>.Invert().
-- If N < 0 an exception will be raised if the matrix is not
-- inversible
Subtract (me : in out; Other : Mat) is static;
---C++: inline
---C++: alias operator -=
Subtracted (me; Other : Mat) returns Mat is static;
---C++: inline
---C++: alias operator -
--- Purpose :
-- cOmputes for each coefficient of the matrix :
-- <me>.Coef(i,j) - <Other>.Coef(i,j)
Transpose (me : in out) is static;
---C++: inline
Transposed (me) returns Mat
---C++: inline
--- Purpose :
-- Transposes the matrix. A(j, i) -> A (i, j)
is static;
fields
matrix : Real[3, 3];
friends
class XYZ from gp,
class Trsf from gp,
class GTrsf from gp
end;

254
src/gp/gp_Mat.cxx Executable file
View File

@@ -0,0 +1,254 @@
// File gp_Mat.cxx, JCV 05/12/90
// 10/09/97 : PMN : Correction BUC40192 (pb avec les matrices negatives)
#ifndef DEB
#define No_Standard_OutOfRange
#define No_Standard_ConstructionError
#endif
#include <gp_Mat.ixx>
#define M00 ((Standard_Real*)M)[0]
#define M01 ((Standard_Real*)M)[1]
#define M02 ((Standard_Real*)M)[2]
#define M10 ((Standard_Real*)M)[3]
#define M11 ((Standard_Real*)M)[4]
#define M12 ((Standard_Real*)M)[5]
#define M20 ((Standard_Real*)M)[6]
#define M21 ((Standard_Real*)M)[7]
#define M22 ((Standard_Real*)M)[8]
#define N00 ((Standard_Real*)N)[0]
#define N01 ((Standard_Real*)N)[1]
#define N02 ((Standard_Real*)N)[2]
#define N10 ((Standard_Real*)N)[3]
#define N11 ((Standard_Real*)N)[4]
#define N12 ((Standard_Real*)N)[5]
#define N20 ((Standard_Real*)N)[6]
#define N21 ((Standard_Real*)N)[7]
#define N22 ((Standard_Real*)N)[8]
gp_Mat::gp_Mat (const gp_XYZ& Col1,
const gp_XYZ& Col2,
const gp_XYZ& Col3)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
M00 = Col1.X(); M10 = Col1.Y(); M20 = Col1.Z();
M01 = Col2.X(); M11 = Col2.Y(); M21 = Col2.Z();
M02 = Col3.X(); M12 = Col3.Y(); M22 = Col3.Z();
}
void gp_Mat::SetCol (const Standard_Integer Col,
const gp_XYZ& Value) {
Standard_OutOfRange_Raise_if (Col < 1 || Col > 3, " ");
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
if (Col == 1) {
M00 = Value.X(); M10 = Value.Y(); M20 = Value.Z();
}
else if (Col == 2) {
M01 = Value.X(); M11 = Value.Y(); M21 = Value.Z();
}
else {
M02 = Value.X(); M12 = Value.Y(); M22 = Value.Z();
}
}
void gp_Mat::SetCols (const gp_XYZ& Col1,
const gp_XYZ& Col2,
const gp_XYZ& Col3)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat00 = Col1.X(); Mat10 = Col1.Y(); Mat20 = Col1.Z();
Mat01 = Col2.X(); Mat11 = Col2.Y(); Mat21 = Col2.Z();
Mat02 = Col3.X(); Mat12 = Col3.Y(); Mat22 = Col3.Z();
}
void gp_Mat::SetCross (const gp_XYZ& Ref)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Standard_Real X = Ref.X();
Standard_Real Y = Ref.Y();
Standard_Real Z = Ref.Z();
M00 = M11 = M22 = 0.0;
M01 = - Z;
M02 = Y;
M12 = - X;
M10 = Z;
M20 = - Y;
M21 = X;
}
void gp_Mat::SetDot (const gp_XYZ& Ref)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Standard_Real X = Ref.X();
Standard_Real Y = Ref.Y();
Standard_Real Z = Ref.Z();
M00 = X * X;
M11 = Y * Y;
M22 = Z * Z;
M01 = X * Y;
M02 = X * Z;
M12 = Y * Z;
M10 = M01;
M20 = M02;
M21 = M12;
}
void gp_Mat::SetRotation (const gp_XYZ& Axis,
const Standard_Real Ang)
{
// Rot = I + sin(Ang) * M + (1. - cos(Ang)) * M*M
// avec M . XYZ = Axis ^ XYZ
// const Standard_Address M = (Standard_Address)&(matrix[0][0]);
gp_XYZ V = Axis.Normalized();
SetCross (V);
Multiply (sin(Ang));
gp_Mat Temp;
Temp.SetScale (1.0);
Add (Temp);
Standard_Real A = V.X();
Standard_Real B = V.Y();
Standard_Real C = V.Z();
Temp.SetRow (1, gp_XYZ(- C*C - B*B, A*B, A*C ));
Temp.SetRow (2, gp_XYZ( A*B, -A*A - C*C, B*C ));
Temp.SetRow (3, gp_XYZ( A*C, B*C, - A*A - B*B));
Temp.Multiply (1.0 - cos(Ang));
Add (Temp);
}
void gp_Mat::SetRow (const Standard_Integer Row,
const gp_XYZ& Value)
{
Standard_OutOfRange_Raise_if (Row < 1 || Row > 3, " ");
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
if (Row == 1) {
M00 = Value.X(); M01 = Value.Y(); M02 = Value.Z();
}
else if (Row == 2) {
M10 = Value.X(); M11 = Value.Y(); M12 = Value.Z();
}
else {
M20 = Value.X(); M21 = Value.Y(); M22 = Value.Z();
}
}
void gp_Mat::SetRows (const gp_XYZ& Row1,
const gp_XYZ& Row2,
const gp_XYZ& Row3)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
M00 = Row1.X(); M01 = Row1.Y(); M02 = Row1.Z();
M10 = Row2.X(); M11 = Row2.Y(); M12 = Row2.Z();
M20 = Row3.X(); M21 = Row3.Y(); M22 = Row3.Z();
}
gp_XYZ gp_Mat::Column (const Standard_Integer Col) const
{
Standard_OutOfRange_Raise_if (Col < 1 || Col > 3, "");
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
if (Col == 1) return gp_XYZ (M00,M10,M20);
if (Col == 2) return gp_XYZ (M01,M11,M21);
return gp_XYZ (M02,M12,M22);
}
gp_XYZ gp_Mat::Diagonal () const
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
return gp_XYZ (M00, M11, M22);
}
gp_XYZ gp_Mat::Row (const Standard_Integer Row) const
{
Standard_OutOfRange_Raise_if (Row < 1 || Row > 3, "");
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
if (Row == 1) return gp_XYZ (M00,M01,M02);
if (Row == 2) return gp_XYZ (M10,M11,M12);
return gp_XYZ (M20,M21,M22);
}
void gp_Mat::Invert ()
{
Standard_Real new_array[3][3] ;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(new_array[0][0]);
//
// calcul de la transposee de la commatrice
//
N00 = M11 * M22 - M12 * M21 ;
N10 = -(M10 * M22 - M20 * M12) ;
N20 = M10 * M21 - M20 * M11 ;
N01 = - (M01 * M22 - M21 * M02) ;
N11 = M00 * M22 - M20 * M02 ;
N21 = -(M00 * M21 - M20 * M01) ;
N02 = M01 * M12 - M11 * M02 ;
N12 = -(M00 * M12 - M10 * M02) ;
N22 = M00 * M11 - M01 * M10 ;
Standard_Real det = M00 * N00 + M01* N10 + M02 * N20 ;
Standard_Real val = det;
if (val < 0) val = - val;
Standard_ConstructionError_Raise_if
(val <= gp::Resolution(),"");
det = 1.0e0 / det ;
M00 = N00;
M10 = N10;
M20 = N20;
M01 = N01;
M11 = N11;
M21 = N21;
M02 = N02;
M12 = N12;
M22 = N22;
Multiply(det) ;
}
gp_Mat gp_Mat::Inverted () const
{
gp_Mat NewMat;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat.matrix[0][0]);
//
// calcul de la transposee de la commatrice
//
N00 = M11 * M22 - M12 * M21 ;
N10 = -(M10 * M22 - M20 * M12) ;
N20 = M10 * M21 - M20 * M11 ;
N01 = - (M01 * M22 - M21 * M02) ;
N11 = M00 * M22 - M20 * M02 ;
N21 = -(M00 * M21 - M20 * M01) ;
N02 = M01 * M12 - M11 * M02 ;
N12 = -(M00 * M12 - M10 * M02) ;
N22 = M00 * M11 - M01 * M10 ;
Standard_Real det = M00 * N00 + M01* N10 + M02 * N20 ;
Standard_Real val = det;
if (val < 0) val = - val;
Standard_ConstructionError_Raise_if
(val <= gp::Resolution(),"");
det = 1.0e0 / det ;
NewMat.Multiply(det) ;
return NewMat;
}
void gp_Mat::Power (const Standard_Integer N)
{
if (N == 1) { }
else if (N == 0) { SetIdentity() ; }
else if (N == -1) { Invert(); }
else {
if (N < 0) { Invert(); }
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_Mat Temp = *this;
while (1) {
if (IsOdd(Npower)) Multiply (Temp);
if (Npower == 1) break;
Temp.Multiply (Temp);
Npower>>=1;
}
}
}

362
src/gp/gp_Mat.lxx Executable file
View File

@@ -0,0 +1,362 @@
//File gp_Mat.lxx, JCV 04/12/90
#include <gp.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_ConstructionError.hxx>
#define Mat00 ((Standard_Real*)M)[0]
#define Mat01 ((Standard_Real*)M)[1]
#define Mat02 ((Standard_Real*)M)[2]
#define Mat10 ((Standard_Real*)M)[3]
#define Mat11 ((Standard_Real*)M)[4]
#define Mat12 ((Standard_Real*)M)[5]
#define Mat20 ((Standard_Real*)M)[6]
#define Mat21 ((Standard_Real*)M)[7]
#define Mat22 ((Standard_Real*)M)[8]
#define Nat00 ((Standard_Real*)N)[0]
#define Nat01 ((Standard_Real*)N)[1]
#define Nat02 ((Standard_Real*)N)[2]
#define Nat10 ((Standard_Real*)N)[3]
#define Nat11 ((Standard_Real*)N)[4]
#define Nat12 ((Standard_Real*)N)[5]
#define Nat20 ((Standard_Real*)N)[6]
#define Nat21 ((Standard_Real*)N)[7]
#define Nat22 ((Standard_Real*)N)[8]
#define Oat00 ((Standard_Real*)O)[0]
#define Oat01 ((Standard_Real*)O)[1]
#define Oat02 ((Standard_Real*)O)[2]
#define Oat10 ((Standard_Real*)O)[3]
#define Oat11 ((Standard_Real*)O)[4]
#define Oat12 ((Standard_Real*)O)[5]
#define Oat20 ((Standard_Real*)O)[6]
#define Oat21 ((Standard_Real*)O)[7]
#define Oat22 ((Standard_Real*)O)[8]
inline gp_Mat::gp_Mat () {
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat00 =
Mat01 =
Mat02 =
Mat10 =
Mat11 =
Mat12 =
Mat20 =
Mat21 =
Mat22 = 0.0;
}
inline gp_Mat::gp_Mat (const Standard_Real a11,
const Standard_Real a12,
const Standard_Real a13,
const Standard_Real a21,
const Standard_Real a22,
const Standard_Real a23,
const Standard_Real a31,
const Standard_Real a32,
const Standard_Real a33) {
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat00 = a11;
Mat01 = a12;
Mat02 = a13;
Mat10 = a21;
Mat11 = a22;
Mat12 = a23;
Mat20 = a31;
Mat21 = a32;
Mat22 = a33;
}
inline void gp_Mat::SetDiagonal (const Standard_Real X1,
const Standard_Real X2,
const Standard_Real X3)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat00 = X1; Mat11 = X2; Mat22 = X3;
}
inline void gp_Mat::SetIdentity ()
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat00 = Mat11 = Mat22 = 1.0;
Mat01 = Mat02 = Mat10 = Mat12 = Mat20 = Mat21 = 0.0;
}
inline void gp_Mat::SetScale (const Standard_Real S)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat00 = Mat11 = Mat22 = S;
Mat01 = Mat02 = Mat10 = Mat12 = Mat20 = Mat21 = 0.0;
}
inline void gp_Mat::SetValue (const Standard_Integer Row,
const Standard_Integer Col,
const Standard_Real Value)
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 3 || Col < 1 || Col > 3, " ");
matrix[Row-1][Col-1] = Value;
}
inline Standard_Real gp_Mat::Determinant () const
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
return
Mat00 * (Mat11 * Mat22 - Mat21 * Mat12) -
Mat01 * (Mat10 * Mat22 - Mat20 * Mat12) +
Mat02 * (Mat10 * Mat21 - Mat20 * Mat11);
}
inline const Standard_Real& gp_Mat::Value (const Standard_Integer Row,
const Standard_Integer Col) const
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 3 || Col < 1 || Col > 3, " ");
return matrix[Row-1][Col-1];
}
inline Standard_Real& gp_Mat::ChangeValue (const Standard_Integer Row,
const Standard_Integer Col)
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 3 || Col < 1 || Col > 3, " ");
return matrix[Row-1][Col-1];
}
inline Standard_Boolean gp_Mat::IsSingular () const
{
// Pour etre sur que Gauss va fonctionner, il faut faire Gauss ...
Standard_Real val = Determinant();
if (val < 0) val = - val;
return val <= gp::Resolution();
}
inline void gp_Mat::Add (const gp_Mat& Other)
{
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]);
Mat00 = Mat00 + Oat00;
Mat01 = Mat01 + Oat01;
Mat02 = Mat02 + Oat02;
Mat10 = Mat10 + Oat10;
Mat11 = Mat11 + Oat11;
Mat12 = Mat12 + Oat12;
Mat20 = Mat20 + Oat20;
Mat21 = Mat21 + Oat21;
Mat22 = Mat22 + Oat22;
}
inline gp_Mat gp_Mat::Added (const gp_Mat& Other) const
{
gp_Mat NewMat;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat.matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other .matrix[0][0]);
Nat00 = Mat00 + Oat00;
Nat01 = Mat01 + Oat01;
Nat02 = Mat02 + Oat02;
Nat10 = Mat10 + Oat10;
Nat11 = Mat11 + Oat11;
Nat12 = Mat12 + Oat12;
Nat20 = Mat20 + Oat20;
Nat21 = Mat21 + Oat21;
Nat22 = Mat22 + Oat22;
return NewMat;
}
inline void gp_Mat::Divide (const Standard_Real Scalar)
{
Standard_Real val = Scalar;
if (val < 0) val = - val;
Standard_ConstructionError_Raise_if
(val <= gp::Resolution(),"gp_Mat : Divide by 0");
Standard_Real UnSurScalar = 1.0 / Scalar;
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat00 *= UnSurScalar;
Mat01 *= UnSurScalar;
Mat02 *= UnSurScalar;
Mat10 *= UnSurScalar;
Mat11 *= UnSurScalar;
Mat12 *= UnSurScalar;
Mat20 *= UnSurScalar;
Mat21 *= UnSurScalar;
Mat22 *= UnSurScalar;
}
inline gp_Mat gp_Mat::Divided (const Standard_Real Scalar) const
{
Standard_Real val = Scalar;
if (val < 0) val = - val;
Standard_ConstructionError_Raise_if
(val <= gp::Resolution(),"gp_Mat : Divide by 0");
gp_Mat NewMat;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat.matrix[0][0]);
Standard_Real UnSurScalar = 1.0 / Scalar;
Nat00 = Mat00 * UnSurScalar;
Nat01 = Mat01 * UnSurScalar;
Nat02 = Mat02 * UnSurScalar;
Nat10 = Mat10 * UnSurScalar;
Nat11 = Mat11 * UnSurScalar;
Nat12 = Mat12 * UnSurScalar;
Nat20 = Mat20 * UnSurScalar;
Nat21 = Mat21 * UnSurScalar;
Nat22 = Mat22 * UnSurScalar;
return NewMat;
}
inline gp_Mat gp_Mat::Multiplied (const gp_Mat& Other) const
{
gp_Mat NewMat = *this;
NewMat.Multiply(Other);
return NewMat;
}
inline void gp_Mat::Multiply (const gp_Mat& Other)
{
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]);
Standard_Real T00,T01,T02,T10,T11,T12,T20,T21,T22;
T00 = Mat00 * Oat00 + Mat01 * Oat10 + Mat02 * Oat20;
T01 = Mat00 * Oat01 + Mat01 * Oat11 + Mat02 * Oat21;
T02 = Mat00 * Oat02 + Mat01 * Oat12 + Mat02 * Oat22;
T10 = Mat10 * Oat00 + Mat11 * Oat10 + Mat12 * Oat20;
T11 = Mat10 * Oat01 + Mat11 * Oat11 + Mat12 * Oat21;
T12 = Mat10 * Oat02 + Mat11 * Oat12 + Mat12 * Oat22;
T20 = Mat20 * Oat00 + Mat21 * Oat10 + Mat22 * Oat20;
T21 = Mat20 * Oat01 + Mat21 * Oat11 + Mat22 * Oat21;
T22 = Mat20 * Oat02 + Mat21 * Oat12 + Mat22 * Oat22;
Mat00 = T00;
Mat01 = T01;
Mat02 = T02;
Mat10 = T10;
Mat11 = T11;
Mat12 = T12;
Mat20 = T20;
Mat21 = T21;
Mat22 = T22;
}
inline void gp_Mat::PreMultiply (const gp_Mat& Other)
{
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]);
Standard_Real T00,T01,T02,T10,T11,T12,T20,T21,T22;
T00 = Oat00 * Mat00 + Oat01 * Mat10 + Oat02 * Mat20;
T01 = Oat00 * Mat01 + Oat01 * Mat11 + Oat02 * Mat21;
T02 = Oat00 * Mat02 + Oat01 * Mat12 + Oat02 * Mat22;
T10 = Oat10 * Mat00 + Oat11 * Mat10 + Oat12 * Mat20;
T11 = Oat10 * Mat01 + Oat11 * Mat11 + Oat12 * Mat21;
T12 = Oat10 * Mat02 + Oat11 * Mat12 + Oat12 * Mat22;
T20 = Oat20 * Mat00 + Oat21 * Mat10 + Oat22 * Mat20;
T21 = Oat20 * Mat01 + Oat21 * Mat11 + Oat22 * Mat21;
T22 = Oat20 * Mat02 + Oat21 * Mat12 + Oat22 * Mat22;
Mat00 = T00;
Mat01 = T01;
Mat02 = T02;
Mat10 = T10;
Mat11 = T11;
Mat12 = T12;
Mat20 = T20;
Mat21 = T21;
Mat22 = T22;
}
inline gp_Mat gp_Mat::Multiplied (const Standard_Real Scalar) const
{
gp_Mat NewMat;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat.matrix[0][0]);
Nat00 = Scalar * Mat00;
Nat01 = Scalar * Mat01;
Nat02 = Scalar * Mat02;
Nat10 = Scalar * Mat10;
Nat11 = Scalar * Mat11;
Nat12 = Scalar * Mat12;
Nat20 = Scalar * Mat20;
Nat21 = Scalar * Mat21;
Nat22 = Scalar * Mat22;
return NewMat;
}
inline void gp_Mat::Multiply (const Standard_Real Scalar)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat00 *= Scalar;
Mat01 *= Scalar;
Mat02 *= Scalar;
Mat10 *= Scalar;
Mat11 *= Scalar;
Mat12 *= Scalar;
Mat20 *= Scalar;
Mat21 *= Scalar;
Mat22 *= Scalar;
}
inline gp_Mat gp_Mat::Powered (const Standard_Integer N) const
{
gp_Mat MatN = *this;
MatN.Power (N);
return MatN;
}
inline void gp_Mat::Subtract (const gp_Mat& Other)
{
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]);
Mat00 -= Oat00;
Mat01 -= Oat01;
Mat02 -= Oat02;
Mat10 -= Oat10;
Mat11 -= Oat11;
Mat12 -= Oat12;
Mat20 -= Oat20;
Mat21 -= Oat21;
Mat22 -= Oat22;
}
inline gp_Mat gp_Mat::Subtracted (const gp_Mat& Other) const
{
gp_Mat NewMat;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat.matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other .matrix[0][0]);
Nat00 = Mat00 - Oat00;
Nat01 = Mat01 - Oat01;
Nat02 = Mat02 - Oat02;
Nat10 = Mat10 - Oat10;
Nat11 = Mat11 - Oat11;
Nat12 = Mat12 - Oat12;
Nat20 = Mat20 - Oat20;
Nat21 = Mat21 - Oat21;
Nat22 = Mat22 - Oat22;
return NewMat;
}
inline void gp_Mat::Transpose ()
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Standard_Real Temp;
Temp = Mat01;
Mat01 = Mat10;
Mat10 = Temp;
Temp = Mat02;
Mat02 = Mat20;
Mat20 = Temp;
Temp = Mat12;
Mat12 = Mat21;
Mat21 = Temp;
}
inline gp_Mat gp_Mat::Transposed () const
{
gp_Mat NewMat = *this;
NewMat.Transpose();
return NewMat;
}
inline gp_Mat operator* (const Standard_Real Scalar, const gp_Mat& Mat3D)
{ return Mat3D.Multiplied (Scalar); }

258
src/gp/gp_Mat2d.cdl Executable file
View File

@@ -0,0 +1,258 @@
---Copyright: Matra Datavision 1991
class Mat2d from gp inherits Storable
---Purpose:
-- Describes a two column, two row matrix. This sort of
-- object is used in various vectorial or matrix computations.
uses XY from gp,
XYZ from gp
raises ConstructionError from Standard,
OutOfRange from Standard
is
Create returns Mat2d;
---C++: inline
--- Purpose : Creates a matrix with null coefficients.
Create (Col1, Col2 : XY) returns Mat2d;
--- Purpose :
-- Col1, Col2 are the 2 columns of the matrix.
SetCol (me : in out; Col : Integer; Value : XY)
--- Purpose : Assigns the two coordinates of Value to the column of range
-- Col of this matrix
-- Raises OutOfRange if Col < 1 or Col > 2.
raises OutOfRange
is static;
SetCols (me : in out; Col1, Col2 : XY)
--- Purpose : Assigns the number pairs Col1, Col2 to the two columns of this matrix
is static;
SetDiagonal (me : in out; X1, X2 : Real) is static;
---C++: inline
--- Purpose :
-- Modifies the main diagonal of the matrix.
-- <me>.Value (1, 1) = X1
-- <me>.Value (2, 2) = X2
-- The other coefficients of the matrix are not modified.
SetIdentity (me : in out) is static;
---C++: inline
--- Purpose : Modifies this matrix, so that it represents the Identity matrix.
SetRotation (me : in out; Ang : Real) is static;
--- Purpose :
-- Modifies this matrix, so that it representso a rotation. Ang is the angular
-- value in radian of the rotation.
---C++: inline
SetRow (me : in out; Row : Integer; Value : XY)
--- Purpose : Assigns the two coordinates of Value to the row of index Row of this matrix.
-- Raises OutOfRange if Row < 1 or Row > 2.
raises OutOfRange
is static;
SetRows (me : in out; Row1, Row2 : XY) is static;
--- Purpose : Assigns the number pairs Row1, Row2 to the two rows of this matrix.
SetScale (me : in out; S : Real) is static;
---C++: inline
--- Purpose :
-- Modifies the matrix such that it
-- represents a scaling transformation, where S is the scale factor :
-- | S 0.0 |
-- <me> = | 0.0 S |
SetValue (me : in out; Row, Col : Integer; Value : Real)
--- Purpose : Assigns <Value> to the coefficient of row Row, column Col of this matrix.
-- Raises OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 2
---C++: inline
raises OutOfRange
is static;
Column (me; Col : Integer) returns XY
--- Purpose : Returns the column of Col index.
-- Raises OutOfRange if Col < 1 or Col > 2
raises OutOfRange
is static;
Determinant (me) returns Real is static;
---C++: inline
--- Purpose : Computes the determinant of the matrix.
Diagonal (me) returns XY is static;
--- Purpose : Returns the main diagonal of the matrix.
Row (me; Row : Integer) returns XY
--- Purpose : Returns the row of index Row.
raises OutOfRange
--- Purpose : Raised if Row < 1 or Row > 2
is static;
Value (me; Row, Col : Integer) returns Real
--- Purpose : Returns the coefficient of range (Row, Col)
-- Raises OutOfRange
-- if Row < 1 or Row > 2 or Col < 1 or Col > 2
---C++: inline
---C++: return const &
---C++: alias operator()
raises OutOfRange
is static;
ChangeValue (me : in out; Row, Col : Integer) returns Real
--- Purpose : Returns the coefficient of range (Row, Col)
-- Raises OutOfRange
-- if Row < 1 or Row > 2 or Col < 1 or Col > 2
---C++: inline
---C++: return &
---C++: alias operator()
raises OutOfRange
is static;
IsSingular (me) returns Boolean is static;
--- Purpose :
-- Returns true if this matrix is singular (and therefore, cannot be inverted).
-- The Gauss LU decomposition is used to invert the matrix
-- so the matrix is considered as singular if the largest
-- pivot found is lower or equal to Resolution from gp.
---C++: inline
Add (me : in out; Other : Mat2d) is static;
---C++: inline
---C++: alias operator +=
Added (me; Other : Mat2d) returns Mat2d is static;
---C++: inline
---C++: alias operator +
--- Purpose :
-- Computes the sum of this matrix and the matrix
-- Other.for each coefficient of the matrix :
-- <me>.Coef(i,j) + <Other>.Coef(i,j)
-- Note:
-- - operator += assigns the result to this matrix, while
-- - operator + creates a new one.
Divide (me : in out; Scalar : Real) is static;
---C++: inline
---C++: alias operator /=
Divided (me; Scalar : Real) returns Mat2d is static;
---C++: inline
---C++: alias operator /
--- Purpose :
-- Divides all the coefficients of the matrix by a scalar.
Invert (me : in out) raises ConstructionError is static;
Inverted (me) returns Mat2d raises ConstructionError is static;
--- Purpose :
-- Inverses the matrix and raises exception if the matrix
-- is singular.
---C++: inline
Multiplied (me; Other : Mat2d) returns Mat2d is static;
---C++: inline
---C++: alias operator *
Multiply (me : in out; Other : Mat2d) is static;
--- Purpose :
-- Computes the product of two matrices <me> * <Other>
---C++: inline
-- C++: alias operator *=
PreMultiply(me : in out; Other : Mat2d) is static;
--- Purpose : Modifies this matrix by premultiplying it by the matrix Other
-- <me> = Other * <me>.
---C++: inline
Multiplied (me; Scalar : Real) returns Mat2d is static;
---C++: inline
---C++: alias operator *
Multiply (me : in out; Scalar : Real) is static;
--- Purpose :
-- Multiplies all the coefficients of the matrix by a scalar.
---C++: inline
---C++: alias operator *=
Power (me : in out; N : Integer) raises ConstructionError is static;
Powered (me; N : Integer) returns Mat2d raises ConstructionError is static;
--- Purpose :
-- computes <me> = <me> * <me> * .......* <me>, N time.
-- if N = 0 <me> = Identity
-- if N < 0 <me> = <me>.Invert() *...........* <me>.Invert().
-- If N < 0 an exception can be raised if the matrix is not
-- inversible
---C++: inline
Subtract (me : in out; Other : Mat2d) is static;
---C++: inline
---C++: alias operator -=
Subtracted (me; Other : Mat2d) returns Mat2d is static;
---C++: inline
---C++: alias operator -
--- Purpose :
-- Computes for each coefficient of the matrix :
-- <me>.Coef(i,j) - <Other>.Coef(i,j)
Transpose (me : in out) is static;
---C++: inline
Transposed (me) returns Mat2d is static;
--- Purpose :
-- Transposes the matrix. A(j, i) -> A (i, j)
---C++: inline
fields
matrix : Real[2, 2];
friends
class Trsf2d from gp,
class GTrsf2d from gp,
class XY from gp
end;

135
src/gp/gp_Mat2d.cxx Executable file
View File

@@ -0,0 +1,135 @@
// File gp_Mat2d.cxx, JCV 08/01/91
// 10/09/97 : PMN : Correction BUC40192 (pb avec les matrices negatives)
#ifndef DEB
#define No_Standard_OutOfRange
#define No_Standard_ConstructionError
#endif
#include <gp_Mat2d.ixx>
#include <Standard_ConstructionError.hxx>
#define M00 ((Standard_Real*)M)[0]
#define M01 ((Standard_Real*)M)[1]
#define M10 ((Standard_Real*)M)[2]
#define M11 ((Standard_Real*)M)[3]
#define N00 ((Standard_Real*)N)[0]
#define N01 ((Standard_Real*)N)[1]
#define N10 ((Standard_Real*)N)[2]
#define N11 ((Standard_Real*)N)[3]
gp_Mat2d::gp_Mat2d (const gp_XY& Col1, const gp_XY& Col2)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
M00 = Col1.X(); M10 = Col1.Y();
M01 = Col2.X(); M11 = Col2.Y();
}
void gp_Mat2d::SetCol (const Standard_Integer Col,
const gp_XY& Value)
{
Standard_OutOfRange_Raise_if (Col < 1 || Col > 2,"");
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
if (Col == 1) {
M00 = Value.X();
M10 = Value.Y();
}
else {
M01 = Value.X();
M11 = Value.Y();
}
}
void gp_Mat2d::SetCols (const gp_XY& Col1,
const gp_XY& Col2)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
M00 = Col1.X(); M10 = Col1.Y();
M01 = Col2.X(); M11 = Col2.Y();
}
void gp_Mat2d::SetRow (const Standard_Integer Row, const gp_XY& Value)
{
Standard_OutOfRange_Raise_if (Row < 1 || Row > 2,"");
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
if (Row == 1) {
M00 = Value.X();
M01 = Value.Y();
}
else {
M10 = Value.X();
M11 = Value.Y();
}
}
void gp_Mat2d::SetRows (const gp_XY& Row1, const gp_XY& Row2)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
M00 = Row1.X(); M01 = Row1.Y();
M10 = Row2.X(); M11 = Row2.Y();
}
gp_XY gp_Mat2d::Column (const Standard_Integer Col) const
{
Standard_OutOfRange_Raise_if (Col < 1 || Col > 2,"");
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
if (Col == 1) return gp_XY (M00,M10);
return gp_XY (M01,M11);
}
gp_XY gp_Mat2d::Diagonal () const
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
return gp_XY (M00,M11);
}
gp_XY gp_Mat2d::Row (const Standard_Integer Row) const
{
Standard_OutOfRange_Raise_if (Row < 1 || Row > 2,"");
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
if (Row == 1) return gp_XY (M00,M01);
return gp_XY (M10,M11);
}
void gp_Mat2d::Invert ()
{
Standard_Real new_matrix[2][2],
det ;
const Standard_Address N = (Standard_Address)&(new_matrix[0][0]);
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
N00 = M11 ;
N01 = -M01 ;
N10 = -M10 ;
N11 = M00 ;
det = N00 * N11 - N01 * N10 ;
Standard_Real val = det;
if (val < 0) val = - val;
Standard_ConstructionError_Raise_if (val <= gp::Resolution(),"");
det = 1.0 / det ;
M00 = N00 * det ;
M10 = N10 * det ;
M01 = N01 * det ;
M11 = N11 * det ;
}
void gp_Mat2d::Power (const Standard_Integer N)
{
if (N == 1) { }
else if (N == 0) { SetIdentity (); }
else if (N == -1) { Invert(); }
else {
if (N < 0) Invert();
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_Mat2d Temp = *this;
while (1) {
if (IsOdd(Npower)) Multiply (Temp);
if (Npower == 1) break;
Temp.Multiply (Temp);
Npower = Npower/2;
}
}
}

256
src/gp/gp_Mat2d.lxx Executable file
View File

@@ -0,0 +1,256 @@
//File gp_Mat2d.lxx, JCV 04/12/90
#include <gp.hxx>
#include <Standard_OutOfRange.hxx>
#define Mat2d00 ((Standard_Real*)M)[0]
#define Mat2d01 ((Standard_Real*)M)[1]
#define Mat2d10 ((Standard_Real*)M)[2]
#define Mat2d11 ((Standard_Real*)M)[3]
#define Nat2d00 ((Standard_Real*)N)[0]
#define Nat2d01 ((Standard_Real*)N)[1]
#define Nat2d10 ((Standard_Real*)N)[2]
#define Nat2d11 ((Standard_Real*)N)[3]
#define Oat2d00 ((Standard_Real*)O)[0]
#define Oat2d01 ((Standard_Real*)O)[1]
#define Oat2d10 ((Standard_Real*)O)[2]
#define Oat2d11 ((Standard_Real*)O)[3]
inline gp_Mat2d::gp_Mat2d ()
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat2d00 = Mat2d01 = Mat2d10 = Mat2d11 = 0.0;
}
inline void gp_Mat2d::SetDiagonal (const Standard_Real X1,
const Standard_Real X2)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat2d00 = X1; Mat2d11 = X2;
}
inline void gp_Mat2d::SetIdentity ()
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat2d00 = Mat2d11 = 1.0;
Mat2d01 = Mat2d10 = 0.0;
}
inline void gp_Mat2d::SetRotation (const Standard_Real Ang)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Standard_Real SinA = sin(Ang);
Standard_Real CosA = cos(Ang);
Mat2d00 = Mat2d11 = CosA;
Mat2d01 = -SinA;
Mat2d10 = SinA;
}
inline void gp_Mat2d::SetScale (const Standard_Real S)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat2d00 = Mat2d11 = S;
Mat2d01 = Mat2d10 = 0.0;
}
inline void gp_Mat2d::SetValue (const Standard_Integer Row,
const Standard_Integer Col,
const Standard_Real Value)
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 2 || Col < 1 || Col > 2, " ");
matrix[Row-1][Col-1] = Value;
}
inline Standard_Real gp_Mat2d::Determinant () const
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
return Mat2d00 * Mat2d11 - Mat2d10 * Mat2d01;
}
inline const Standard_Real& gp_Mat2d::Value (const Standard_Integer Row,
const Standard_Integer Col) const
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 2 || Col < 1 || Col > 2, " ");
return matrix[Row-1][Col-1];
}
inline Standard_Real&
gp_Mat2d::ChangeValue (const Standard_Integer Row,
const Standard_Integer Col)
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 2 || Col < 1 || Col > 2, " ");
return matrix[Row-1][Col-1];
}
inline Standard_Boolean gp_Mat2d::IsSingular () const
{
Standard_Real det = Determinant();
if (det < 0) det = - det;
return det <= gp::Resolution();
}
inline void gp_Mat2d::Add (const gp_Mat2d& Other)
{
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]);
Mat2d00 += Oat2d00;
Mat2d01 += Oat2d01;
Mat2d10 += Oat2d10;
Mat2d11 += Oat2d11;
}
inline gp_Mat2d gp_Mat2d::Added (const gp_Mat2d& Other) const
{
gp_Mat2d NewMat2d;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other .matrix[0][0]);
Nat2d00 = Mat2d00 + Oat2d00;
Nat2d01 = Mat2d01 + Oat2d01;
Nat2d10 = Mat2d10 + Oat2d10;
Nat2d11 = Mat2d11 + Oat2d11;
return NewMat2d;
}
inline void gp_Mat2d::Divide (const Standard_Real Scalar)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat2d00 /= Scalar;
Mat2d01 /= Scalar;
Mat2d10 /= Scalar;
Mat2d11 /= Scalar;
}
inline gp_Mat2d gp_Mat2d::Divided (const Standard_Real Scalar) const
{
gp_Mat2d NewMat2d;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]);
Nat2d00 = Mat2d00 / Scalar;
Nat2d01 = Mat2d01 / Scalar;
Nat2d10 = Mat2d10 / Scalar;
Nat2d11 = Mat2d11 / Scalar;
return NewMat2d;
}
inline gp_Mat2d gp_Mat2d::Inverted () const
{
gp_Mat2d NewMat = *this;
NewMat.Invert();
return NewMat;
}
inline gp_Mat2d gp_Mat2d::Multiplied (const gp_Mat2d& Other) const
{
gp_Mat2d NewMat2d = *this;
NewMat2d.Multiply(Other);
return NewMat2d;
}
inline void gp_Mat2d::Multiply (const gp_Mat2d& Other)
{
Standard_Real T00,T10;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]);
T00 = Mat2d00 * Oat2d00 + Mat2d01 * Oat2d10;
T10 = Mat2d10 * Oat2d00 + Mat2d11 * Oat2d10;
Mat2d01 = Mat2d00 * Oat2d01 + Mat2d01 * Oat2d11;
Mat2d11 = Mat2d10 * Oat2d01 + Mat2d11 * Oat2d11;
Mat2d00 = T00;
Mat2d10 = T10;
}
inline void gp_Mat2d::PreMultiply (const gp_Mat2d& Other)
{
Standard_Real T00,T01;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]);
T00 = Oat2d00 * Mat2d00 + Oat2d01 * Mat2d10;
Mat2d10 = Oat2d10 * Mat2d00 + Oat2d11 * Mat2d10;
T01 = Oat2d00 * Mat2d01 + Oat2d01 * Mat2d11;
Mat2d11 = Oat2d10 * Mat2d01 + Oat2d11 * Mat2d11;
Mat2d00 = T00;
Mat2d01 = T01;
}
inline gp_Mat2d gp_Mat2d::Multiplied (const Standard_Real Scalar) const
{
gp_Mat2d NewMat2d;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]);
Nat2d00 = Mat2d00 * Scalar;
Nat2d01 = Mat2d01 * Scalar;
Nat2d10 = Mat2d10 * Scalar;
Nat2d11 = Mat2d11 * Scalar;
return NewMat2d;
}
inline void gp_Mat2d::Multiply (const Standard_Real Scalar)
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Mat2d00 *= Scalar;
Mat2d01 *= Scalar;
Mat2d10 *= Scalar;
Mat2d11 *= Scalar;
}
inline gp_Mat2d gp_Mat2d::Powered (const Standard_Integer N) const
{
gp_Mat2d Mat2dN = *this;
Mat2dN.Power (N);
return Mat2dN;
}
inline void gp_Mat2d::Subtract (const gp_Mat2d& Other)
{
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other.matrix[0][0]);
Mat2d00 -= Oat2d00;
Mat2d01 -= Oat2d01;
Mat2d10 -= Oat2d10;
Mat2d11 -= Oat2d11;
}
inline gp_Mat2d gp_Mat2d::Subtracted (const gp_Mat2d& Other) const
{
gp_Mat2d NewMat2d;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]);
const Standard_Address O = (Standard_Address)&(Other .matrix[0][0]);
Nat2d00 = Mat2d00 - Oat2d00;
Nat2d01 = Mat2d01 - Oat2d01;
Nat2d10 = Mat2d10 - Oat2d10;
Nat2d11 = Mat2d11 - Oat2d11;
return NewMat2d;
}
inline void gp_Mat2d::Transpose ()
{
const Standard_Address M = (Standard_Address)&(matrix[0][0]);
Standard_Real Temp;
Temp = Mat2d01;
Mat2d01 = Mat2d10;
Mat2d10 = Temp;
}
inline gp_Mat2d gp_Mat2d::Transposed () const
{
gp_Mat2d NewMat2d;
const Standard_Address M = (Standard_Address)&( matrix[0][0]);
const Standard_Address N = (Standard_Address)&(NewMat2d.matrix[0][0]);
Nat2d10 = Mat2d01;
Nat2d01 = Mat2d10;
Nat2d00 = Mat2d00;
Nat2d11 = Mat2d11;
return NewMat2d;
}
inline gp_Mat2d operator* (const Standard_Real Scalar,
const gp_Mat2d& Mat2D)
{ return Mat2D.Multiplied (Scalar); }

268
src/gp/gp_Parab.cdl Executable file
View File

@@ -0,0 +1,268 @@
---Copyright: Matra Datavision 1991
class Parab from gp inherits Storable
---Purpose:
-- Describes a parabola in 3D space.
-- A parabola is defined by its focal length (that is, the
-- distance between its focus and apex) and positioned in
-- space with a coordinate system (a gp_Ax2 object)
-- where:
-- - the origin of the coordinate system is on the apex of
-- the parabola,
-- - the "X Axis" of the coordinate system is the axis of
-- symmetry; the parabola is on the positive side of this axis, and
-- - the origin, "X Direction" and "Y Direction" of the
-- coordinate system define the plane of the parabola.
-- The equation of the parabola in this coordinate system,
-- which is the "local coordinate system" of the parabola, is:
-- Y**2 = (2*P) * X.
-- where P, referred to as the parameter of the parabola, is
-- the distance between the focus and the directrix (P is
-- twice the focal length).
-- The "main Direction" of the local coordinate system gives
-- the normal vector to the plane of the parabola.
-- See Also
-- gce_MakeParab which provides functions for more
-- complex parabola constructions
-- Geom_Parabola which provides additional functions for
-- constructing parabolas and works, in particular, with the
-- parametric equations of parabolas
uses Ax1, Ax2, Pnt, Trsf, Vec
raises ConstructionError from Standard
is
Create returns Parab;
---C++: inline
--- Purpose : Creates an indefinite Parabola.
Create (A2 : Ax2; Focal : Real) returns Parab
---C++: inline
--- Purpose :
-- Creates a parabola with its local coordinate system "A2"
-- and it's focal length "Focal".
-- The XDirection of A2 defines the axis of symmetry of the
-- parabola. The YDirection of A2 is parallel to the directrix
-- of the parabola. The Location point of A2 is the vertex of
-- the parabola
-- Raises ConstructionError if Focal < 0.0
raises ConstructionError;
--- Purpose : Raised if Focal < 0.0
Create (D : Ax1; F : Pnt) returns Parab;
---C++: inline
--- Purpose :
-- D is the directrix of the parabola and F the focus point.
-- The symmetry axis (XAxis) of the parabola is normal to the
-- directrix and pass through the focus point F, but its
-- location point is the vertex of the parabola.
-- The YAxis of the parabola is parallel to D and its location
-- point is the vertex of the parabola. The normal to the plane
-- of the parabola is the cross product between the XAxis and the
-- YAxis.
SetAxis (me : in out; A1 : Ax1)
---C++: inline
--- Purpose : Modifies this parabola by redefining its local coordinate system so that
-- - its origin and "main Direction" become those of the
-- axis A1 (the "X Direction" and "Y Direction" are then
-- recomputed in the same way as for any gp_Ax2)
-- Raises ConstructionError if the direction of A1 is parallel to the previous
-- XAxis of the parabola.
raises ConstructionError
is static;
SetFocal (me : in out; Focal : Real)
---C++: inline
--- Purpose : Changes the focal distance of the parabola.
-- Raises ConstructionError if Focal < 0.0
raises ConstructionError
is static;
SetLocation (me : in out; P : Pnt) is static;
---C++: inline
--- Purpose :
-- Changes the location of the parabola. It is the vertex of
-- the parabola.
SetPosition (me : in out; A2 : Ax2) is static;
--- Purpose : Changes the local coordinate system of the parabola.
Axis (me) returns Ax1 is static;
---C++: inline
--- Purpose :
-- Returns the main axis of the parabola.
-- It is the axis normal to the plane of the parabola passing
-- through the vertex of the parabola.
---C++: return const&
Directrix (me) returns Ax1 is static;
---C++: inline
--- Purpose : Computes the directrix of this parabola.
-- The directrix is:
-- - a line parallel to the "Y Direction" of the local
-- coordinate system of this parabola, and
-- - located on the negative side of the axis of symmetry,
-- at a distance from the apex which is equal to the focal
-- length of this parabola.
-- The directrix is returned as an axis (a gp_Ax1 object),
-- the origin of which is situated on the "X Axis" of this parabola.
Focal (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the distance between the vertex and the focus
-- of the parabola.
Focus (me) returns Pnt is static;
---C++: inline
---Purpose: - Computes the focus of the parabola.
Location (me) returns Pnt is static;
---C++: inline
--- Purpose :
-- Returns the vertex of the parabola. It is the "Location"
-- point of the coordinate system of the parabola.
---C++: return const&
Parameter (me) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the parameter of the parabola.
-- It is the distance between the focus and the directrix of
-- the parabola. This distance is twice the focal length.
Position (me) returns Ax2 is static;
--- Purpose :
-- Returns the local coordinate system of the parabola.
---C++: inline
---C++: return const&
XAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose :
-- Returns the symmetry axis of the parabola. The location point
-- of the axis is the vertex of the parabola.
YAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose :
-- It is an axis parallel to the directrix of the parabola.
-- The location point of this axis is the vertex of the parabola.
Mirror (me : in out; P : Pnt) is static;
Mirrored (me; P : Pnt) returns Parab is static;
--- Purpose :
-- Performs the symmetrical transformation of a parabola
-- with respect to the point P which is the center of the
-- symmetry.
Mirror (me : in out; A1 : Ax1) is static;
Mirrored (me; A1 : Ax1) returns Parab is static;
--- Purpose :
-- Performs the symmetrical transformation of a parabola
-- with respect to an axis placement which is the axis of
-- the symmetry.
Mirror (me : in out; A2 : Ax2) is static;
Mirrored (me; A2 : Ax2) returns Parab is static;
--- Purpose :
-- Performs the symmetrical transformation of a parabola
-- with respect to a plane. The axis placement A2 locates
-- the plane of the symmetry (Location, XDirection, YDirection).
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
---C++: inline
Rotated (me; A1 : Ax1; Ang : Real) returns Parab is static;
---C++: inline
--- Purpose :
-- Rotates a parabola. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt; S : Real) returns Parab is static;
---C++: inline
--- Purpose :
-- Scales a parabola. S is the scaling value.
-- If S is negative the direction of the symmetry axis
-- XAxis is reversed and the direction of the YAxis too.
Transform (me : in out; T : Trsf) is static;
---C++: inline
Transformed (me; T : Trsf) returns Parab is static;
---C++: inline
--- Purpose :
-- Transforms a parabola with the transformation T from class Trsf.
Translate (me : in out; V : Vec) is static;
---C++: inline
Translated (me; V : Vec) returns Parab is static;
---C++: inline
--- Purpose :
-- Translates a parabola in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt) is static;
---C++: inline
Translated (me; P1, P2 : Pnt) returns Parab is static;
---C++: inline
--- Purpose :
-- Translates a parabola from the point P1 to the point P2.
fields
pos : Ax2;
focalLength : Real;
end;

35
src/gp/gp_Parab.cxx Executable file
View File

@@ -0,0 +1,35 @@
//File gp_Parab.cxx JCV 12/10/90
// Modif jcv 14/12/90 suite a la premiere revue de projet
#include <gp_Parab.ixx>
void gp_Parab::Mirror (const gp_Pnt& P)
{ pos.Mirror (P); }
gp_Parab gp_Parab::Mirrored (const gp_Pnt& P) const
{
gp_Parab Prb = *this;
Prb.pos.Mirror (P);
return Prb;
}
void gp_Parab::Mirror (const gp_Ax1& A1)
{ pos.Mirror (A1); }
gp_Parab gp_Parab::Mirrored (const gp_Ax1& A1) const
{
gp_Parab Prb = *this;
Prb.pos.Mirror (A1);
return Prb;
}
void gp_Parab::Mirror (const gp_Ax2& A2)
{ pos.Mirror (A2); }
gp_Parab gp_Parab::Mirrored (const gp_Ax2& A2) const
{
gp_Parab Prb = *this;
Prb.pos.Mirror (A2);
return Prb;
}

153
src/gp/gp_Parab.lxx Executable file
View File

@@ -0,0 +1,153 @@
//File gp_Parab.lxx JCV/12/10/90
#include <gp_Lin.hxx>
#include <Standard_ConstructionError.hxx>
inline gp_Parab::gp_Parab () :
focalLength (RealLast())
{ }
inline gp_Parab::gp_Parab (const gp_Ax2& A2,
const Standard_Real Focal) :
pos(A2),
focalLength (Focal)
{ Standard_ConstructionError_Raise_if(Focal < 0.0,""); }
inline gp_Parab::gp_Parab (const gp_Ax1& D,
const gp_Pnt& F)
{
gp_Lin Droite(D);
focalLength = Droite.Distance(F) / 2.;
gp_Ax1 Ax = Droite.Normal(F).Position();
gp_Ax1 Ay = Droite.Position();
const gp_Dir& DD = Ax.Direction();
pos = gp_Ax2 (gp_Pnt(F.X() - focalLength * DD.X(),
F.Y() - focalLength * DD.Y(),
F.Z() - focalLength * DD.Z()),
Ax.Direction().Crossed(Ay.Direction()),
Ax.Direction());
}
inline void gp_Parab::SetAxis (const gp_Ax1& A1)
{ pos.SetAxis (A1); }
inline void gp_Parab::SetFocal (const Standard_Real Focal)
{
Standard_ConstructionError_Raise_if(Focal < 0.0,"");
focalLength = Focal;
}
inline void gp_Parab::SetLocation (const gp_Pnt& P)
{ pos.SetLocation(P); }
inline void gp_Parab::SetPosition (const gp_Ax2& A2)
{ pos = A2; }
inline const gp_Ax1& gp_Parab::Axis () const
{ return pos.Axis(); }
inline gp_Ax1 gp_Parab::Directrix() const
{
const gp_Pnt& PP = pos.Location ();
const gp_Dir& DD = pos.XDirection();
gp_Pnt P (PP.X() - focalLength * DD.X(),
PP.Y() - focalLength * DD.Y(),
PP.Z() - focalLength * DD.Z());
return gp_Ax1 (P, pos.YDirection());
}
inline Standard_Real gp_Parab::Focal() const
{ return focalLength; }
inline gp_Pnt gp_Parab::Focus() const
{
const gp_Pnt& PP = pos.Location ();
const gp_Dir& DD = pos.XDirection();
return gp_Pnt (PP.X() + focalLength * DD.X(),
PP.Y() + focalLength * DD.Y(),
PP.Z() + focalLength * DD.Z());
}
inline const gp_Pnt& gp_Parab::Location () const
{ return pos.Location(); }
inline Standard_Real gp_Parab::Parameter() const
{ return 2.0 * focalLength; }
inline const gp_Ax2& gp_Parab::Position() const
{ return pos; }
inline gp_Ax1 gp_Parab::XAxis () const
{ return gp_Ax1 (pos.Location(), pos.XDirection()); }
inline gp_Ax1 gp_Parab::YAxis () const
{ return gp_Ax1 (pos.Location(), pos.YDirection()); }
inline void gp_Parab::Rotate (const gp_Ax1& A1,
const Standard_Real Ang)
{ pos.Rotate (A1, Ang); }
inline gp_Parab gp_Parab::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Parab Prb = *this;
Prb.pos.Rotate (A1, Ang);
return Prb;
}
inline void gp_Parab::Scale (const gp_Pnt& P,
const Standard_Real S)
{
focalLength *= S;
if (focalLength < 0) focalLength = - focalLength;
pos.Scale (P, S);
}
inline gp_Parab gp_Parab::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Parab Prb = *this;
Prb.focalLength *= S;
if (Prb.focalLength < 0) Prb.focalLength = - Prb.focalLength;
Prb.pos.Scale (P, S);
return Prb;
}
inline void gp_Parab::Transform (const gp_Trsf& T)
{
focalLength *= T.ScaleFactor();
if (focalLength < 0) focalLength = - focalLength;
pos.Transform (T);
}
inline gp_Parab gp_Parab::Transformed (const gp_Trsf& T) const
{
gp_Parab Prb = *this;
Prb.focalLength *= T.ScaleFactor();
if (Prb.focalLength < 0) Prb.focalLength = - Prb.focalLength;
Prb.pos.Transform (T);
return Prb;
}
inline void gp_Parab::Translate (const gp_Vec& V)
{ pos.Translate (V); }
inline gp_Parab gp_Parab::Translated (const gp_Vec& V) const
{
gp_Parab Prb = *this;
Prb.pos.Translate (V);
return Prb;
}
inline void gp_Parab::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{ pos.Translate (P1, P2); }
inline gp_Parab gp_Parab::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Parab Prb = *this;
Prb.pos.Translate (P1, P2);
return Prb;
}

277
src/gp/gp_Parab2d.cdl Executable file
View File

@@ -0,0 +1,277 @@
---Copyright: Matra Datavision 1991
class Parab2d from gp inherits Storable
---Purpose: Describes a parabola in the plane (2D space).
-- A parabola is defined by its focal length (that is, the
-- distance between its focus and apex) and positioned in
-- the plane with a coordinate system (a gp_Ax22d object) where:
-- - the origin of the coordinate system is on the apex of
-- the parabola, and
-- - the "X Axis" of the coordinate system is the axis of
-- symmetry; the parabola is on the positive side of this axis.
-- This coordinate system is the "local coordinate system"
-- of the parabola. Its orientation (direct or indirect sense)
-- gives an implicit orientation to the parabola.
-- In this coordinate system, the equation for the parabola is:
-- Y**2 = (2*P) * X.
-- where P, referred to as the parameter of the parabola, is
-- the distance between the focus and the directrix (P is
-- twice the focal length).
-- See Also
-- GCE2d_MakeParab2d which provides functions for
-- more complex parabola constructions
-- Geom2d_Parabola which provides additional functions
-- for constructing parabolas and works, in particular, with
-- the parametric equations of parabolas
uses Ax2d from gp,
Ax22d from gp,
Pnt2d from gp,
Trsf2d from gp,
Vec2d from gp
raises ConstructionError from Standard
is
Create returns Parab2d;
---C++: inline
--- Purpose : Creates an indefinite parabola.
Create (MirrorAxis : Ax2d;
Focal : Real;
Sense : Boolean from Standard = Standard_True) returns Parab2d
---C++: inline
--- Purpose :
-- Creates a parabola with its vertex point, its axis of symmetry
-- ("XAxis") and its focal length.
-- The sense of parametrization is given by Sense.
-- Warnings : It is possible to have Focal = 0.
-- Raises ConstructionError if Focal < 0.0
raises ConstructionError;
Create (A : Ax22d;
Focal : Real) returns Parab2d
---C++: inline
--- Purpose :
-- Creates a parabola with its vertex point, its axis of symmetry
-- ("XAxis") and its focal length.
-- The sense of parametrization is given by A.
-- Warnings : It is possible to have Focal = 0.
-- Raises ConstructionError if Focal < 0.0
raises ConstructionError;
Create (D : Ax2d;
F : Pnt2d;
Sense : Boolean from Standard = Standard_True) returns Parab2d;
--- Purpose :
-- Creates a parabola with the directrix and the focus point.
-- The sense of parametrization is given by Sense.
Create (D : Ax22d; F : Pnt2d) returns Parab2d;
--- Purpose :
-- Creates a parabola with the directrix and the focus point.
-- The Sense of parametrization is given by D.
SetFocal (me : in out; Focal : Real)
---C++: inline
--- Purpose :
-- Changes the focal distance of the parabola
-- Warnings : It is possible to have Focal = 0.
-- Raises ConstructionError if Focal < 0.0
raises ConstructionError
is static;
SetLocation (me : in out; P : Pnt2d) is static;
---C++: inline
--- Purpose :
-- Changes the "Location" point of the parabola. It is the
-- vertex of the parabola.
SetMirrorAxis (me : in out; A : Ax2d) is static;
---C++: inline
--- Purpose : Modifies this parabola, by redefining its local coordinate system so that
-- its origin and "X Direction" become those of the axis
-- MA. The "Y Direction" of the local coordinate system is
-- then recomputed. The orientation of the local
-- coordinate system is not modified.
SetAxis (me : in out; A : Ax22d) is static;
---C++: inline
--- Purpose :
-- Changes the local coordinate system of the parabola.
-- The "Location" point of A becomes the vertex of the parabola.
Coefficients (me; A, B, C, D, E, F : out Real) is static;
--- Purpose :
-- Computes the coefficients of the implicit equation of the parabola.
-- A * (X**2) + B * (Y**2) + 2*C*(X*Y) + 2*D*X + 2*E*Y + F = 0.
Directrix (me) returns Ax2d is static;
---C++: inline
--- Purpose :
-- Computes the directrix of the parabola.
-- The directrix is:
-- - a line parallel to the "Y Direction" of the local
-- coordinate system of this parabola, and
-- - located on the negative side of the axis of symmetry,
-- at a distance from the apex which is equal to the focal length of this parabola.
-- The directrix is returned as an axis (a gp_Ax2d object),
-- the origin of which is situated on the "X Axis" of this parabola.
Focal (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the distance between the vertex and the focus
-- of the parabola.
Focus (me) returns Pnt2d is static;
---C++: inline
--- Purpose : Returns the focus of the parabola.
Location (me) returns Pnt2d is static;
---C++: inline
--- Purpose : Returns the vertex of the parabola.
MirrorAxis (me) returns Ax2d is static;
---C++: inline
--- Purpose :
-- Returns the symmetry axis of the parabola.
-- The "Location" point of this axis is the vertex of the parabola.
Axis (me) returns Ax22d is static;
---C++: inline
--- Purpose :
-- Returns the local coordinate system of the parabola.
-- The "Location" point of this axis is the vertex of the parabola.
Parameter (me) returns Real is static;
---C++: inline
--- Purpose :
-- Returns the distance between the focus and the
-- directrix of the parabola.
Reverse (me : in out) is static;
---C++: inline
Reversed (me) returns Parab2d is static;
---C++: inline
---Purpose:
-- Reverses the orientation of the local coordinate system
-- of this parabola (the "Y Direction" is reversed).
-- Therefore, the implicit orientation of this parabola is reversed.
-- Note:
-- - Reverse assigns the result to this parabola, while
-- - Reversed creates a new one.
IsDirect (me) returns Boolean is static;
---C++: inline
--- Purpose : Returns true if the local coordinate system is direct
-- and false in the other case.
Mirror (me : in out; P : Pnt2d) is static;
Mirrored (me; P : Pnt2d) returns Parab2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a parabola with respect
-- to the point P which is the center of the symmetry
Mirror (me : in out; A : Ax2d) is static;
Mirrored (me; A : Ax2d) returns Parab2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a parabola with respect
-- to an axis placement which is the axis of the symmetry.
Rotate (me : in out; P : Pnt2d; Ang : Real) is static;
---C++: inline
Rotated (me; P : Pnt2d; Ang : Real) returns Parab2d is static;
---C++: inline
--- Purpose :
-- Rotates a parabola. P is the center of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt2d; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt2d; S : Real) returns Parab2d is static;
---C++: inline
--- Purpose :
-- Scales a parabola. S is the scaling value.
-- If S is negative the direction of the symmetry axis
-- "XAxis" is reversed and the direction of the "YAxis" too.
Transform (me : in out; T : Trsf2d) is static;
---C++: inline
Transformed (me; T : Trsf2d) returns Parab2d is static;
---C++: inline
--- Purpose :
-- Transforms an parabola with the transformation T from class Trsf2d.
Translate (me : in out; V : Vec2d) is static;
---C++: inline
Translated (me; V : Vec2d) returns Parab2d is static;
---C++: inline
--- Purpose :
-- Translates a parabola in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt2d ) is static;
---C++: inline
Translated (me; P1, P2 : Pnt2d) returns Parab2d is static;
---C++: inline
--- Purpose :
-- Translates a parabola from the point P1 to the point P2.
fields
pos : Ax22d;
focalLength : Real;
end;

83
src/gp/gp_Parab2d.cxx Executable file
View File

@@ -0,0 +1,83 @@
//File gp_Parab2d.cxx JCV 10/01/91
#define No_Standard_OutOfRange
#include <gp_Parab2d.ixx>
gp_Parab2d::gp_Parab2d (const gp_Ax22d& D,
const gp_Pnt2d& F)
{
gp_XY DCoord = D.XDirection().XY();
gp_XY GCoord = D.YDirection().XY();
gp_XY PCoord = D.Location().XY();
gp_XY MCoord = F.XY();
focalLength = DCoord.Dot ( MCoord.Subtracted (PCoord));
if (focalLength < 0) focalLength = - focalLength;
gp_XY N = GCoord;
N.Multiply (focalLength);
MCoord.Add (N);
N.Reverse();
pos = gp_Ax22d (gp_Pnt2d (MCoord), gp_Dir2d (N));
focalLength = focalLength / 2.0;
}
gp_Parab2d::gp_Parab2d (const gp_Ax2d& D,
const gp_Pnt2d& F,
const Standard_Boolean Sense)
{
gp_XY DCoord = D.Direction().XY();
gp_XY PCoord = D.Location().XY();
gp_XY MCoord = F.XY();
focalLength = DCoord.Dot ( MCoord.Subtracted (PCoord));
if (focalLength < 0) focalLength = - focalLength;
gp_XY N;
if (Sense) N.SetCoord(DCoord.Y(), -DCoord.X());
else N.SetCoord(-DCoord.Y(), DCoord.X());
N.Multiply (focalLength);
MCoord.Add (N);
N.Reverse();
pos = gp_Ax22d (gp_Pnt2d (MCoord), gp_Dir2d (N),Sense);
focalLength = focalLength / 2.0;
}
void gp_Parab2d::Coefficients
(Standard_Real& A, Standard_Real& B, Standard_Real& C,
Standard_Real& D, Standard_Real& E, Standard_Real& F) const
{
Standard_Real P = 2.0 * focalLength;
gp_Trsf2d T;
T.SetTransformation (pos.XAxis());
Standard_Real T11 = T.Value (1, 1);
Standard_Real T12 = T.Value (1, 2);
Standard_Real T13 = T.Value (1, 3);
Standard_Real T21 = T.Value (2, 1);
Standard_Real T22 = T.Value (2, 2);
Standard_Real T23 = T.Value (2, 3);
A = T21 * T21;
B = T22 * T22;
C = T21 * T22;
D = (T21 * T23) - (P * T11);
E = (T22 * T23) - (P * T12);
F = (T23 * T23) - (2.0 * P * T13);
}
void gp_Parab2d::Mirror (const gp_Pnt2d& P)
{ pos.Mirror (P); }
gp_Parab2d gp_Parab2d::Mirrored (const gp_Pnt2d& P) const
{
gp_Parab2d Prb = *this;
Prb.pos.Mirror (P);
return Prb;
}
void gp_Parab2d::Mirror (const gp_Ax2d& A)
{ pos.Mirror (A); }
gp_Parab2d gp_Parab2d::Mirrored (const gp_Ax2d& A) const
{
gp_Parab2d Prb = *this;
Prb.pos.Mirror (A);
return Prb;
}

154
src/gp/gp_Parab2d.lxx Executable file
View File

@@ -0,0 +1,154 @@
//File gp_Parab2d.lxx
#include <Standard_ConstructionError.hxx>
inline gp_Parab2d::gp_Parab2d () :
focalLength(RealLast())
{ }
inline gp_Parab2d::gp_Parab2d (const gp_Ax22d& A,
const Standard_Real Focal) :
pos (A),
focalLength (Focal)
{ Standard_ConstructionError_Raise_if(Focal < 0.0,""); }
inline gp_Parab2d::gp_Parab2d (const gp_Ax2d& MirrorAxis,
const Standard_Real Focal,
const Standard_Boolean Sense) :
focalLength (Focal)
{
pos = gp_Ax22d(MirrorAxis,Sense);
Standard_ConstructionError_Raise_if(Focal < 0.0,"");
}
inline void gp_Parab2d::SetFocal (const Standard_Real Focal)
{
Standard_ConstructionError_Raise_if(Focal < 0.0,"");
focalLength = Focal;
}
inline void gp_Parab2d::SetLocation (const gp_Pnt2d& P)
{ pos.SetLocation(P); }
inline void gp_Parab2d::SetMirrorAxis (const gp_Ax2d& A)
{ pos.SetXAxis(A); }
inline void gp_Parab2d::SetAxis (const gp_Ax22d& A)
{ pos.SetAxis(A); }
inline gp_Ax2d gp_Parab2d::Directrix() const
{
gp_Pnt2d P (pos.Location().X() - focalLength * pos.XDirection().X(),
pos.Location().Y() - focalLength * pos.XDirection().Y() );
gp_Dir2d V (pos.YDirection().Reversed());
return gp_Ax2d (P, V);
}
inline Standard_Real gp_Parab2d::Focal() const
{ return focalLength; }
inline gp_Pnt2d gp_Parab2d::Focus() const
{
return gp_Pnt2d (pos.Location().X() + focalLength * pos.XDirection().X(),
pos.Location().Y() + focalLength * pos.XDirection().Y());
}
inline gp_Pnt2d gp_Parab2d::Location () const
{ return pos.Location(); }
inline gp_Ax2d gp_Parab2d::MirrorAxis () const
{ return pos.XAxis(); }
inline gp_Ax22d gp_Parab2d::Axis () const
{ return pos; }
inline Standard_Real gp_Parab2d::Parameter() const
{ return 2.0 * focalLength; }
inline void gp_Parab2d::Reverse()
{
gp_Dir2d Temp = pos.YDirection ();
Temp.Reverse ();
pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp));
}
inline gp_Parab2d gp_Parab2d::Reversed() const
{
gp_Parab2d P = *this;
gp_Dir2d Temp = pos.YDirection ();
Temp.Reverse ();
P.pos.SetAxis(gp_Ax22d(pos.Location(),pos.XDirection(),Temp));
return P;
}
inline Standard_Boolean gp_Parab2d::IsDirect() const
{ return (pos.XDirection().Crossed(pos.YDirection())) >= 0.0; }
inline void gp_Parab2d::Rotate (const gp_Pnt2d& P,
const Standard_Real Ang)
{pos.Rotate (P, Ang);}
inline gp_Parab2d gp_Parab2d::Rotated (const gp_Pnt2d& P,
const Standard_Real Ang) const
{
gp_Parab2d Prb = *this;
Prb.pos.Rotate (P, Ang);
return Prb;
}
inline void gp_Parab2d::Scale (const gp_Pnt2d& P,
const Standard_Real S)
{
focalLength *= S;
if (focalLength < 0) focalLength = - focalLength;
pos.Scale (P, S);
}
inline gp_Parab2d gp_Parab2d::Scaled (const gp_Pnt2d& P,
const Standard_Real S) const
{
gp_Parab2d Prb = *this;
Prb.focalLength *= S;
if (Prb.focalLength < 0) Prb.focalLength = - Prb.focalLength;
Prb.pos.Scale (P, S);
return Prb;
}
inline void gp_Parab2d::Transform (const gp_Trsf2d& T)
{
focalLength *= T.ScaleFactor();
if (focalLength < 0) focalLength = - focalLength;
pos.Transform (T);
}
inline gp_Parab2d gp_Parab2d::Transformed (const gp_Trsf2d& T) const
{
gp_Parab2d Prb = *this;
Prb.focalLength *= T.ScaleFactor();
if (Prb.focalLength < 0) Prb.focalLength = - Prb.focalLength;
Prb.pos.Transform (T);
return Prb;
}
inline void gp_Parab2d::Translate (const gp_Vec2d& V)
{ pos.Translate (V); }
inline gp_Parab2d gp_Parab2d::Translated (const gp_Vec2d& V) const
{
gp_Parab2d Prb = *this;
Prb.pos.Translate(V);
return Prb;
}
inline void gp_Parab2d::Translate (const gp_Pnt2d& P1,
const gp_Pnt2d& P2)
{ pos.Translate (P1, P2); }
inline gp_Parab2d gp_Parab2d::Translated (const gp_Pnt2d& P1,
const gp_Pnt2d& P2) const
{
gp_Parab2d Prb = *this;
Prb.pos.Translate (P1, P2);
return Prb;
}

302
src/gp/gp_Pln.cdl Executable file
View File

@@ -0,0 +1,302 @@
---Copyright: Matra Datavision 1991
class Pln from gp inherits Storable
--- Purpose :Describes a plane.
-- A plane is positioned in space with a coordinate system
-- (a gp_Ax3 object), such that the plane is defined by the
-- origin, "X Direction" and "Y Direction" of this coordinate
-- system, which is the "local coordinate system" of the
-- plane. The "main Direction" of the coordinate system is a
-- vector normal to the plane. It gives the plane an implicit
-- orientation such that the plane is said to be "direct", if the
-- coordinate system is right-handed, or "indirect" in the other case.
-- Note: when a gp_Pln plane is converted into a
-- Geom_Plane plane, some implicit properties of its local
-- coordinate system are used explicitly:
-- - its origin defines the origin of the two parameters of
-- the planar surface,
-- - its implicit orientation is also that of the Geom_Plane.
-- See Also
-- gce_MakePln which provides functions for more complex
-- plane constructions
-- Geom_Plane which provides additional functions for
-- constructing planes and works, in particular, with the
-- parametric equations of planes
uses Ax1 from gp,
Ax2 from gp,
Ax3 from gp,
Dir from gp,
Lin from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard
is
Create returns Pln;
---C++:inline
--- Purpose : Creates a plane coincident with OXY plane of the
-- reference coordinate system.
Create (A3 : Ax3) returns Pln;
---C++:inline
--- Purpose :
-- The coordinate system of the plane is defined with the axis
-- placement A3.
-- The "Direction" of A3 defines the normal to the plane.
-- The "Location" of A3 defines the location (origin) of the plane.
-- The "XDirection" and "YDirection" of A3 define the "XAxis" and
-- the "YAxis" of the plane used to parametrize the plane.
Create (P : Pnt; V : Dir) returns Pln;
--- Purpose :
-- Creates a plane with the "Location" point <P>
-- and the normal direction <V>.
Create (A, B, C, D : Real) returns Pln
--- Purpose :
-- Creates a plane from its cartesian equation :
-- A * X + B * Y + C * Z + D = 0.0
-- Raises ConstructionError if Sqrt (A*A + B*B + C*C) <= Resolution from gp.
raises ConstructionError;
Coefficients (me; A, B ,C ,D : out Real) is static;
---C++:inline
--- Purpose :
-- Returns the coefficients of the plane's cartesian equation :
-- A * X + B * Y + C * Z + D = 0.
SetAxis (me : in out; A1 : Ax1)
---C++: inline
--- Purpose : Modifies this plane, by redefining its local coordinate system so that
-- - its origin and "main Direction" become those of the
-- axis A1 (the "X Direction" and "Y Direction" are then recomputed).
-- Raises ConstructionError if the A1 is parallel to the "XAxis" of the plane.
raises ConstructionError
is static;
SetLocation (me : in out; Loc : Pnt) is static;
---C++:inline
--- Purpose : Changes the origin of the plane.
SetPosition (me : in out; A3 : Ax3) is static;
---C++:inline
--- Purpose : Changes the local coordinate system of the plane.
UReverse (me : in out)
---C++:inline
---Purpose: Reverses the U parametrization of the plane
-- reversing the XAxis.
is static;
VReverse (me : in out)
---C++:inline
---Purpose: Reverses the V parametrization of the plane
-- reversing the YAxis.
is static;
Direct (me) returns Boolean from Standard
---C++:inline
---Purpose: returns true if the Ax3 is right handed.
is static;
Axis (me) returns Ax1 is static;
---C++:inline
--- Purpose : Returns the plane's normal Axis.
---C++: return const&
Location (me) returns Pnt is static;
--- Purpose : Returns the plane's location (origin).
---C++: inline
---C++: return const&
Position (me) returns Ax3 is static;
--- Purpose : Returns the local coordinate system of the plane .
---C++: inline
---C++: return const&
Distance (me; P : Pnt) returns Real is static;
---C++: inline
--- Purpose : Computes the distance between <me> and the point <P>.
Distance (me; L : Lin) returns Real is static;
---C++: inline
--- Purpose : Computes the distance between <me> and the line <L>.
Distance (me; Other : Pln) returns Real is static;
---C++: inline
--- Purpose : Computes the distance between two planes.
SquareDistance (me; P : Pnt) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the square distance between <me> and the point <P>.
SquareDistance (me; L : Lin) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the square distance between <me> and the line <L>.
SquareDistance (me; Other : Pln) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the square distance between two planes.
XAxis (me) returns Ax1 is static;
---C++:inline
--- Purpose : Returns the X axis of the plane.
YAxis (me) returns Ax1 is static;
---C++:inline
--- Purpose : Returns the Y axis of the plane.
Contains (me; P : Pnt; LinearTolerance : Real) returns Boolean
is static;
---C++: inline
---Purpose: Returns true if this plane contains the point P. This means that
-- - the distance between point P and this plane is less
-- than or equal to LinearTolerance, or
-- - line L is normal to the "main Axis" of the local
-- coordinate system of this plane, within the tolerance
-- AngularTolerance, and the distance between the origin
-- of line L and this plane is less than or equal to
-- LinearTolerance.
Contains (me; L : Lin; LinearTolerance, AngularTolerance : Real)
returns Boolean
is static;
---C++: inline
---Purpose: Returns true if this plane contains the line L. This means that
-- - the distance between point P and this plane is less
-- than or equal to LinearTolerance, or
-- - line L is normal to the "main Axis" of the local
-- coordinate system of this plane, within the tolerance
-- AngularTolerance, and the distance between the origin
-- of line L and this plane is less than or equal to
-- LinearTolerance.
Mirror (me : in out; P : Pnt) is static;
Mirrored (me; P : Pnt) returns Pln is static;
--- Purpose :
-- Performs the symmetrical transformation of a plane with respect
-- to the point <P> which is the center of the symmetry
-- Warnings :
-- The normal direction to the plane is not changed.
-- The "XAxis" and the "YAxis" are reversed.
Mirror (me : in out; A1 : Ax1)
is static;
Mirrored (me; A1 : Ax1) returns Pln is static;
--- Purpose : Performs the symmetrical transformation of a
-- plane with respect to an axis placement which is the axis
-- of the symmetry. The transformation is performed on the
-- "Location" point, on the "XAxis" and the "YAxis". The
-- resulting normal direction is the cross product between
-- the "XDirection" and the "YDirection" after transformation
-- if the initial plane was right handed, else it is the
-- opposite.
Mirror (me : in out; A2 : Ax2)
is static;
Mirrored (me; A2 : Ax2) returns Pln is static;
--- Purpose : Performs the symmetrical transformation of a
-- plane with respect to an axis placement. The axis
-- placement <A2> locates the plane of the symmetry. The
-- transformation is performed on the "Location" point, on
-- the "XAxis" and the "YAxis". The resulting normal
-- direction is the cross product between the "XDirection"
-- and the "YDirection" after transformation if the initial
-- plane was right handed, else it is the opposite.
Rotate (me : in out; A1 : Ax1; Ang : Real)
---C++:inline
is static;
Rotated (me; A1 : Ax1; Ang : Real) returns Pln is static;
---C++: inline
--- Purpose :
-- rotates a plane. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real)
---C++: inline
is static;
Scaled (me; P : Pnt; S : Real) returns Pln is static;
---C++: inline
--- Purpose :
-- Scales a plane. S is the scaling value.
Transform (me : in out; T : Trsf)
---C++: inline
is static;
Transformed (me; T : Trsf) returns Pln is static;
---C++: inline
--- Purpose :
-- Transforms a plane with the transformation T from class Trsf.
-- The transformation is performed on the "Location"
-- point, on the "XAxis" and the "YAxis".
-- The resulting normal direction is the cross product between
-- the "XDirection" and the "YDirection" after transformation.
Translate (me : in out; V : Vec)
---C++: inline
is static;
Translated (me; V : Vec) returns Pln is static;
---C++: inline
--- Purpose :
-- Translates a plane in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt)
---C++: inline
is static;
Translated (me; P1, P2 : Pnt) returns Pln is static;
---C++: inline
--- Purpose :
-- Translates a plane from the point P1 to the point P2.
fields
pos : Ax3;
end;

110
src/gp/gp_Pln.cxx Executable file
View File

@@ -0,0 +1,110 @@
// File gp_Pln.cxx , JCV 03/06/90
// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
// JCV 1/10/90 Changement de nom du package vgeom -> gp
// JCV 12/12/90 Modif suite a la premiere revue de projet
// LPA, JCV 07/92 passage sur C1.
// JCV 07/92 Introduction de la method Dump
// LBO 08/93 Passage aux Ax3
#include <gp_Pln.ixx>
#include <gp.hxx>
gp_Pln::gp_Pln (const gp_Pnt& P,
const gp_Dir& V)
{
Standard_Real A = V.X();
Standard_Real B = V.Y();
Standard_Real C = V.Z();
Standard_Real Aabs = A;
if (Aabs < 0) Aabs = - Aabs;
Standard_Real Babs = B;
if (Babs < 0) Babs = - Babs;
Standard_Real Cabs = C;
if (Cabs < 0) Cabs = - Cabs;
// pour determiner l'axe X :
// on dit que le produit scalaire Vx.V = 0.
// et on recherche le max(A,B,C) pour faire la division.
// l'une des coordonnees du vecteur est nulle.
if( Babs <= Aabs && Babs <= Cabs) {
if (Aabs > Cabs) pos = gp_Ax3 (P, V, gp_Dir (-C,0., A));
else pos = gp_Ax3 (P, V, gp_Dir ( C,0.,-A));
}
else if( Aabs <= Babs && Aabs <= Cabs) {
if (Babs > Cabs) pos = gp_Ax3 (P, V, gp_Dir (0.,-C, B));
else pos = gp_Ax3 (P, V, gp_Dir (0., C,-B));
}
else {
if (Aabs > Babs) pos = gp_Ax3 (P, V, gp_Dir (-B, A,0.));
else pos = gp_Ax3 (P, V, gp_Dir ( B,-A,0.));
}
}
gp_Pln::gp_Pln (const Standard_Real A,
const Standard_Real B,
const Standard_Real C,
const Standard_Real D)
{
Standard_Real Aabs = A;
if (Aabs < 0) Aabs = - Aabs;
Standard_Real Babs = B;
if (Babs < 0) Babs = - Babs;
Standard_Real Cabs = C;
if (Cabs < 0) Cabs = - Cabs;
if (Babs <= Aabs && Babs <= Cabs) {
if (Aabs > Cabs) pos = gp_Ax3(gp_Pnt(-D/A, 0., 0.),
gp_Dir(A,B,C),
gp_Dir(-C,0., A));
else pos = gp_Ax3(gp_Pnt( 0., 0.,-D/C),
gp_Dir(A,B,C),
gp_Dir( C,0.,-A));
}
else if (Aabs <= Babs && Aabs <= Cabs) {
if (Babs > Cabs) pos = gp_Ax3(gp_Pnt( 0.,-D/B, 0.),
gp_Dir(A,B,C),
gp_Dir(0.,-C, B));
else pos = gp_Ax3(gp_Pnt( 0., 0.,-D/C),
gp_Dir(A,B,C),
gp_Dir(0., C,-B));
}
else {
if (Aabs > Babs) pos = gp_Ax3(gp_Pnt(-D/A, 0., 0.),
gp_Dir(A,B,C),
gp_Dir(-B, A, 0.));
else pos = gp_Ax3(gp_Pnt( 0.,-D/B, 0.),
gp_Dir(A,B,C),
gp_Dir( B,-A, 0.));
}
}
void gp_Pln::Mirror (const gp_Pnt& P)
{ pos.Mirror(P); }
gp_Pln gp_Pln::Mirrored (const gp_Pnt& P) const
{
gp_Pln Pl = *this;
Pl.pos.Mirror(P);
return Pl;
}
void gp_Pln::Mirror (const gp_Ax1& A1)
{ pos.Mirror(A1); }
gp_Pln gp_Pln::Mirrored (const gp_Ax1& A1) const
{
gp_Pln Pl = *this;
Pl.pos.Mirror(A1);
return Pl;
}
void gp_Pln::Mirror (const gp_Ax2& A2)
{ pos.Mirror(A2); }
gp_Pln gp_Pln::Mirrored (const gp_Ax2& A2) const
{
gp_Pln Pl = *this;
Pl.pos.Mirror(A2);
return Pl;
}

180
src/gp/gp_Pln.lxx Executable file
View File

@@ -0,0 +1,180 @@
// File gp_Pln.lxx , JCV 03/06/90
// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
#include <gp_Lin.hxx>
inline gp_Pln::gp_Pln()
{ }
inline gp_Pln::gp_Pln(const gp_Ax3& A3) : pos(A3)
{ }
inline void gp_Pln::Coefficients (Standard_Real& A,
Standard_Real& B,
Standard_Real& C,
Standard_Real& D) const
{
const gp_Dir& dir = pos.Direction();
if (pos.Direct()) {
A = dir.X();
B = dir.Y();
C = dir.Z();
}
else {
A = -dir.X();
B = -dir.Y();
C = -dir.Z();
}
const gp_Pnt& P = pos.Location();
D = -(A * P.X() + B * P.Y() + C * P.Z());
}
inline void gp_Pln::SetAxis (const gp_Ax1& A1)
{ pos.SetAxis (A1); }
inline void gp_Pln::SetLocation (const gp_Pnt& Loc)
{ pos.SetLocation (Loc); }
inline void gp_Pln::SetPosition (const gp_Ax3& A3)
{ pos = A3; }
inline void gp_Pln::UReverse ()
{ pos.XReverse(); }
inline void gp_Pln::VReverse ()
{ pos.YReverse(); }
inline Standard_Boolean gp_Pln::Direct()const
{ return pos.Direct(); }
inline const gp_Ax1& gp_Pln::Axis() const
{ return pos.Axis(); }
inline const gp_Pnt& gp_Pln::Location() const
{ return pos.Location(); }
inline const gp_Ax3& gp_Pln::Position() const
{ return pos; }
inline Standard_Real gp_Pln::Distance(const gp_Pnt& P) const
{
const gp_Pnt& loc = pos.Location ();
const gp_Dir& dir = pos.Direction();
Standard_Real D = (dir.X() * (P.X() - loc.X()) +
dir.Y() * (P.Y() - loc.Y()) +
dir.Z() * (P.Z() - loc.Z()));
if (D < 0) D = - D;
return D;
}
inline Standard_Real gp_Pln::Distance (const gp_Lin& L) const
{
Standard_Real D = 0.0;
if ((pos.Direction()).IsNormal (L.Direction(), gp::Resolution())) {
const gp_Pnt& P = L .Location ();
const gp_Pnt& loc = pos.Location ();
const gp_Dir& dir = pos.Direction();
D = (dir.X() * (P.X() - loc.X()) +
dir.Y() * (P.Y() - loc.Y()) +
dir.Z() * (P.Z() - loc.Z()));
if (D < 0) D = - D;
}
return D;
}
inline Standard_Real gp_Pln::Distance(const gp_Pln& Other) const
{
Standard_Real D = 0.0;
if ((pos.Direction()).IsParallel(Other.pos.Direction(), gp::Resolution())){
const gp_Pnt& P = Other.pos.Location();
const gp_Pnt& loc = pos.Location ();
const gp_Dir& dir = pos.Direction();
D = (dir.X() * (P.X() - loc.X()) +
dir.Y() * (P.Y() - loc.Y()) +
dir.Z() * (P.Z() - loc.Z()));
if (D < 0) D = - D;
}
return D;
}
inline Standard_Real gp_Pln::SquareDistance (const gp_Pnt& P) const
{ Standard_Real D = Distance(P); return D * D; }
inline Standard_Real gp_Pln::SquareDistance (const gp_Lin& L) const
{ Standard_Real D = Distance(L); return D * D; }
inline Standard_Real gp_Pln::SquareDistance (const gp_Pln& Other) const
{ Standard_Real D = Distance(Other); return D * D; }
inline gp_Ax1 gp_Pln::XAxis () const
{ return gp_Ax1 (pos.Location(), pos.XDirection()); }
inline gp_Ax1 gp_Pln::YAxis () const
{ return gp_Ax1 (pos.Location(), pos.YDirection()); }
inline Standard_Boolean gp_Pln::Contains
(const gp_Pnt& P,
const Standard_Real LinearTolerance) const
{ return Distance(P) <= LinearTolerance; }
inline Standard_Boolean gp_Pln::Contains
(const gp_Lin& L,
const Standard_Real LinearTolerance,
const Standard_Real AngularTolerance) const
{ return Contains(L.Location(), LinearTolerance) &&
pos.Direction().IsNormal(L.Direction(), AngularTolerance);
}
inline void gp_Pln::Rotate (const gp_Ax1& A1, const Standard_Real Ang)
{ pos.Rotate(A1, Ang); }
inline gp_Pln gp_Pln::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Pln Pl = *this;
Pl.pos.Rotate(A1, Ang);
return Pl;
}
inline void gp_Pln::Scale (const gp_Pnt& P, const Standard_Real S)
{ pos.Scale(P, S); }
inline gp_Pln gp_Pln::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Pln Pl = *this;
Pl.pos.Scale(P, S);
return Pl;
}
inline void gp_Pln::Transform (const gp_Trsf& T)
{ pos.Transform(T); }
inline gp_Pln gp_Pln::Transformed (const gp_Trsf& T) const
{
gp_Pln Pl = *this;
Pl.pos.Transform(T);
return Pl;
}
inline void gp_Pln::Translate (const gp_Vec& V)
{ pos.Translate(V); }
inline gp_Pln gp_Pln::Translated (const gp_Vec& V) const
{
gp_Pln Pl = *this;
Pl.pos.Translate(V);
return Pl;
}
inline void gp_Pln::Translate (const gp_Pnt& P1, const gp_Pnt& P2)
{ pos.Translate(P1,P2); }
inline gp_Pln gp_Pln::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Pln Pl = *this;
Pl.pos.Translate(P1, P2);
return Pl;
}

203
src/gp/gp_Pnt.cdl Executable file
View File

@@ -0,0 +1,203 @@
---Copyright: Matra Datavision 1991
class Pnt from gp inherits Storable
--- Purpose : Defines a 3D cartesian point.
uses Ax1 from gp,
Ax2 from gp,
Trsf from gp,
Vec from gp,
XYZ from gp
raises OutOfRange from Standard
is
Create returns Pnt;
---C++: inline
---Purpose : Creates a point with zero coordinates.
Create (Coord : XYZ) returns Pnt;
---C++: inline
--- Purpose : Creates a point from a XYZ object.
Create (Xp, Yp, Zp : Real) returns Pnt;
---C++:inline
--- Purpose :
-- Creates a point with its 3 cartesian's coordinates : Xp, Yp, Zp.
SetCoord (me : in out; Index : Integer; Xi : Real)
---C++:inline
--- Purpose :
-- Changes the coordinate of range Index :
-- Index = 1 => X is modified
-- Index = 2 => Y is modified
-- Index = 3 => Z is modified
raises OutOfRange
--- Purpose : Raised if Index != {1, 2, 3}.
is static;
SetCoord (me : in out; Xp, Yp, Zp : Real)
---C++: inline
---Purpose: For this point, assigns the values Xp, Yp and Zp to its three coordinates.
is static;
SetX (me : in out; X : Real)
---C++: inline
---Purpose: Assigns the given value to the X coordinate of this point.
is static;
SetY (me : in out; Y : Real)
---C++: inline
---Purpose: Assigns the given value to the Y coordinate of this point.
is static;
SetZ (me : in out; Z : Real)
---C++: inline
---Purpose: Assigns the given value to the Z coordinate of this point.
is static;
SetXYZ (me : in out; Coord : XYZ)
---C++: inline
---Purpose: Assigns the three coordinates of Coord to this point.
is static;
Coord (me; Index : Integer) returns Real
--- Purpose :
-- Returns the coordinate of corresponding to the value of Index :
-- Index = 1 => X is returned
-- Index = 2 => Y is returned
-- Index = 3 => Z is returned
-- Raises OutOfRange if Index != {1, 2, 3}.
raises OutOfRange
---C++: inline
--- Purpose : Raised if Index != {1, 2, 3}.
is static;
Coord (me; Xp, Yp, Zp : out Real)
---C++: inline
---Purpose: For this point gives its three coordinates Xp, Yp and Zp.
is static;
X (me) returns Real
---C++: inline
---Purpose: For this point, returns its X coordinate.
is static;
Y (me) returns Real
---C++: inline
---Purpose: For this point, returns its Y coordinate.
is static;
Z (me) returns Real
---C++: inline
---Purpose: For this point, returns its Z coordinate.
is static;
XYZ (me) returns XYZ is static;
---C++: inline
---C++: return const &
---Purpose: For this point, returns its three coordinates as a XYZ object.
Coord (me) returns XYZ is static;
---C++: inline
---C++: return const &
---Purpose: For this point, returns its three coordinates as a XYZ object.
ChangeCoord (me : in out) returns XYZ is static;
---C++: inline
---C++: return &
--- Purpose:
-- Returns the coordinates of this point.
-- Note: This syntax allows direct modification of the returned value.
BaryCenter(me : in out; Alpha : Real; P : Pnt from gp; Beta : Real);
---C++: inline
---Purpose: Assigns the result of the following expression to this point
-- (Alpha*this + Beta*P) / (Alpha + Beta)
IsEqual (me; Other : Pnt; LinearTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose : Comparison
-- Returns True if the distance between the two points is
-- lower or equal to LinearTolerance.
Distance (me; Other : Pnt) returns Real is static;
---C++: inline
--- Purpose : Computes the distance between two points.
SquareDistance (me; Other : Pnt) returns Real is static;
---C++: inline
--- Purpose : Computes the square distance between two points.
Mirror (me : in out; P : Pnt) is static;
--- Purpose :
-- Performs the symmetrical transformation of a point
-- with respect to the point P which is the center of
-- the symmetry.
Mirrored (me; P : Pnt) returns Pnt is static;
--- Purpose :
-- Performs the symmetrical transformation of a point
-- with respect to an axis placement which is the axis
-- of the symmetry.
Mirror (me : in out; A1 : Ax1) is static;
Mirrored (me; A1 : Ax1) returns Pnt is static;
--- Purpose :
-- Performs the symmetrical transformation of a point
-- with respect to a plane. The axis placement A2 locates
-- the plane of the symmetry : (Location, XDirection, YDirection).
Mirror (me : in out; A2 : Ax2) is static;
Mirrored (me; A2 : Ax2) returns Pnt is static;
--- Purpose :
-- Rotates a point. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
---C++: inline
Rotated (me; A1 : Ax1; Ang : Real) returns Pnt is static;
---C++: inline
--- Purpose : Scales a point. S is the scaling value.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt; S : Real) returns Pnt is static;
---C++: inline
--- Purpose : Transforms a point with the transformation T.
Transform (me : in out; T : Trsf) is static;
Transformed (me; T : Trsf) returns Pnt is static;
---C++: inline
--- Purpose :
-- Translates a point in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; V : Vec) is static;
---C++: inline
Translated (me; V : Vec) returns Pnt is static;
---C++: inline
--- Purpose :
-- Translates a point from the point P1 to the point P2.
Translate (me : in out; P1, P2 : Pnt) is static;
---C++: inline
Translated (me; P1, P2 : Pnt) returns Pnt is static;
---C++: inline
fields
coord : XYZ;
end;

67
src/gp/gp_Pnt.cxx Executable file
View File

@@ -0,0 +1,67 @@
// File gp_Pnt.cxx, JCV 03/06/90
// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
// JCV 01/10/90 Changement de nom du package vgeom -> gp
// JCV 07/12/90 Modifs introduction des classes XYZ, Mat dans le package gp
#define No_Standard_OutOfRange
#include <gp_Pnt.ixx>
void gp_Pnt::Transform (const gp_Trsf& T)
{
if (T.Form() == gp_Identity) { }
else if (T.Form() == gp_Translation) { coord.Add (T.TranslationPart ()); }
else if (T.Form() == gp_Scale) {
coord.Multiply (T.ScaleFactor ());
coord.Add (T.TranslationPart ());
}
else if(T.Form() == gp_PntMirror) {
coord.Reverse ();
coord.Add (T.TranslationPart ());
}
else { T.Transforms(coord); }
}
void gp_Pnt::Mirror (const gp_Pnt& P)
{
coord.Reverse ();
gp_XYZ XYZ = P.coord;
XYZ.Multiply (2.0);
coord.Add (XYZ);
}
gp_Pnt gp_Pnt::Mirrored (const gp_Pnt& P) const
{
gp_Pnt Pres = *this;
Pres.Mirror (P);
return Pres;
}
void gp_Pnt::Mirror (const gp_Ax1& A1)
{
gp_Trsf T;
T.SetMirror (A1);
T.Transforms (coord);
}
gp_Pnt gp_Pnt::Mirrored (const gp_Ax1& A1) const
{
gp_Pnt P = *this;
P.Mirror (A1);
return P;
}
void gp_Pnt::Mirror (const gp_Ax2& A2)
{
gp_Trsf T;
T.SetMirror (A2);
T.Transforms (coord);
}
gp_Pnt gp_Pnt::Mirrored (const gp_Ax2& A2) const
{
gp_Pnt P = *this;
P.Mirror (A2);
return P;
}

165
src/gp/gp_Pnt.lxx Executable file
View File

@@ -0,0 +1,165 @@
// File gp_Pnt.lxx , JCV 03/06/90
// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
// JCV 06/12/90 Modif introduction des classes XYZ Mat dans le package gp
// Modif DPF 23/06/93 Ajout fonction Coord pour genericite 2d 3d
#include <gp_Trsf.hxx>
#include <gp_Vec.hxx>
inline gp_Pnt::gp_Pnt() { }
inline gp_Pnt::gp_Pnt (const gp_XYZ& Coordinates) : coord (Coordinates)
{ }
inline gp_Pnt::gp_Pnt (const Standard_Real Xp,
const Standard_Real Yp,
const Standard_Real Zp) : coord(Xp, Yp,Zp)
{ }
inline void gp_Pnt::SetCoord (const Standard_Integer Index,
const Standard_Real Xi)
{ coord.SetCoord (Index, Xi); }
inline void gp_Pnt::SetCoord (const Standard_Real Xp,
const Standard_Real Yp,
const Standard_Real Zp) {
coord.SetCoord (Xp, Yp, Zp);
}
inline void gp_Pnt::SetX (const Standard_Real X)
{ coord.SetX (X); }
inline void gp_Pnt::SetY (const Standard_Real Y)
{ coord.SetY (Y); }
inline void gp_Pnt::SetZ (const Standard_Real Z)
{ coord.SetZ (Z); }
inline void gp_Pnt::SetXYZ (const gp_XYZ& Coordinates)
{ coord = Coordinates; }
inline Standard_Real gp_Pnt::Coord (const Standard_Integer Index) const
{ return coord.Coord(Index); }
inline void gp_Pnt::Coord (Standard_Real& Xp,
Standard_Real& Yp,
Standard_Real& Zp) const {
coord.Coord (Xp, Yp, Zp);
}
inline Standard_Real gp_Pnt::X() const
{ return coord.X(); }
inline Standard_Real gp_Pnt::Y() const
{ return coord.Y(); }
inline Standard_Real gp_Pnt::Z() const
{ return coord.Z(); }
inline const gp_XYZ& gp_Pnt::XYZ () const
{ return coord; }
inline const gp_XYZ& gp_Pnt::Coord () const
{ return coord; }
inline gp_XYZ& gp_Pnt::ChangeCoord ()
{ return coord; }
inline void gp_Pnt::BaryCenter(const Standard_Real A,
const gp_Pnt& P,
const Standard_Real B)
{
coord.SetLinearForm(A,coord,B,P.coord);
coord.Divide(A + B);
}
inline Standard_Boolean gp_Pnt::IsEqual
(const gp_Pnt& Other,
const Standard_Real LinearTolerance) const
{ return Distance (Other) <= LinearTolerance; }
inline Standard_Real gp_Pnt::Distance (const gp_Pnt& Other) const
{
Standard_Real d=0,dd;
const gp_XYZ& XYZ = Other.coord;
dd = coord.X(); dd -= XYZ.X(); dd *= dd; d += dd;
dd = coord.Y(); dd -= XYZ.Y(); dd *= dd; d += dd;
dd = coord.Z(); dd -= XYZ.Z(); dd *= dd; d += dd;
return(sqrt(d));
}
inline Standard_Real gp_Pnt::SquareDistance (const gp_Pnt& Other) const
{
Standard_Real d=0,dd;
const gp_XYZ& XYZ = Other.coord;
dd = coord.X(); dd -= XYZ.X(); dd *= dd; d += dd;
dd = coord.Y(); dd -= XYZ.Y(); dd *= dd; d += dd;
dd = coord.Z(); dd -= XYZ.Z(); dd *= dd; d += dd;
return(d);
}
inline void gp_Pnt::Rotate (const gp_Ax1& A1,
const Standard_Real Ang)
{
gp_Trsf T;
T.SetRotation (A1, Ang);
T.Transforms (coord);
}
inline gp_Pnt gp_Pnt::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Pnt P = *this;
P.Rotate (A1, Ang);
return P;
}
inline void gp_Pnt::Scale (const gp_Pnt& P,
const Standard_Real S)
{
gp_XYZ XYZ = P.coord;
XYZ.Multiply (1.0 - S);
coord.Multiply (S);
coord.Add (XYZ);
}
inline gp_Pnt gp_Pnt::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Pnt Pres = *this;
Pres.Scale (P, S);
return Pres;
}
inline gp_Pnt gp_Pnt::Transformed (const gp_Trsf& T) const
{
gp_Pnt P = *this;
P.Transform (T);
return P;
}
inline void gp_Pnt::Translate (const gp_Vec& V)
{ coord.Add (V.XYZ()); }
inline gp_Pnt gp_Pnt::Translated (const gp_Vec& V) const
{
gp_Pnt P = *this;
P.coord.Add (V.XYZ());
return P;
}
inline void gp_Pnt::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{
coord.Add (P2.coord);
coord.Subtract (P1.coord);
}
inline gp_Pnt gp_Pnt::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Pnt P = *this;
P.Translate (P1 , P2);
return P;
}

177
src/gp/gp_Pnt2d.cdl Executable file
View File

@@ -0,0 +1,177 @@
---Copyright: Matra Datavision 1991
class Pnt2d from gp inherits Storable
--- Purpose : Defines a non-persistent 2D cartesian point.
uses Ax2d from gp,
Trsf2d from gp,
Vec2d from gp,
XY from gp
raises OutOfRange from Standard
is
Create returns Pnt2d;
---C++: inline
---Purpose : Creates a point with zero coordinates.
Create (Coord : XY) returns Pnt2d;
---C++: inline
--- Purpose : Creates a point with a doublet of coordinates.
Create (Xp, Yp : Real) returns Pnt2d;
---C++: inline
--- Purpose :
-- Creates a point with its 2 cartesian's coordinates : Xp, Yp.
SetCoord (me : in out; Index : Integer; Xi : Real)
---C++:inline
--- Purpose :
-- Assigns the value Xi to the coordinate that corresponds to Index:
-- Index = 1 => X is modified
-- Index = 2 => Y is modified
-- Raises OutOfRange if Index != {1, 2}.
raises OutOfRange
is static;
SetCoord (me : in out; Xp, Yp : Real)
---C++: inline
---Purpose: For this point, assigns the values Xp and Yp to its two coordinates
is static;
SetX (me : in out; X : Real)
---C++: inline
---Purpose: Assigns the given value to the X coordinate of this point.
is static;
SetY (me : in out; Y : Real)
---C++: inline
---Purpose: Assigns the given value to the Y coordinate of this point.
is static;
SetXY (me : in out; Coord : XY)
---C++: inline
---Purpose: Assigns the two coordinates of Coord to this point.
is static;
Coord (me; Index : Integer) returns Real
--- Purpose :
-- Returns the coordinate of range Index :
-- Index = 1 => X is returned
-- Index = 2 => Y is returned
-- Raises OutOfRange if Index != {1, 2}.
raises OutOfRange
is static;
Coord (me; Xp, Yp : out Real)
---C++:inline
---Purpose: For this point returns its two coordinates as a number pair.
is static;
X (me) returns Real
---C++:inline
---Purpose: For this point, returns its X coordinate.
is static;
Y (me) returns Real
---C++:inline
---Purpose: For this point, returns its Y coordinate.
is static;
XY (me) returns XY
---C++: inline
---C++: return const&
---Purpose: For this point, returns its two coordinates as a number pair.
is static;
Coord (me) returns XY
---C++: inline
---C++: return const&
---Purpose: For this point, returns its two coordinates as a number pair.
is static;
ChangeCoord (me: in out) returns XY
---C++: inline
---C++: return &
---Purpose:
-- Returns the coordinates of this point.
-- Note: This syntax allows direct modification of the returned value.
is static;
IsEqual (me; Other : Pnt2d; LinearTolerance : Real) returns Boolean
is static;
---C++: inline
--- Purpose : Comparison
-- Returns True if the distance between the two
-- points is lower or equal to LinearTolerance.
Distance (me; Other : Pnt2d) returns Real is static;
---C++: inline
--- Purpose : Computes the distance between two points.
SquareDistance (me; Other : Pnt2d) returns Real is static;
---C++: inline
--- Purpose : Computes the square distance between two points.
Mirror (me : in out; P : Pnt2d) is static;
--- Purpose :
-- Performs the symmetrical transformation of a point
-- with respect to the point P which is the center of
-- the symmetry.
Mirrored (me; P : Pnt2d) returns Pnt2d is static;
--- Purpose :
-- Performs the symmetrical transformation of a point
-- with respect to an axis placement which is the axis
Mirror (me : in out; A : Ax2d) is static;
Mirrored (me; A : Ax2d) returns Pnt2d is static;
--- Purpose :
-- Rotates a point. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Rotate (me : in out; P : Pnt2d; Ang : Real) is static;
---C++: inline
Rotated (me; P : Pnt2d; Ang : Real) returns Pnt2d is static;
---C++: inline
--- Purpose : Scales a point. S is the scaling value.
Scale (me : in out; P : Pnt2d; S : Real) is static;
---C++: inline
Scaled (me; P : Pnt2d; S : Real) returns Pnt2d is static;
---C++: inline
--- Purpose : Transforms a point with the transformation T.
Transform (me : in out; T : Trsf2d) is static;
Transformed (me; T : Trsf2d) returns Pnt2d is static;
---C++: inline
--- Purpose :
-- Translates a point in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; V : Vec2d) is static;
---C++: inline
Translated (me; V : Vec2d) returns Pnt2d is static;
---C++: inline
--- Purpose :
-- Translates a point from the point P1 to the point P2.
Translate (me : in out; P1, P2 : Pnt2d) is static;
---C++: inline
Translated (me; P1, P2 : Pnt2d) returns Pnt2d is static;
---C++: inline
fields
coord : XY;
end;

53
src/gp/gp_Pnt2d.cxx Executable file
View File

@@ -0,0 +1,53 @@
// File gp_Pnt2d.cxx, JCV 06/90
// File gp_Pnt2d.cxx, REG 26/10/90 nouvelle version
// JCV 08/01/91 Modifs introduction des classes XY, Mat2d dans le package gp
#define No_Standard_OutOfRange
#include <gp_Pnt2d.ixx>
void gp_Pnt2d::Transform (const gp_Trsf2d& T)
{
if (T.Form () == gp_Identity) { }
else if (T.Form () == gp_Translation)
{ coord.Add (T.TranslationPart ()); }
else if (T.Form () == gp_Scale) {
coord.Multiply (T.ScaleFactor ());
coord.Add (T.TranslationPart ());
}
else if (T.Form () == gp_PntMirror) {
coord.Reverse ();
coord.Add (T.TranslationPart ());
}
else { T.Transforms(coord); }
}
void gp_Pnt2d::Mirror (const gp_Pnt2d& P)
{
coord.Reverse ();
gp_XY XY = P.coord;
XY.Multiply (2.0);
coord.Add (XY);
}
gp_Pnt2d gp_Pnt2d::Mirrored (const gp_Pnt2d& P) const
{
gp_Pnt2d Pres = *this;
Pres.Mirror (P);
return Pres;
}
void gp_Pnt2d::Mirror (const gp_Ax2d& A)
{
gp_Trsf2d T;
T.SetMirror (A);
T.Transforms (coord);
}
gp_Pnt2d gp_Pnt2d::Mirrored (const gp_Ax2d& A) const
{
gp_Pnt2d P = *this;
P.Mirror (A);
return P;
}

142
src/gp/gp_Pnt2d.lxx Executable file
View File

@@ -0,0 +1,142 @@
// File gp_Pnt2d.lxx , REG 27/10/90
// Modif JCV 08/01/91 modifs suite a la deuxieme revue de projet
// et introduction des classes XY, Mat2d.
// Modif DPF 23/06/93 Ajout fonction Coord pour genericite 2d 3d
#include <gp_Vec2d.hxx>
#include <gp_Ax2d.hxx>
#include <gp_Trsf2d.hxx>
inline gp_Pnt2d::gp_Pnt2d (const gp_XY& Coordinates) : coord (Coordinates)
{ }
inline gp_Pnt2d::gp_Pnt2d (const Standard_Real Xp,
const Standard_Real Yp) : coord (Xp, Yp)
{ }
inline gp_Pnt2d::gp_Pnt2d() { }
inline Standard_Real gp_Pnt2d::Coord(const Standard_Integer Index) const { return coord.Coord(Index); }
inline void gp_Pnt2d::SetX (const Standard_Real X)
{ coord.SetX (X); }
inline void gp_Pnt2d::SetY (const Standard_Real Y)
{ coord.SetY (Y); }
inline void gp_Pnt2d::SetXY (const gp_XY& Coordinates)
{ coord = Coordinates; }
inline void gp_Pnt2d::SetCoord (const Standard_Real Xp,
const Standard_Real Yp)
{ coord.SetCoord (Xp, Yp);}
inline void gp_Pnt2d::SetCoord (const Standard_Integer Index,
const Standard_Real Xi)
{ coord.SetCoord (Index, Xi); }
inline void gp_Pnt2d::Coord (Standard_Real& Xp,
Standard_Real& Yp) const
{ coord.Coord (Xp, Yp); }
inline Standard_Real gp_Pnt2d::X() const
{ return coord.X(); }
inline Standard_Real gp_Pnt2d::Y() const
{ return coord.Y(); }
inline const gp_XY& gp_Pnt2d::XY () const
{ return coord; }
inline const gp_XY& gp_Pnt2d::Coord () const
{ return coord; }
inline gp_XY& gp_Pnt2d::ChangeCoord ()
{ return coord; }
inline Standard_Boolean gp_Pnt2d::IsEqual
(const gp_Pnt2d& Other,
const Standard_Real LinearTolerance) const
{ return Distance (Other) <= LinearTolerance; }
inline Standard_Real gp_Pnt2d::Distance (const gp_Pnt2d& Other) const
{
const gp_XY& XY = Other.coord;
Standard_Real X = coord.X() - XY.X();
Standard_Real Y = coord.Y() - XY.Y();
return sqrt (X * X + Y * Y);
}
inline Standard_Real gp_Pnt2d::SquareDistance (const gp_Pnt2d& Other) const
{
const gp_XY& XY = Other.coord;
Standard_Real X = coord.X() - XY.X();
Standard_Real Y = coord.Y() - XY.Y();
return (X * X + Y * Y);
}
inline void gp_Pnt2d::Rotate (const gp_Pnt2d& P,
const Standard_Real Ang)
{
gp_Trsf2d T;
T.SetRotation (P, Ang);
T.Transforms (coord);
}
inline gp_Pnt2d gp_Pnt2d::Rotated (const gp_Pnt2d& P,
const Standard_Real Ang) const
{
gp_Pnt2d Pres = *this;
Pres.Rotate (P, Ang);
return Pres;
}
inline void gp_Pnt2d::Scale (const gp_Pnt2d& P,
const Standard_Real S)
{
gp_XY XY = P.coord;
XY.Multiply (1.0 - S);
coord.Multiply (S);
coord.Add (XY);
}
inline gp_Pnt2d gp_Pnt2d::Scaled (const gp_Pnt2d& P,
const Standard_Real S) const
{
gp_Pnt2d Pres = *this;
Pres.Scale (P, S);
return Pres;
}
inline gp_Pnt2d gp_Pnt2d::Transformed (const gp_Trsf2d& T) const
{
gp_Pnt2d Pres = *this;
Pres.Transform (T);
return Pres;
}
inline void gp_Pnt2d::Translate (const gp_Vec2d& V)
{ coord.Add (V.XY()); }
inline gp_Pnt2d gp_Pnt2d::Translated (const gp_Vec2d& V) const
{
gp_Pnt2d P = *this;
P.coord.Add (V.XY ());
return P;
}
inline void gp_Pnt2d::Translate (const gp_Pnt2d& P1,
const gp_Pnt2d& P2)
{
coord.Add (P2.coord);
coord.Subtract (P1.coord);
}
inline gp_Pnt2d gp_Pnt2d::Translated (const gp_Pnt2d& P1,
const gp_Pnt2d& P2) const
{
gp_Pnt2d P = *this;
P.Translate (P1, P2);
return P;
}

206
src/gp/gp_Quaternion.cdl Normal file
View File

@@ -0,0 +1,206 @@
---File: gp_Quaternion.cdl
---Created: Tue May 11 12:09:38 2010
---Author: Kirill GAVRILOV
---Copyright: Open CASCADE SAS 2010
class Quaternion from gp
---Purpose: Represents operation of rotation in 3d space as queternion
-- and implements operations with rotations basing on
-- quaternion mathematics.
--
-- In addition, provides methods for conversion to and from other
-- representatons of rotation (3*3 matrix, vector and
-- angle, Euler angles)
uses
Vec from gp,
Mat from gp,
EulerSequence from gp
is
Create returns Quaternion from gp;
---Purpose: Creates an identity quaternion
---C++: inline
Create (x, y, z, w: Real)
returns Quaternion from gp;
---Purpose: Creates quaternion directly from component values
Create (theToCopy: Quaternion from gp)
returns Quaternion from gp;
---Purpose: Creates copy of another quaternion
Create (theVecFrom, theVecTo: Vec from gp)
returns Quaternion from gp;
---Purpose: Creates quaternion representing shortest-arc rotation
-- operator producing vector theVecTo from vector theVecFrom.
Create (theVecFrom, theVecTo, theHelpCrossVec: Vec from gp)
returns Quaternion from gp;
---Purpose: Creates quaternion representing shortest-arc rotation
-- operator producing vector theVecTo from vector theVecFrom.
-- Additional vector theHelpCrossVec defines preferred direction for
-- rotation and is used when theVecTo and theVecFrom are directed
-- oppositely.
Create (theAxis: Vec from gp; theAngle: Real)
returns Quaternion from gp;
---Purpose: Creates quaternion representing rotation on angle
-- theAngle around vector theAxis
Create (theMat: Mat from gp)
returns Quaternion from gp;
---Purpose: Creates quaternion from rotation matrix 3*3
-- (which should be orthonormal skew-symmetric matrix)
IsEqual (me; theOther: Quaternion from gp) returns Boolean;
---Purpose: Simple equal test without precision
SetRotation (me: in out; theVecFrom, theVecTo: Vec from gp);
---Purpose: Sets quaternion to shortest-arc rotation producing
-- vector theVecTo from vector theVecFrom.
-- If vectors theVecFrom and theVecTo are opposite then rotation
-- axis is computed as theVecFrom ^ (1,0,0) or theVecFrom ^ (0,0,1).
SetRotation (me: in out; theVecFrom, theVecTo, theHelpCrossVec: Vec from gp);
---Purpose: Sets quaternion to shortest-arc rotation producing
-- vector theVecTo from vector theVecFrom.
-- If vectors theVecFrom and theVecTo are opposite then rotation
-- axis is computed as theVecFrom ^ theHelpCrossVec.
SetVectorAndAngle (me: in out; theAxis: Vec from gp; theAngle: Real);
---Purpose: Create a unit quaternion from Axis+Angle representation
GetVectorAndAngle (me; theAxis: out Vec from gp; theAngle: out Real);
---Purpose: Convert a quaternion to Axis+Angle representation,
-- preserve the axis direction and angle from -PI to +PI
SetMatrix (me: in out; theMat: Mat from gp);
---Purpose: Create a unit quaternion by rotation matrix
-- matrix must contain only rotation (not scale or shear)
--
-- For numerical stability we find first the greatest component of quaternion
-- and than search others from this one
GetMatrix (me) returns Mat from gp;
---Purpose: Returns rotation operation as 3*3 matrix
SetEulerAngles (me: in out; theOrder: EulerSequence from gp;
theAlpha, theBeta, theGamma: Real);
---Purpose: Create a unit quaternion representing rotation defined
-- by generalized Euler angles
GetEulerAngles (me; theOrder: EulerSequence from gp;
theAlpha, theBeta, theGamma: out Real);
---Purpose: Returns Euler angles describing current rotation
Set (me: in out; x, y, z, w: Real);
Set (me: in out; theQuaternion: Quaternion from gp);
X (me) returns Real;
Y (me) returns Real;
Z (me) returns Real;
W (me) returns Real;
SetIdent (me: in out);
---Purpose: Make identity quaternion (zero-rotation)
Reverse (me: in out);
---Purpose: Reverse direction of rotation (conjugate quaternion)
Reversed (me) returns Quaternion from gp;
---Purpose: Return rotation with reversed direction (conjugated quaternion)
Invert (me: in out);
---Purpose: Inverts quaternion (both rotation direction and norm)
Inverted (me) returns Quaternion from gp;
---Purpose: Return inversed quaternion q^-1
SquareNorm (me) returns Real;
---Purpose: Returns square norm of quaternion
Norm (me) returns Real;
---Purpose: Returns norm of quaternion
Scale (me: in out; theScale: Real);
---Purpose: Scale all components by quaternion by theScale; note that
-- rotation is not changed by this operation (except 0-scaling)
---C++: alias operator *=
Scaled (me; theScale: Real) returns Quaternion from gp;
---Purpose: Returns scaled quaternion
---C++: alias operator *
StabilizeLength (me: in out);
---Purpose: Stabilize quaternion length within 1 - 1/4.
-- This operation is a lot faster than normalization
-- and preserve length goes to 0 or infinity
Normalize (me: in out);
---Purpose: Scale quaternion that its norm goes to 1.
-- The appearing of 0 magnitude or near is a error,
-- so we can be sure that can divide by magnitude
Normalized (me) returns Quaternion from gp;
---Purpose: Returns quaternion scaled so that its norm goes to 1.
Negated (me) returns Quaternion from gp;
---Purpose: Returns quaternion with all components negated.
-- Note that this operation does not affect neither
-- rotation operator defined by quaternion nor its norm.
---C++: alias operator -
Added (me; theOther: Quaternion from gp) returns Quaternion from gp;
---Purpose: Makes sum of quaternion components; result is "rotations mix"
---C++: alias operator +
Subtracted (me; theOther: Quaternion from gp) returns Quaternion from gp;
---Purpose: Makes difference of quaternion components; result is "rotations mix"
---C++: alias operator -
Multiplied (me; theOther: Quaternion from gp) returns Quaternion from gp;
---Purpose: Multiply function - work the same as Matrices multiplying.
-- qq' = (cross(v,v') + wv' + w'v, ww' - dot(v,v'))
-- Result is rotation combination: q' than q (here q=this, q'=theQ).
-- Notices than:
-- qq' != q'q;
-- qq^-1 = q;
---C++: alias operator *
Add (me: in out; theOther: Quaternion from gp);
---Purpose: Adds componnets of other quaternion; result is "rotations mix"
---C++: alias operator +=
Subtract (me: in out; theOther: Quaternion from gp);
---Purpose: Subtracts componnets of other quaternion; result is "rotations mix"
---C++: alias operator -=
Multiply (me: in out; theOther: Quaternion from gp);
---Purpose: Adds rotation by multiplication
---C++: alias operator *=
Dot (me; theOther: Quaternion from gp) returns Real;
---Purpose: Computes inner product / scalar product / Dot
GetRotationAngle (me) returns Real;
---Purpose: Return rotation angle from -PI to PI
Multiply (me; theVec: Vec from gp) returns Vec from gp;
---Purpose: Rotates vector by quaternion as rotation operator
---C++: alias operator *
fields
x: Real;
y: Real;
z: Real;
w: Real;
end;

438
src/gp/gp_Quaternion.cxx Normal file
View File

@@ -0,0 +1,438 @@
// File: gp_Quaternion.cxx
// Created: Tue May 11 12:09:38 2010
// Author: Kirill GAVRILOV
// Copyright: Open CASCADE SAS 2010
//
// Note: implementation is based on free samples from
// http://www.gamedev.ru/code/articles/?id=4215&page=3
// and maths found in Wikipedia and elsewhere
#include <gp_Quaternion.hxx>
#include <gp_Vec.hxx>
#include <gp_Mat.hxx>
//=======================================================================
//function : IsEqual
//purpose :
//=======================================================================
Standard_Boolean gp_Quaternion::IsEqual (const gp_Quaternion& theOther) const
{
if (this == &theOther)
return Standard_True;
return Abs (x - theOther.x) <= gp::Resolution() &&
Abs (y - theOther.y) <= gp::Resolution() &&
Abs (z - theOther.z) <= gp::Resolution() &&
Abs (w - theOther.w) <= gp::Resolution();
}
//=======================================================================
//function : SetRotation
//purpose :
//=======================================================================
void gp_Quaternion::SetRotation (const gp_Vec& theVecFrom, const gp_Vec& theVecTo)
{
gp_Vec aVecCross (theVecFrom.Crossed (theVecTo));
Set (aVecCross.X(), aVecCross.Y(), aVecCross.Z(), theVecFrom.Dot (theVecTo));
Normalize(); // if "from" or "to" not unit, normalize quat
w += 1.0; // reducing angle to halfangle
if (w <= gp::Resolution()) // angle close to PI
{
if ((theVecFrom.Z() * theVecFrom.Z()) > (theVecFrom.X() * theVecFrom.X()))
Set ( 0.0, theVecFrom.Z(), -theVecFrom.Y(), w); // theVecFrom * gp_Vec(1,0,0)
else
Set (theVecFrom.Y(), -theVecFrom.X(), 0.0, w); // theVecFrom * gp_Vec(0,0,1)
}
Normalize();
}
//=======================================================================
//function : SetRotation
//purpose :
//=======================================================================
void gp_Quaternion::SetRotation (const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec)
{
gp_Vec aVecCross (theVecFrom.Crossed (theVecTo));
Set (aVecCross.X(), aVecCross.Y(), aVecCross.Z(), theVecFrom.Dot (theVecTo));
Normalize(); // if "from" or "to" not unit, normalize quat
w += 1.0; // reducing angle to halfangle
if (w <= gp::Resolution()) // angle close to PI
{
gp_Vec theAxis = theVecFrom.Crossed (theHelpCrossVec);
Set (theAxis.X(), theAxis.Y(), theAxis.Z(), w);
}
Normalize();
}
//=======================================================================
//function : SetVectorAndAngle
//purpose :
//=======================================================================
void gp_Quaternion::SetVectorAndAngle (const gp_Vec& theAxis, const Standard_Real theAngle)
{
gp_Vec anAxis = theAxis.Normalized();
Standard_Real anAngleHalf = 0.5 * theAngle;
Standard_Real sin_a = Sin (anAngleHalf);
Set (anAxis.X() * sin_a, anAxis.Y() * sin_a, anAxis.Z() * sin_a, Cos (anAngleHalf));
}
//=======================================================================
//function : GetVectorAndAngle
//purpose :
//=======================================================================
void gp_Quaternion::GetVectorAndAngle (gp_Vec& theAxis, Standard_Real& theAngle) const
{
Standard_Real vl = Sqrt (x * x + y * y + z * z);
if (vl > gp::Resolution())
{
Standard_Real ivl = 1.0 / vl;
theAxis.SetCoord (x * ivl, y * ivl, z * ivl);
if (w < 0.0)
{
theAngle = 2.0 * ATan2 (-vl, -w); // [-PI, 0]
}
else
{
theAngle = 2.0 * ATan2 ( vl, w); // [ 0, PI]
}
}
else
{
theAxis.SetCoord (0.0, 0.0, 1.0);
theAngle = 0.0;
}
}
//=======================================================================
//function : SetMatrix
//purpose :
//=======================================================================
void gp_Quaternion::SetMatrix (const gp_Mat& theMat)
{
Standard_Real tr = theMat (1, 1) + theMat (2, 2) + theMat(3, 3); // trace of martix
if (tr > 0.0)
{ // if trace positive than "w" is biggest component
Set (theMat (3, 2) - theMat (2, 3),
theMat (1, 3) - theMat (3, 1),
theMat (2, 1) - theMat (1, 2),
tr + 1.0);
Scale (0.5 / Sqrt (w)); // "w" contain the "norm * 4"
}
else if ((theMat (1, 1) > theMat (2, 2)) && (theMat (1, 1) > theMat (3, 3)))
{ // Some of vector components is bigger
Set (1.0 + theMat (1, 1) - theMat (2, 2) - theMat (3, 3),
theMat (1, 2) + theMat (2, 1),
theMat (1, 3) + theMat (3, 1),
theMat (3, 2) - theMat (2, 3));
Scale (0.5 / Sqrt (x));
}
else if (theMat (2, 2) > theMat (3, 3))
{
Set (theMat (1, 2) + theMat (2, 1),
1.0 + theMat (2, 2) - theMat (1, 1) - theMat (3, 3),
theMat (2, 3) + theMat (3, 2),
theMat (1, 3) - theMat (3, 1));
Scale (0.5 / Sqrt (y));
}
else
{
Set (theMat (1, 3) + theMat (3, 1),
theMat (2, 3) + theMat (3, 2),
1.0 + theMat (3, 3) - theMat (1, 1) - theMat (2, 2),
theMat (2, 1) - theMat (1, 2));
Scale (0.5 / Sqrt (z));
}
}
//=======================================================================
//function : GetMatrix
//purpose :
//=======================================================================
gp_Mat gp_Quaternion::GetMatrix () const
{
Standard_Real wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
Standard_Real s = 2.0 / SquareNorm();
x2 = x * s; y2 = y * s; z2 = z * s;
xx = x * x2; xy = x * y2; xz = x * z2;
yy = y * y2; yz = y * z2; zz = z * z2;
wx = w * x2; wy = w * y2; wz = w * z2;
gp_Mat aMat;
aMat (1, 1) = 1.0 - (yy + zz);
aMat (1, 2) = xy - wz;
aMat (1, 3) = xz + wy;
aMat (2, 1) = xy + wz;
aMat (2, 2) = 1.0 - (xx + zz);
aMat (2, 3) = yz - wx;
aMat (3, 1) = xz - wy;
aMat (3, 2) = yz + wx;
aMat (3, 3) = 1.0 - (xx + yy);
// 1 division 16 multiplications 15 addidtions 12 variables
return aMat;
}
//=======================================================================
//function : translateEulerSequence
//purpose :
// Code supporting conversion between quaternion and generalized
// Euler angles (sequence of three rotations) is based on
// algorithm by Ken Shoemake, published in Graphics Gems IV, p. 222-22
// http://tog.acm.org/resources/GraphicsGems/gemsiv/euler_angle/EulerAngles.c
//=======================================================================
struct gp_EulerSequence_Parameters
{
Standard_Integer i; // first rotation axis
Standard_Integer j; // next axis of rotation
Standard_Integer k; // third axis
Standard_Boolean isOdd; // true if order of two first rotation axes is odd permutation, e.g. XZ
Standard_Boolean isTwoAxes; // true if third rotation is about the same axis as first
Standard_Boolean isExtrinsic; // true if rotations are made around fixed axes
gp_EulerSequence_Parameters (Standard_Integer theAx1,
Standard_Boolean theisOdd,
Standard_Boolean theisTwoAxes,
Standard_Boolean theisExtrinsic)
: i(theAx1),
j(1 + (theAx1 + (theisOdd ? 1 : 0)) % 3),
k(1 + (theAx1 + (theisOdd ? 0 : 1)) % 3),
isOdd(theisOdd),
isTwoAxes(theisTwoAxes),
isExtrinsic(theisExtrinsic)
{}
};
gp_EulerSequence_Parameters translateEulerSequence (const gp_EulerSequence theSeq)
{
typedef gp_EulerSequence_Parameters Params;
const Standard_Boolean F = Standard_False;
const Standard_Boolean T = Standard_True;
switch (theSeq)
{
case gp_Extrinsic_XYZ: return Params (1, F, F, T);
case gp_Extrinsic_XZY: return Params (1, T, F, T);
case gp_Extrinsic_YZX: return Params (2, F, F, T);
case gp_Extrinsic_YXZ: return Params (2, T, F, T);
case gp_Extrinsic_ZXY: return Params (3, F, F, T);
case gp_Extrinsic_ZYX: return Params (3, T, F, T);
case gp_Intrinsic_XYZ: return Params (1, F, F, F);
case gp_Intrinsic_XZY: return Params (1, T, F, F);
case gp_Intrinsic_YZX: return Params (2, F, F, F);
case gp_Intrinsic_YXZ: return Params (2, T, F, F);
case gp_Intrinsic_ZXY: return Params (3, F, F, F);
case gp_Intrinsic_ZYX: return Params (3, T, F, F);
case gp_Extrinsic_XYX: return Params (1, F, T, T);
case gp_Extrinsic_XZX: return Params (1, T, T, T);
case gp_Extrinsic_YZY: return Params (2, F, T, T);
case gp_Extrinsic_YXY: return Params (2, T, T, T);
case gp_Extrinsic_ZXZ: return Params (3, F, T, T);
case gp_Extrinsic_ZYZ: return Params (3, T, T, T);
case gp_Intrinsic_XYX: return Params (1, F, T, F);
case gp_Intrinsic_XZX: return Params (1, T, T, F);
case gp_Intrinsic_YZY: return Params (2, F, T, F);
case gp_Intrinsic_YXY: return Params (2, T, T, F);
case gp_Intrinsic_ZXZ: return Params (3, F, T, F);
case gp_Intrinsic_ZYZ: return Params (3, T, T, F);
default:
case gp_EulerAngles : return Params (3, F, T, F); // = Intrinsic_ZXZ
case gp_YawPitchRoll: return Params (3, T, F, F); // = Intrinsic_ZYX
};
}
//=======================================================================
//function : SetEulerAngles
//purpose :
//=======================================================================
void gp_Quaternion::SetEulerAngles (const gp_EulerSequence theOrder,
const Standard_Real theAlpha,
const Standard_Real theBeta,
const Standard_Real theGamma)
{
gp_EulerSequence_Parameters o = translateEulerSequence (theOrder);
Standard_Real a = theAlpha, b = theBeta, c = theGamma;
if ( ! o.isExtrinsic )
{
a = theGamma;
c = theAlpha;
}
if ( o.isOdd )
b = -b;
Standard_Real ti = 0.5 * a;
Standard_Real tj = 0.5 * b;
Standard_Real th = 0.5 * c;
Standard_Real ci = Cos (ti);
Standard_Real cj = Cos (tj);
Standard_Real ch = Cos (th);
Standard_Real si = Sin (ti);
Standard_Real sj = Sin (tj);
Standard_Real sh = Sin (th);
Standard_Real cc = ci * ch;
Standard_Real cs = ci * sh;
Standard_Real sc = si * ch;
Standard_Real ss = si * sh;
Standard_Real values[4]; // w, x, y, z
if ( o.isTwoAxes )
{
values[o.i] = cj * (cs + sc);
values[o.j] = sj * (cc + ss);
values[o.k] = sj * (cs - sc);
values[0] = cj * (cc - ss);
}
else
{
values[o.i] = cj * sc - sj * cs;
values[o.j] = cj * ss + sj * cc;
values[o.k] = cj * cs - sj * sc;
values[0] = cj * cc + sj * ss;
}
if ( o.isOdd )
values[o.j] = -values[o.j];
x = values[1];
y = values[2];
z = values[3];
w = values[0];
}
//=======================================================================
//function : GetEulerAngles
//purpose :
//=======================================================================
void gp_Quaternion::GetEulerAngles (const gp_EulerSequence theOrder,
Standard_Real& theAlpha,
Standard_Real& theBeta,
Standard_Real& theGamma) const
{
gp_Mat M = GetMatrix();
gp_EulerSequence_Parameters o = translateEulerSequence (theOrder);
if ( o.isTwoAxes )
{
double sy = sqrt (M(o.i, o.j) * M(o.i, o.j) + M(o.i, o.k) * M(o.i, o.k));
if (sy > 16 * DBL_EPSILON)
{
theAlpha = ATan2 (M(o.i, o.j), M(o.i, o.k));
theGamma = ATan2 (M(o.j, o.i), -M(o.k, o.i));
}
else
{
theAlpha = ATan2 (-M(o.j, o.k), M(o.j, o.j));
theGamma = 0.;
}
theBeta = ATan2 (sy, M(o.i, o.i));
}
else
{
double cy = sqrt (M(o.i, o.i) * M(o.i, o.i) + M(o.j, o.i) * M(o.j, o.i));
if (cy > 16 * DBL_EPSILON)
{
theAlpha = ATan2 (M(o.k, o.j), M(o.k, o.k));
theGamma = ATan2 (M(o.j, o.i), M(o.i, o.i));
}
else
{
theAlpha = ATan2 (-M(o.j, o.k), M(o.j, o.j));
theGamma = 0.;
}
theBeta = ATan2 (-M(o.k, o.i), cy);
}
if ( o.isOdd )
{
theAlpha = -theAlpha;
theBeta = -theBeta;
theGamma = -theGamma;
}
if ( ! o.isExtrinsic )
{
Standard_Real aFirst = theAlpha;
theAlpha = theGamma;
theGamma = aFirst;
}
}
//=======================================================================
//function : StabilizeLength
//purpose :
//=======================================================================
void gp_Quaternion::StabilizeLength()
{
Standard_Real cs = Abs (x) + Abs (y) + Abs (z) + Abs (w);
if (cs > 0.0)
{
x /= cs; y /= cs; z /= cs; w /= cs;
}
else
{
SetIdent();
}
}
//=======================================================================
//function : Normalize
//purpose :
//=======================================================================
void gp_Quaternion::Normalize()
{
Standard_Real aMagn = Norm();
if (aMagn < gp::Resolution())
{
StabilizeLength();
aMagn = Norm();
}
Scale (1.0 / aMagn);
}
//=======================================================================
//function : Normalize
//purpose :
//=======================================================================
Standard_Real gp_Quaternion::GetRotationAngle() const
{
if (w < 0.0)
{
return 2.0 * ATan2 (-Sqrt (x * x + y * y + z * z), -w);
}
else
{
return 2.0 * ATan2 ( Sqrt (x * x + y * y + z * z), w);
}
}
//=======================================================================
//function : Multiply
//purpose :
//=======================================================================
gp_Vec gp_Quaternion::Multiply (const gp_Vec& theVec) const
{
gp_Quaternion theQ (theVec.X() * w + theVec.Z() * y - theVec.Y() * z,
theVec.Y() * w + theVec.X() * z - theVec.Z() * x,
theVec.Z() * w + theVec.Y() * x - theVec.X() * y,
theVec.X() * x + theVec.Y() * y + theVec.Z() * z);
return gp_Vec (w * theQ.x + x * theQ.w + y * theQ.z - z * theQ.y,
w * theQ.y + y * theQ.w + z * theQ.x - x * theQ.z,
w * theQ.z + z * theQ.w + x * theQ.y - y * theQ.x) * (1.0 / SquareNorm());
}

520
src/gp/gp_Quaternion.hxx Normal file
View File

@@ -0,0 +1,520 @@
#ifndef _gp_Quaternion_HeaderFile
#define _gp_Quaternion_HeaderFile
/**
* Initial sources based on free samples from
* http://www.gamedev.ru/code/articles/?id=4215&page=3
*/
#include <gp_Vec.hxx>
#include <gp_Mat.hxx>
#include <Precision.hxx>
//! General quaternion class (unit and nonunit),
//! designed for 3d rotations and orientation representation <br>
class gp_Quaternion
{
public:
//! Creates an identity quaternion. <br>
gp_Quaternion()
: x (0.0), y (0.0), z (0.0), w (1.0) {}
gp_Quaternion (Standard_Real x, Standard_Real y, Standard_Real z, Standard_Real w)
: x (x), y (y), z (z), w (w) {}
gp_Quaternion (const gp_Quaternion& theToCopy)
: x (theToCopy.x), y (theToCopy.y), z (theToCopy.z), w (theToCopy.w) {}
gp_Quaternion (const gp_Vec& theVecFrom, const gp_Vec& theVecTo)
: x (0.0), y (0.0), z (0.0), w (1.0)
{
Init (theVecFrom, theVecTo);
}
gp_Quaternion (const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec)
: x (0.0), y (0.0), z (0.0), w (1.0)
{
Init (theVecFrom, theVecTo, theHelpCrossVec);
}
//! Simple equal test without precision
Standard_Boolean IsEqual (const gp_Quaternion& theOther) const
{
if (this == &theOther)
{
return Standard_True;
}
return Abs (x - theOther.x) <= gp::Resolution() &&
Abs (y - theOther.y) <= gp::Resolution() &&
Abs (z - theOther.z) <= gp::Resolution() &&
Abs (w - theOther.w) <= gp::Resolution();
}
/**
* Shortest arc quaternion rotate one vector to another by shortest path.
* Create rotation from -> to, for any length vectors.
* If vectors theVecFrom and theVecTo are opposite then rotation axis computed as
* theVecFrom * gp_Vec(1,0,0) or theVecFrom * gp_Vec(0,0,1).
*/
void Init (const gp_Vec& theVecFrom, const gp_Vec& theVecTo)
{
gp_Vec aVecCross (theVecFrom.Crossed (theVecTo));
Set (aVecCross.X(), aVecCross.Y(), aVecCross.Z(), theVecFrom.Dot (theVecTo));
Normalize(); // if "from" or "to" not unit, normalize quat
w += 1.0; // reducing angle to halfangle
if (w <= Precision::Confusion()) // angle close to PI
{
if ((theVecFrom.Z() * theVecFrom.Z()) > (theVecFrom.X() * theVecFrom.X()))
Set ( 0.0, theVecFrom.Z(), -theVecFrom.Y(), w); // theVecFrom * gp_Vec(1,0,0)
else
Set (theVecFrom.Y(), -theVecFrom.X(), 0.0, w); // theVecFrom * gp_Vec(0,0,1)
}
Normalize();
}
/**
* Shortest arc quaternion rotate one vector to another by shortest path.
* If vectors theVecFrom and theVecTo are opposite then rotation axis computed as
* theVecFrom * theHelpCrossVec.
*/
void Init (const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec)
{
gp_Vec aVecCross (theVecFrom.Crossed (theVecTo));
Set (aVecCross.X(), aVecCross.Y(), aVecCross.Z(), theVecFrom.Dot (theVecTo));
Normalize(); // if "from" or "to" not unit, normalize quat
w += 1.0; // reducing angle to halfangle
if (w <= Precision::Confusion()) // angle close to PI
{
gp_Vec theAxis = theVecFrom.Crossed (theHelpCrossVec);
Set (theAxis.X(), theAxis.Y(), theAxis.Z(), w);
}
Normalize();
}
gp_Quaternion (const gp_Vec& theAxis, const Standard_Real& theAngle)
: x (0.0), y (0.0), z (0.0), w (1.0)
{
InitUnit (theAxis, theAngle);
}
//! Create a unit quaternion from Axis+Angle representation
void InitUnit (const gp_Vec& theAxis, const Standard_Real& theAngle)
{
gp_Vec anAxis = theAxis.Normalized();
Standard_Real anAngleHalf = 0.5 * theAngle;
Standard_Real sin_a = Sin (anAngleHalf);
Set (anAxis.X() * sin_a, anAxis.Y() * sin_a, anAxis.Z() * sin_a, Cos (anAngleHalf));
}
/**
* Convert a quaternion to Axis+Angle representation,
* preserve the axis direction and angle from -PI to +PI
*/
void GetAxisAngle (gp_Vec& theAxis, Standard_Real& theAngle) const
{
Standard_Real vl = Sqrt (x * x + y * y + z * z);
if (vl > Precision::Confusion())
{
Standard_Real ivl = 1.0 / vl;
theAxis.SetCoord (x * ivl, y * ivl, z * ivl);
if (w < 0.0)
{
theAngle = 2.0 * ATan2 (-vl, -w); // [-PI, 0]
}
else
{
theAngle = 2.0 * ATan2 ( vl, w); // [ 0, PI]
}
}
else
{
theAxis.SetCoord (0.0, 0.0, 0.0);
theAngle = 0.0;
}
}
/**
* Create a unit quaternion by rotation matrix
* matrix must contain only rotation (not scale or shear)
*
* For numerical stability we find first the greatest component of quaternion
* and than search others from this one
*/
void InitUnit (const gp_Mat& theMat)
{
Standard_Real tr = theMat (1, 1) + theMat (2, 2) + theMat(3, 3); // trace of martix
if (tr > 0.0)
{ // if trace positive than "w" is biggest component
Set (theMat (3, 2) - theMat (2, 3),
theMat (1, 3) - theMat (3, 1),
theMat (2, 1) - theMat (1, 2),
tr + 1.0);
Scale (0.5 / Sqrt (w)); // "w" contain the "norm * 4"
}
else if ((theMat (1, 1) > theMat (2, 2)) && (theMat (1, 1) > theMat (3, 3)))
{ // Some of vector components is bigger
Set (1.0 + theMat (1, 1) - theMat (2, 2) - theMat (3, 3),
theMat (1, 2) + theMat (2, 1),
theMat (1, 3) + theMat (3, 1),
theMat (3, 2) - theMat (2, 3));
Scale (0.5 / Sqrt (x));
}
else if (theMat (2, 2) > theMat (3, 3))
{
Set (theMat (1, 2) + theMat (2, 1),
1.0 + theMat (2, 2) - theMat (1, 1) - theMat (3, 3),
theMat (2, 3) + theMat (3, 2),
theMat (1, 3) - theMat (3, 1));
Scale (0.5 / Sqrt (y));
}
else
{
Set (theMat (1, 3) + theMat (3, 1),
theMat (2, 3) + theMat (3, 2),
1.0 + theMat (3, 3) - theMat (1, 1) - theMat (2, 2),
theMat (2, 1) - theMat (1, 2));
Scale (0.5 / Sqrt (z));
}
}
gp_Quaternion (const gp_Mat& theMat)
: x (0.0), y (0.0), z (0.0), w (1.0)
{
Init (theMat);
}
/**
* Create a nonunit quaternion from rotation matrix
* martix must contain only rotation (not scale or shear)
* the result quaternion length is numerical stable
*/
void Init (const gp_Mat& theMat)
{
Standard_Real tr = theMat (1, 1) + theMat (2, 2) + theMat (3, 3); // trace of martix
if (tr > 0.0)
{ // if trace positive than "w" is biggest component
Set (theMat (3, 2) - theMat (2, 3),
theMat (1, 3) - theMat (3, 1),
theMat (2, 1) - theMat (1, 2),
tr + 1.0);
}
else if ((theMat (1, 1) > theMat (2, 2)) && (theMat (1, 1) > theMat (3, 3)))
{ // Some of vector components is bigger
Set (1.0 + theMat (1, 1) - theMat (2, 2) - theMat (3, 3),
theMat (1, 2) + theMat (2, 1),
theMat (1, 3) + theMat (3, 1),
theMat (3, 2) - theMat (2, 3));
}
else if (theMat (2, 2) > theMat (3, 3))
{
Set (theMat (1, 2) + theMat (2, 1),
1.0 + theMat (2, 2) - theMat (1, 1) - theMat (3, 3),
theMat (2, 3) + theMat (3, 2),
theMat (1, 3) - theMat (3, 1));
}
else
{
Set (theMat (1, 3) + theMat (3, 1),
theMat (2, 3) + theMat (3, 2),
1.0 + theMat (3, 3) - theMat (1, 1) - theMat (2, 2),
theMat (2, 1) - theMat (1, 2));
}
}
//! Set the rotation to matrix
void GetRotateMatrix (gp_Mat& theMat) const
{
Standard_Real wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
Standard_Real s = 2.0 / Norm();
x2 = x * s; y2 = y * s; z2 = z * s;
xx = x * x2; xy = x * y2; xz = x * z2;
yy = y * y2; yz = y * z2; zz = z * z2;
wx = w * x2; wy = w * y2; wz = w * z2;
theMat (1, 1) = 1.0 - (yy + zz);
theMat (1, 2) = xy - wz;
theMat (1, 3) = xz + wy;
theMat (2, 1) = xy + wz;
theMat (2, 2) = 1.0 - (xx + zz);
theMat (2, 3) = yz - wx;
theMat (3, 1) = xz - wy;
theMat (3, 2) = yz + wx;
theMat (3, 3) = 1.0 - (xx + yy);
// 1 division 16 multiplications 15 addidtions 12 variables
}
//! Set the rotation from unit quat to matrix
void GetRotateMatrixFromUnit (gp_Mat& theMat) const
{
Standard_Real wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
x2 = x + x; y2 = y + y; z2 = z + z;
xx = x * x2; xy = x * y2; xz = x * z2;
yy = y * y2; yz = y * z2; zz = z * z2;
wx = w * x2; wy = w * y2; wz = w * z2;
theMat (1, 1) = 1.0 - (yy + zz);
theMat (1, 2) = xy - wz;
theMat (1, 3) = xz + wy;
theMat (2, 1) = xy + wz;
theMat (2, 2) = 1.0 - (xx + zz);
theMat (2, 3) = yz - wx;
theMat (3, 1) = xz - wy;
theMat (3, 2) = yz + wx;
theMat (3, 3) = 1.0 - (xx + yy);
}
void Set (Standard_Real x, Standard_Real y, Standard_Real z, Standard_Real w)
{
this->x = x; this->y = y; this->z = z; this->w = w;
}
void Set (const gp_Quaternion& theQuaternion)
{
x = theQuaternion.x; y = theQuaternion.y; z = theQuaternion.z; w = theQuaternion.w;
}
Standard_Real X() const
{
return x;
}
Standard_Real Y() const
{
return y;
}
Standard_Real Z() const
{
return z;
}
Standard_Real W() const
{
return w;
}
//! Make identity quaternion (zero-rotation)
void Ident()
{
x = 0.0; y = 0.0; z = 0.0; w = 1.0;
}
//! Reverse rotation
void Conjugate()
{
x = -x; y = -y; z = -z;
}
//! Return reversed rotation
gp_Quaternion Conjugated() const
{
return gp_Quaternion (-x, -y, -z, w);
}
//! Rotation will not be changed by this operation (except 0-scaling)
void Scale (Standard_Real theScale)
{
x *= theScale; y *= theScale; z *= theScale; w *= theScale;
}
gp_Quaternion Scaled (const Standard_Real theScale) const
{
return gp_Quaternion (x * theScale, y * theScale, z * theScale, w * theScale);
}
Standard_Real Norm() const
{
return x * x + y * y + z * z + w * w;
}
Standard_Real Magnitude() const
{
return Sqrt (Norm());
}
//! Invert quaternion q = q^-1
void Invert()
{
Standard_Real in = 1.0 / Norm();
Set (-x * in, -y * in, -z * in, w * in);
}
//! Return inversed quaternion q^-1
gp_Quaternion Inverted() const
{
Standard_Real in = 1.0 / Norm();
return gp_Quaternion (-x * in, -y * in, -z * in, w * in);
}
/**
* Stabilize quaternion length within 1 - 1/4
* This operation is a lot faster than normalization
* and preserve length goes to 0 or infinity
*/
void StabilizeLength()
{
Standard_Real cs = Abs (x) + Abs (y) + Abs (z) + Abs (w);
if (cs > 0.0)
{
x /= cs; y /= cs; z /= cs; w /= cs;
}
else
{
Ident();
}
}
/**
* Scale quaternion that its norm goes to 1
* The appearing of 0 magnitude or near is a error,
* so we can be sure that can divide by magnitude
*/
void Normalize()
{
Standard_Real aMagn = Magnitude();
if (aMagn < Precision::Confusion())
{
StabilizeLength();
aMagn = Magnitude();
}
Scale (1.0 / aMagn);
}
gp_Quaternion Normalized() const
{
gp_Quaternion aNormilizedQ (*this);
aNormilizedQ.Normalize();
return aNormilizedQ;
}
gp_Quaternion operator-() const
{
return gp_Quaternion (-x, -y, -z, -w);
}
//! Result is "rotations mix"
gp_Quaternion Added (const gp_Quaternion& theQ) const
{
return gp_Quaternion (x + theQ.x, y + theQ.y, z + theQ.z, w + theQ.w);
}
//! Result is "rotations mix"
gp_Quaternion operator+ (const gp_Quaternion& theQ) const
{
return Added(theQ);
}
//! Result is "rotations mix"
gp_Quaternion Subtracted (const gp_Quaternion& theQ) const
{
return gp_Quaternion (x - theQ.x, y - theQ.y, z - theQ.z, w - theQ.w);
}
//! Result is "rotations mix"
gp_Quaternion operator- (const gp_Quaternion& theQ) const
{
return Subtracted (theQ);
}
//! Rotation will not be changed by this operation (except 0-scaling)
gp_Quaternion operator* (const Standard_Real& theScale) const
{
return gp_Quaternion (x * theScale, y * theScale, z * theScale, w * theScale);
}
/**
* Multiply function - work the same as Matrices multiplying.
* qq' = (cross(v,v') + wv' + w'v, ww' - dot(v,v'))
* Result is rotation combination: q' than q (here q=this, q'=theQ).
* Notices than:
* qq' != q'q;
* qq^-1 = q;
*/
gp_Quaternion operator* (const gp_Quaternion& theQ) const
{
return gp_Quaternion (w * theQ.x + x * theQ.w + y * theQ.z - z * theQ.y,
w * theQ.y + y * theQ.w + z * theQ.x - x * theQ.z,
w * theQ.z + z * theQ.w + x * theQ.y - y * theQ.x,
w * theQ.w - x * theQ.x - y * theQ.y - z * theQ.z);
// 16 multiplications 12 addidtions 0 variables
}
//! Result is "rotations mix"
const gp_Quaternion& Add (const gp_Quaternion& theQ)
{
x += theQ.x; y += theQ.y; z += theQ.z; w += theQ.w;
return *this;
}
//! Result is "rotations mix"
const gp_Quaternion& operator+= (const gp_Quaternion& theQ)
{
return Add (theQ);
}
//! Result is "rotations mix"
const gp_Quaternion& Subtract (const gp_Quaternion& theQ)
{
x -= theQ.x; y -= theQ.y; z -= theQ.z; w -= theQ.w;
return *this;
}
//! Result is "rotations mix"
const gp_Quaternion& operator-= (const gp_Quaternion& theQ)
{
return Subtract(theQ);
}
const gp_Quaternion& operator*= (const gp_Quaternion& theQ)
{
Set ((*this) * theQ); // have no optimization here
return *this;
}
//! Inner product / scalar product / Dot
Standard_Real Dot (const gp_Quaternion& theQ)
{
return x * theQ.x + y * theQ.y + z * theQ.z + w * theQ.w;
}
//! Return rotation angle from -PI to PI
Standard_Real GetRotationAngle() const
{
if (w < 0.0)
{
return 2.0 * ATan2 (-Sqrt (x * x + y * y + z * z), -w);
}
else
{
return 2.0 * ATan2 ( Sqrt (x * x + y * y + z * z), w);
}
}
//! Return vector rotated by quaternion
gp_Vec Rotated (const gp_Vec& theVec) const
{
gp_Quaternion theQ (theVec.X() * w + theVec.Z() * y - theVec.Y() * z,
theVec.Y() * w + theVec.X() * z - theVec.Z() * x,
theVec.Z() * w + theVec.Y() * x - theVec.X() * y,
theVec.X() * x + theVec.Y() * y + theVec.Z() * z);
return gp_Vec (w * theQ.x + x * theQ.w + y * theQ.z - z * theQ.y,
w * theQ.y + y * theQ.w + z * theQ.x - x * theQ.z,
w * theQ.z + z * theQ.w + x * theQ.y - y * theQ.x) * (1.0 / Norm());
}
private:
Standard_Real x;
Standard_Real y;
Standard_Real z;
Standard_Real w;
};
#endif //_gp_Quaternion_HeaderFile

338
src/gp/gp_Quaternion.lxx Normal file
View File

@@ -0,0 +1,338 @@
//=======================================================================
//function : gp_Quaternion
//purpose :
//=======================================================================
inline gp_Quaternion::gp_Quaternion()
: x(0.0), y(0.0), z(0.0), w(1.0)
{
}
//=======================================================================
//function : gp_Quaternion
//purpose :
//=======================================================================
inline gp_Quaternion::gp_Quaternion (const Standard_Real x, const Standard_Real y,
const Standard_Real z, const Standard_Real w)
: x(x), y(y), z(z), w(w)
{
}
//=======================================================================
//function : gp_Quaternion
//purpose :
//=======================================================================
inline gp_Quaternion::gp_Quaternion (const gp_Quaternion& theToCopy)
: x(theToCopy.x), y(theToCopy.y), z(theToCopy.z), w(theToCopy.w)
{
}
//=======================================================================
//function : gp_Quaternion
//purpose :
//=======================================================================
inline gp_Quaternion::gp_Quaternion (const gp_Vec& theVecFrom, const gp_Vec& theVecTo)
{
SetRotation (theVecFrom, theVecTo);
}
//=======================================================================
//function : gp_Quaternion
//purpose :
//=======================================================================
inline gp_Quaternion::gp_Quaternion (const gp_Vec& theVecFrom, const gp_Vec& theVecTo, const gp_Vec& theHelpCrossVec)
{
SetRotation (theVecFrom, theVecTo, theHelpCrossVec);
}
//=======================================================================
//function : gp_Quaternion
//purpose :
//=======================================================================
inline gp_Quaternion::gp_Quaternion (const gp_Vec& theAxis, const Standard_Real theAngle)
{
SetVectorAndAngle (theAxis, theAngle);
}
//=======================================================================
//function : gp_Quaternion
//purpose :
//=======================================================================
inline gp_Quaternion::gp_Quaternion (const gp_Mat& theMat)
{
SetMatrix (theMat);
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
inline void gp_Quaternion::Set (Standard_Real x, Standard_Real y,
Standard_Real z, Standard_Real w)
{
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
inline void gp_Quaternion::Set (const gp_Quaternion& theQuaternion)
{
x = theQuaternion.x;
y = theQuaternion.y;
z = theQuaternion.z;
w = theQuaternion.w;
}
//=======================================================================
//function : X
//purpose :
//=======================================================================
inline Standard_Real gp_Quaternion::X() const
{
return x;
}
//=======================================================================
//function : Y
//purpose :
//=======================================================================
inline Standard_Real gp_Quaternion::Y() const
{
return y;
}
//=======================================================================
//function : Z
//purpose :
//=======================================================================
inline Standard_Real gp_Quaternion::Z() const
{
return z;
}
//=======================================================================
//function : W
//purpose :
//=======================================================================
inline Standard_Real gp_Quaternion::W() const
{
return w;
}
//=======================================================================
//function : SetIdent
//purpose :
//=======================================================================
inline void gp_Quaternion::SetIdent()
{
x = y = z = 0.0;
w = 1.0;
}
//=======================================================================
//function : Reverse
//purpose :
//=======================================================================
inline void gp_Quaternion::Reverse()
{
x = -x;
y = -y;
z = -z;
}
//=======================================================================
//function : Reversed
//purpose :
//=======================================================================
inline gp_Quaternion gp_Quaternion::Reversed() const
{
return gp_Quaternion (-x, -y, -z, w);
}
//=======================================================================
//function : Scale
//purpose :
//=======================================================================
inline void gp_Quaternion::Scale (const Standard_Real theScale)
{
x *= theScale;
y *= theScale;
z *= theScale;
w *= theScale;
}
//=======================================================================
//function : Scaled
//purpose :
//=======================================================================
inline gp_Quaternion gp_Quaternion::Scaled (const Standard_Real theScale) const
{
return gp_Quaternion (x * theScale, y * theScale, z * theScale, w * theScale);
}
//=======================================================================
//function : SquareNorm
//purpose :
//=======================================================================
inline Standard_Real gp_Quaternion::SquareNorm() const
{
return x * x + y * y + z * z + w * w;
}
//=======================================================================
//function : Norm
//purpose :
//=======================================================================
inline Standard_Real gp_Quaternion::Norm() const
{
return Sqrt (SquareNorm());
}
//=======================================================================
//function : Invert
//purpose :
//=======================================================================
inline void gp_Quaternion::Invert()
{
Standard_Real in = 1.0 / SquareNorm();
Set (-x * in, -y * in, -z * in, w * in);
}
//=======================================================================
//function : Inverted
//purpose :
//=======================================================================
inline gp_Quaternion gp_Quaternion::Inverted() const
{
Standard_Real in = 1.0 / SquareNorm();
return gp_Quaternion (-x * in, -y * in, -z * in, w * in);
}
//=======================================================================
//function : Normalized
//purpose :
//=======================================================================
inline gp_Quaternion gp_Quaternion::Normalized() const
{
gp_Quaternion aNormilizedQ (*this);
aNormilizedQ.Normalize();
return aNormilizedQ;
}
//=======================================================================
//function : Negated
//purpose :
//=======================================================================
inline gp_Quaternion gp_Quaternion::Negated () const
{
return gp_Quaternion (-x, -y, -z, -w);
}
//=======================================================================
//function : Added
//purpose :
//=======================================================================
inline gp_Quaternion gp_Quaternion::Added (const gp_Quaternion& theQ) const
{
return gp_Quaternion (x + theQ.x, y + theQ.y, z + theQ.z, w + theQ.w);
}
//=======================================================================
//function : Subtracted
//purpose :
//=======================================================================
inline gp_Quaternion gp_Quaternion::Subtracted (const gp_Quaternion& theQ) const
{
return gp_Quaternion (x - theQ.x, y - theQ.y, z - theQ.z, w - theQ.w);
}
//=======================================================================
//function : Multiplied
//purpose :
//=======================================================================
inline gp_Quaternion gp_Quaternion::Multiplied (const gp_Quaternion& theQ) const
{
return gp_Quaternion (w * theQ.x + x * theQ.w + y * theQ.z - z * theQ.y,
w * theQ.y + y * theQ.w + z * theQ.x - x * theQ.z,
w * theQ.z + z * theQ.w + x * theQ.y - y * theQ.x,
w * theQ.w - x * theQ.x - y * theQ.y - z * theQ.z);
// 16 multiplications 12 addidtions 0 variables
}
//=======================================================================
//function : Add
//purpose :
//=======================================================================
inline void gp_Quaternion::Add (const gp_Quaternion& theQ)
{
x += theQ.x;
y += theQ.y;
z += theQ.z;
w += theQ.w;
}
//=======================================================================
//function : Subtract
//purpose :
//=======================================================================
inline void gp_Quaternion::Subtract (const gp_Quaternion& theQ)
{
x -= theQ.x;
y -= theQ.y;
z -= theQ.z;
w -= theQ.w;
}
//=======================================================================
//function : Multiply
//purpose :
//=======================================================================
inline void gp_Quaternion::Multiply (const gp_Quaternion& theQ)
{
(*this) = Multiplied (theQ); // have no optimization here
}
//=======================================================================
//function : Dot
//purpose :
//=======================================================================
inline Standard_Real gp_Quaternion::Dot (const gp_Quaternion& theQ) const
{
return x * theQ.x + y * theQ.y + z * theQ.z + w * theQ.w;
}

View File

@@ -0,0 +1,62 @@
#ifndef _gp_QuaternionNLerp_HeaderFile
#define _gp_QuaternionNLerp_HeaderFile
#include <gp_Quaternion.hxx>
/**
* Class perform linear interpolation (approximate rotation interpolation),
* result quaternion nonunit, its length lay between. sqrt(2)/2 and 1.0
*/
class gp_QuaternionNLerp
{
public:
gp_QuaternionNLerp() {}
gp_QuaternionNLerp (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
{
Init (theQStart, theQEnd);
}
void Init (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
{
InitFromUnit (theQStart.Normalized(), theQEnd.Normalized());
}
void InitFromUnit (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
{
myQStart = theQStart;
myQEnd = theQEnd;
Standard_Real anInner = myQStart.Dot (myQEnd);
if (anInner < 0.0)
{
myQEnd = -myQEnd;
}
myQEnd -= myQStart;
}
//! Set interpolated quaternion for theT position (from 0.0 to 1.0)
void Interpolate (Standard_Real theT, gp_Quaternion& theResultQ) const
{
theResultQ = myQStart + myQEnd * theT;
}
static gp_Quaternion Interpolate (const gp_Quaternion& theQStart,
const gp_Quaternion& theQEnd,
Standard_Real theT)
{
gp_Quaternion aResultQ;
gp_QuaternionNLerp aNLerp (theQStart, theQEnd);
aNLerp.Interpolate (theT, aResultQ);
return aResultQ;
}
private:
gp_Quaternion myQStart;
gp_Quaternion myQEnd;
};
#endif //_gp_QuaternionNLerp_HeaderFile

View File

@@ -0,0 +1,61 @@
#ifndef _gp_QuaternionSLerp_HeaderFile
#define _gp_QuaternionSLerp_HeaderFile
#include <gp_Quaternion.hxx>
/**
* Perform Spherical Linear Interpolation of the quaternions,
* return unit length quaternion.
*/
class gp_QuaternionSLerp
{
public:
gp_QuaternionSLerp() {}
gp_QuaternionSLerp (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
{
Init (theQStart, theQEnd);
}
void Init (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
{
InitFromUnit (theQStart.Normalized(), theQEnd.Normalized());
}
void InitFromUnit (const gp_Quaternion& theQStart, const gp_Quaternion& theQEnd)
{
myQStart = theQStart;
myQEnd = theQEnd;
Standard_Real cosOmega = myQStart.Dot (myQEnd);
if (cosOmega < 0.0)
{
cosOmega = -cosOmega;
myQEnd = -myQEnd;
}
if (cosOmega > 0.9999)
{
cosOmega = 0.9999;
}
myOmega = ACos (cosOmega);
Standard_Real invSinOmega = (1.0 / Sin (myOmega));
myQStart.Scale (invSinOmega);
myQEnd.Scale (invSinOmega);
}
//! Set interpolated quaternion for theT position (from 0.0 to 1.0)
void Interpolate (Standard_Real theT, gp_Quaternion& theResultQ) const
{
theResultQ = myQStart * Sin((1.0 - theT) * myOmega) + myQEnd * Sin (theT * myOmega);
}
private:
gp_Quaternion myQStart;
gp_Quaternion myQEnd;
Standard_Real myOmega;
};
#endif //_gp_QuaternionSLerp_HeaderFile

229
src/gp/gp_Sphere.cdl Executable file
View File

@@ -0,0 +1,229 @@
---Copyright: Matra Datavision 1991
class Sphere from gp inherits Storable
--- Purpose :
-- Describes a sphere.
-- A sphere is defined by its radius and positioned in space
-- with a coordinate system (a gp_Ax3 object). The origin of
-- the coordinate system is the center of the sphere. This
-- coordinate system is the "local coordinate system" of the sphere.
-- Note: when a gp_Sphere sphere is converted into a
-- Geom_SphericalSurface sphere, some implicit
-- properties of its local coordinate system are used explicitly:
-- - its origin, "X Direction", "Y Direction" and "main
-- Direction" are used directly to define the parametric
-- directions on the sphere and the origin of the parameters,
-- - its implicit orientation (right-handed or left-handed)
-- gives the orientation (direct, indirect) to the
-- Geom_SphericalSurface sphere.
-- See Also
-- gce_MakeSphere which provides functions for more
-- complex sphere constructions
-- Geom_SphericalSurface which provides additional
-- functions for constructing spheres and works, in
-- particular, with the parametric equations of spheres.
uses Ax1 from gp,
Ax2 from gp,
Ax3 from gp,
Dir from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard
is
Create returns Sphere;
---C++:inline
--- Purpose : Creates an indefinite sphere.
Create (A3 : Ax3; Radius : Real) returns Sphere
---C++: inline
--- Purpose :
-- Constructs a sphere with radius Radius, centered on the origin
-- of A3. A3 is the local coordinate system of the sphere.
-- Warnings :
-- It is not forbidden to create a sphere with null radius.
-- Raises ConstructionError if Radius < 0.0
raises ConstructionError;
SetLocation (me : in out; Loc : Pnt) is static;
---C++: inline
--- Purpose : Changes the center of the sphere.
SetPosition (me : in out; A3 : Ax3) is static;
---C++: inline
--- Purpose : Changes the local coordinate system of the sphere.
SetRadius (me : in out; R : Real)
---C++: inline
--- Purpose : Assigns R the radius of the Sphere.
-- Warnings :
-- It is not forbidden to create a sphere with null radius.
-- Raises ConstructionError if R < 0.0
raises ConstructionError
is static;
Area (me) returns Real is static;
---C++: inline
--- Purpose :
-- Computes the aera of the sphere.
Coefficients (me; A1, A2, A3, B1, B2, B3, C1, C2, C3, D : out Real)
is static;
--- Purpose :
-- Computes the coefficients of the implicit equation of the quadric
-- in the absolute cartesian coordinates system :
-- A1.X**2 + A2.Y**2 + A3.Z**2 + 2.(B1.X.Y + B2.X.Z + B3.Y.Z) +
-- 2.(C1.X + C2.Y + C3.Z) + D = 0.0
UReverse (me : in out)
---C++: inline
---Purpose: Reverses the U parametrization of the sphere
-- reversing the YAxis.
is static;
VReverse (me : in out)
---C++: inline
---Purpose: Reverses the V parametrization of the sphere
-- reversing the ZAxis.
is static;
Direct (me) returns Boolean from Standard
---C++: inline
---Purpose: Returns true if the local coordinate system of this sphere
-- is right-handed.
is static;
Location (me) returns Pnt is static;
---C++: inline
--- Purpose ;
-- Returns the center of the sphere.
---C++: return const&
Position (me) returns Ax3 is static;
--- Purpose :
-- Returns the local coordinates system of the sphere.
---C++: inline
---C++: return const&
Radius (me) returns Real is static;
---C++: inline
--- Purpose : Returns the radius of the sphere.
Volume (me) returns Real is static;
---C++: inline
--- Purpose : Computes the volume of the sphere
XAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose : Returns the axis X of the sphere.
YAxis (me) returns Ax1 is static;
---C++: inline
--- Purpose : Returns the axis Y of the sphere.
Mirror (me : in out; P : Pnt) is static;
Mirrored (me; P : Pnt) returns Sphere is static;
--- Purpose :
-- Performs the symmetrical transformation of a sphere
-- with respect to the point P which is the center of the
-- symmetry.
Mirror (me : in out; A1 : Ax1) is static;
Mirrored (me; A1 : Ax1) returns Sphere is static;
--- Purpose :
-- Performs the symmetrical transformation of a sphere with
-- respect to an axis placement which is the axis of the
-- symmetry.
Mirror (me : in out; A2 : Ax2) is static;
Mirrored (me; A2 : Ax2) returns Sphere is static;
--- Purpose :
-- Performs the symmetrical transformation of a sphere with respect
-- to a plane. The axis placement A2 locates the plane of the
-- of the symmetry : (Location, XDirection, YDirection).
Rotate (me : in out; A1 : Ax1; Ang : Real) is static;
---C++: inline
Rotated (me; A1 : Ax1; Ang : Real) returns Sphere is static;
---C++: inline
--- Purpose :
-- Rotates a sphere. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++:inline
Scaled (me; P : Pnt; S : Real) returns Sphere is static;
---C++:inline
--- Purpose :
-- Scales a sphere. S is the scaling value.
-- The absolute value of S is used to scale the sphere
Transform (me : in out; T : Trsf) is static;
---C++:inline
Transformed (me; T : Trsf) returns Sphere is static;
---C++:inline
--- Purpose :
-- Transforms a sphere with the transformation T from class Trsf.
Translate (me : in out; V : Vec) is static;
---C++:inline
Translated (me; V : Vec) returns Sphere is static;
---C++:inline
--- Purpose :
-- Translates a sphere in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt) is static;
---C++:inline
Translated (me; P1, P2 : Pnt) returns Sphere is static;
---C++:inline
--- Purpose :
-- Translates a sphere from the point P1 to the point P2.
fields
pos : Ax3;
radius : Real;
end;

70
src/gp/gp_Sphere.cxx Executable file
View File

@@ -0,0 +1,70 @@
//File gp_Sphere.cxx JCV 09/03/91
#include <gp_Sphere.ixx>
#include <Standard_ConstructionError.hxx>
void gp_Sphere::Coefficients
(Standard_Real& A1, Standard_Real& A2, Standard_Real& A3,
Standard_Real& B1, Standard_Real& B2, Standard_Real& B3,
Standard_Real& C1, Standard_Real& C2, Standard_Real& C3,
Standard_Real& D) const
{
// Dans le repere local de la sphere :
// X*X + Y*Y + Z*Z - radius * radius = 0
gp_Trsf T;
T.SetTransformation (pos);
Standard_Real T11 = T.Value (1, 1);
Standard_Real T12 = T.Value (1, 2);
Standard_Real T13 = T.Value (1, 3);
Standard_Real T14 = T.Value (1, 4);
Standard_Real T21 = T.Value (2, 1);
Standard_Real T22 = T.Value (2, 2);
Standard_Real T23 = T.Value (2, 3);
Standard_Real T24 = T.Value (2, 4);
Standard_Real T31 = T.Value (3, 1);
Standard_Real T32 = T.Value (3, 2);
Standard_Real T33 = T.Value (3, 3);
Standard_Real T34 = T.Value (3, 4);
A1 = T11 * T11 + T21 * T21 + T31 * T31;
A2 = T12 * T12 + T22 * T22 + T32 * T32;
A3 = T13 * T13 + T23 * T23 + T33 * T33;
B1 = T11 * T12 + T21 * T22 + T31 * T32;
B2 = T11 * T13 + T21 * T23 + T31 * T33;
B3 = T12 * T13 + T22 * T23 + T32 * T33;
C1 = T11 * T14 + T21 * T24 + T31 * T34;
C2 = T12 * T14 + T22 * T24 + T32 * T34;
C3 = T13 * T14 + T23 * T24 + T33 * T34;
D = T14 * T14 + T24 * T24 + T34 * T34 - radius * radius;
}
void gp_Sphere::Mirror (const gp_Pnt& P)
{ pos.Mirror (P); }
gp_Sphere gp_Sphere::Mirrored (const gp_Pnt& P) const
{
gp_Sphere C = *this;
C.pos.Mirror (P);
return C;
}
void gp_Sphere::Mirror (const gp_Ax1& A1)
{ pos.Mirror (A1); }
gp_Sphere gp_Sphere::Mirrored (const gp_Ax1& A1) const
{
gp_Sphere C = *this;
C.pos.Mirror (A1);
return C;
}
void gp_Sphere::Mirror (const gp_Ax2& A2)
{ pos.Mirror (A2); }
gp_Sphere gp_Sphere::Mirrored (const gp_Ax2& A2) const
{
gp_Sphere C = *this;
C.pos.Mirror (A2);
return C;
}

121
src/gp/gp_Sphere.lxx Executable file
View File

@@ -0,0 +1,121 @@
//File gp_Sphere.lxx
inline gp_Sphere::gp_Sphere () : radius (RealLast())
{ }
inline gp_Sphere::gp_Sphere (const gp_Ax3& A3,
const Standard_Real Radius) :
pos (A3),
radius (Radius)
{ Standard_ConstructionError_Raise_if (Radius < 0.0,""); }
inline void gp_Sphere::SetLocation (const gp_Pnt& Loc)
{ pos.SetLocation (Loc); }
inline void gp_Sphere::SetPosition (const gp_Ax3& A3)
{ pos = A3; }
inline void gp_Sphere::SetRadius (const Standard_Real R)
{
Standard_ConstructionError_Raise_if (R < 0.0,"");
radius = R;
}
inline Standard_Real gp_Sphere::Area () const
{ return 4.0 * Standard_PI * radius * radius; }
inline void gp_Sphere::UReverse()
{ pos.YReverse(); }
inline void gp_Sphere::VReverse()
{ pos.ZReverse(); }
inline Standard_Boolean gp_Sphere::Direct() const
{ return pos.Direct(); }
inline const gp_Pnt& gp_Sphere::Location () const
{ return pos.Location(); }
inline const gp_Ax3& gp_Sphere::Position () const
{ return pos; }
inline Standard_Real gp_Sphere::Radius () const
{ return radius; }
inline Standard_Real gp_Sphere::Volume () const
{ return (4.0 * Standard_PI * radius * radius * radius) / 3.0; }
inline gp_Ax1 gp_Sphere::XAxis () const
{ return gp_Ax1(pos.Location(), pos.XDirection()); }
inline gp_Ax1 gp_Sphere::YAxis () const
{ return gp_Ax1(pos.Location(), pos.YDirection()); }
inline void gp_Sphere::Rotate (const gp_Ax1& A1,
const Standard_Real Ang)
{ pos.Rotate (A1, Ang); }
inline gp_Sphere gp_Sphere::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Sphere C = *this;
C.pos.Rotate (A1, Ang);
return C;
}
inline void gp_Sphere::Scale (const gp_Pnt& P,
const Standard_Real S)
{
pos.Scale (P, S);
radius *= S;
if (radius < 0) radius = - radius;
}
inline gp_Sphere gp_Sphere::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Sphere C = *this;
C.pos.Scale (P, S);
C.radius *= S;
if (C.radius < 0) C.radius = - C.radius;
return C;
}
inline void gp_Sphere::Transform (const gp_Trsf& T)
{
pos.Transform (T);
radius *= T.ScaleFactor();
if (radius < 0) radius = - radius;
}
inline gp_Sphere gp_Sphere::Transformed (const gp_Trsf& T) const
{
gp_Sphere C = *this;
C.pos.Transform (T);
C.radius *= T.ScaleFactor();
if (C.radius < 0) C.radius = - C.radius;
return C;
}
inline void gp_Sphere::Translate (const gp_Vec& V)
{ pos.Translate (V); }
inline gp_Sphere gp_Sphere::Translated (const gp_Vec& V) const
{
gp_Sphere C = *this;
C.pos.Translate (V);
return C;
}
inline void gp_Sphere::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{ pos.Translate (P1, P2); }
inline gp_Sphere gp_Sphere::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Sphere C = *this;
C.pos.Translate (P1, P2);
return C;
}

290
src/gp/gp_Torus.cdl Executable file
View File

@@ -0,0 +1,290 @@
---Copyright: Matra Datavision 1991
class Torus from gp inherits Storable
--- Purpose :
-- Describes a torus.
-- A torus is defined by its major and minor radii and
-- positioned in space with a coordinate system (a gp_Ax3
-- object) as follows:
-- - The origin of the coordinate system is the center of the torus;
-- - The surface is obtained by rotating a circle of radius
-- equal to the minor radius of the torus about the "main
-- Direction" of the coordinate system. This circle is
-- located in the plane defined by the origin, the "X
-- Direction" and the "main Direction" of the coordinate
-- system. It is centered on the "X Axis" of this coordinate
-- system, and located at a distance, from the origin of
-- this coordinate system, equal to the major radius of the torus;
-- - The "X Direction" and "Y Direction" define the
-- reference plane of the torus.
-- The coordinate system described above is the "local
-- coordinate system" of the torus.
-- Note: when a gp_Torus torus is converted into a
-- Geom_ToroidalSurface torus, some implicit properties
-- of its local coordinate system are used explicitly:
-- - its origin, "X Direction", "Y Direction" and "main
-- Direction" are used directly to define the parametric
-- directions on the torus and the origin of the parameters,
-- - its implicit orientation (right-handed or left-handed)
-- gives the orientation (direct, indirect) to the
-- Geom_ToroidalSurface torus.
-- See Also
-- gce_MakeTorus which provides functions for more
-- complex torus constructions
-- Geom_ToroidalSurface which provides additional
-- functions for constructing tori and works, in particular,
-- with the parametric equations of tori.
uses Array1OfReal from TColStd,
Ax1 from gp,
Ax2 from gp,
Ax3 from gp,
Dir from gp,
Pnt from gp,
Trsf from gp,
Vec from gp
raises ConstructionError from Standard,
DimensionError from Standard
is
Create returns Torus;
---C++: inline
--- Purpose : creates an indefinite Torus.
Create (A3 : Ax3; MajorRadius, MinorRadius : Real) returns Torus
---C++: inline
--- Purpose :
-- a torus centered on the origin of coordinate system
-- A3, with major radius MajorRadius and minor radius
-- MinorRadius, and with the reference plane defined
-- by the origin, the "X Direction" and the "Y Direction" of A3.
-- Warnings :
-- It is not forbidden to create a torus with
-- MajorRadius = MinorRadius = 0.0
-- Raises ConstructionError if MinorRadius < 0.0 or if MajorRadius < 0.0
raises ConstructionError;
SetAxis (me : in out; A1 : Ax1)
---C++: inline
--- Purpose : Modifies this torus, by redefining its local coordinate
-- system so that:
-- - its origin and "main Direction" become those of the
-- axis A1 (the "X Direction" and "Y Direction" are then recomputed).
-- Raises ConstructionError if the direction of A1 is parallel to the "XDirection"
-- of the coordinate system of the toroidal surface.
raises ConstructionError
is static;
SetLocation (me : in out; Loc : Pnt) is static;
---C++:inline
--- Purpose : Changes the location of the torus.
SetMajorRadius (me : in out; MajorRadius : Real)
---C++: inline
--- Purpose : Assigns value to the major radius of this torus.
-- Raises ConstructionError if MajorRadius - MinorRadius <= Resolution()
raises ConstructionError
is static;
SetMinorRadius (me : in out; MinorRadius : Real)
---C++: inline
--- Purpose : Assigns value to the minor radius of this torus.
-- Raises ConstructionError if MinorRadius < 0.0 or if
-- MajorRadius - MinorRadius <= Resolution from gp.
raises ConstructionError
is static;
SetPosition (me : in out; A3 : Ax3) is static;
---C++: inline
--- Purpose : Changes the local coordinate system of the surface.
Area (me) returns Real is static;
---C++: inline
--- Purpose : Computes the area of the torus.
UReverse (me : in out)
---C++: inline
---Purpose: Reverses the U parametrization of the torus
-- reversing the YAxis.
is static;
VReverse (me : in out)
---Purpose: Reverses the V parametrization of the torus
-- reversing the ZAxis.
is static;
Direct (me) returns Boolean from Standard
---C++:inline
---Purpose: returns true if the Ax3, the local coordinate system of this torus, is right handed.
is static;
Axis (me) returns Ax1 is static;
---C++:inline
--- Purpose : returns the symmetry axis of the torus.
---C++: return const&
Coefficients (me; Coef : out Array1OfReal from TColStd)
--- Purpose :
-- Computes the coefficients of the implicit equation of the surface
-- in the absolute cartesian coordinate system :
-- Coef(1) * X**4 + Coef(2) * Y**4 + Coef(3) * Z**4 +
-- Coef(4) * X**3 * Y + Coef(5) * X**3 * Z + Coef(6) * Y**3 * X +
-- Coef(7) * Y**3 * Z + Coef(8) * Z**3 * X + Coef(9) * Z**3 * Y +
-- Coef(10) * X**2 * Y**2 + Coef(11) * X**2 * Z**2 +
-- Coef(12) * Y**2 * Z**2 + Coef(13) * X**3 + Coef(14) * Y**3 +
-- Coef(15) * Z**3 + Coef(16) * X**2 * Y + Coef(17) * X**2 * Z +
-- Coef(18) * Y**2 * X + Coef(19) * Y**2 * Z + Coef(20) * Z**2 * X +
-- Coef(21) * Z**2 * Y + Coef(22) * X**2 + Coef(23) * Y**2 +
-- Coef(24) * Z**2 + Coef(25) * X * Y + Coef(26) * X * Z +
-- Coef(27) * Y * Z + Coef(28) * X + Coef(29) * Y + Coef(30) * Z +
-- Coef(31) = 0.0
-- Raises DimensionError if the length of Coef is lower than 31.
raises DimensionError
is static;
Location (me) returns Pnt is static;
---C++:inline
--- Purpose : Returns the Torus's location.
---C++: return const&
Position (me) returns Ax3 is static;
--- Purpose : Returns the local coordinates system of the torus.
---C++: inline
---C++: return const&
MajorRadius (me) returns Real is static;
--- Purpose : returns the major radius of the torus.
---C++: inline
MinorRadius (me) returns Real is static;
--- Purpose : returns the minor radius of the torus.
---C++: inline
Volume (me) returns Real is static;
--- Purpose : Computes the volume of the torus.
---C++: inline
XAxis (me) returns Ax1 is static;
---C++:inline
--- Purpose : returns the axis X of the torus.
YAxis (me) returns Ax1 is static;
---C++:inline
--- Purpose : returns the axis Y of the torus.
Mirror (me : in out; P : Pnt)
is static;
Mirrored (me; P : Pnt) returns Torus is static;
--- Purpose :
-- Performs the symmetrical transformation of a torus
-- with respect to the point P which is the center of the
-- symmetry.
Mirror (me : in out; A1 : Ax1)
is static;
Mirrored (me; A1 : Ax1) returns Torus is static;
--- Purpose :
-- Performs the symmetrical transformation of a torus with
-- respect to an axis placement which is the axis of the
-- symmetry.
Mirror (me : in out; A2 : Ax2)
is static;
Mirrored (me; A2 : Ax2) returns Torus is static;
--- Purpose :
-- Performs the symmetrical transformation of a torus with respect
-- to a plane. The axis placement A2 locates the plane of the
-- of the symmetry : (Location, XDirection, YDirection).
Rotate (me : in out; A1 : Ax1; Ang : Real)
---C++:inline
is static;
Rotated (me; A1 : Ax1; Ang : Real) returns Torus is static;
---C++:inline
--- Purpose :
-- Rotates a torus. A1 is the axis of the rotation.
-- Ang is the angular value of the rotation in radians.
Scale (me : in out; P : Pnt; S : Real) is static;
---C++:inline
Scaled (me; P : Pnt; S : Real) returns Torus is static;
---C++:inline
--- Purpose :
-- Scales a torus. S is the scaling value.
-- The absolute value of S is used to scale the torus
Transform (me : in out; T : Trsf) is static;
---C++:inline
Transformed (me; T : Trsf) returns Torus is static;
---C++:inline
--- Purpose :
-- Transforms a torus with the transformation T from class Trsf.
Translate (me : in out; V : Vec)
---C++:inline
is static;
Translated (me; V : Vec) returns Torus is static;
---C++:inline
--- Purpose :
-- Translates a torus in the direction of the vector V.
-- The magnitude of the translation is the vector's magnitude.
Translate (me : in out; P1, P2 : Pnt) is static;
---C++:inline
Translated (me; P1, P2 : Pnt) returns Torus is static;
---C++:inline
--- Purpose :
-- Translates a torus from the point P1 to the point P2.
fields
pos : Ax3;
majorRadius : Real;
minorRadius : Real;
end;

203
src/gp/gp_Torus.cxx Executable file
View File

@@ -0,0 +1,203 @@
//File gp_Torus.cxx JCV 09/03/91
#include <gp_Torus.ixx>
#include <gp.hxx>
#include <Standard_ConstructionError.hxx>
#include <Standard_DimensionError.hxx>
void gp_Torus::Coefficients (TColStd_Array1OfReal& Coef) const
{
// Dans le repere local du tore :
// X*X + Y*Y + Z*Z - 2.0 * majorRadius * sqrt (X*X + Y*Y)
// - minorRadius * minorRadius + majorRadius * majorRadius = 0.0
// X**4 + Y **4 + 2.0 * (X*Y)**2 + 2.0 * (X*Z)**2 + 2.0 * (Y*Z)**2 -
// 2.0 * (majorRadius + minorRadius) * (X**2 + Y**2) +
// 2.0 * (majorRadius - minorRadius) * Z**2 - 2.0 *
// majorRadius * minorRadius = 0.0
Standard_Integer Low = Coef.Lower();
Standard_DimensionError_Raise_if (Coef.Length() < 31, " ");
gp_Trsf T;
Standard_Real SumRadius = (majorRadius * majorRadius +
minorRadius * minorRadius);
Standard_Real SubRadius = (majorRadius * majorRadius -
minorRadius * minorRadius);
T.SetTransformation (pos);
Standard_Real T11 = T.Value (1, 1);
Standard_Real T12 = T.Value (1, 2);
Standard_Real T13 = T.Value (1, 3);
Standard_Real T14 = T.Value (1, 4);
Standard_Real T21 = T.Value (2, 1);
Standard_Real T22 = T.Value (2, 2);
Standard_Real T23 = T.Value (2, 3);
Standard_Real T24 = T.Value (2, 4);
Standard_Real T31 = T.Value (3, 1);
Standard_Real T32 = T.Value (3, 2);
Standard_Real T33 = T.Value (3, 3);
Standard_Real T34 = T.Value (3, 4);
Coef(Low) = Pow (T11, 4) + Pow (T21, 4) + Pow(T31, 4) +
2.0 * (T11 * T11 * T21 * T21 + T11 * T11 * T31 * T31 +
T21 * T21 * T31 * T31);
Coef(Low+1) = Pow (T12, 4) + Pow (T22, 4) + Pow(T32, 4) +
2.0 * (T12 * T12 * T22 * T22 + T12 * T12 * T32 * T32 +
T22 * T22 * T32 * T32);
Coef(Low+2) = Pow (T13, 4) + Pow (T23, 4) + Pow(T33, 4) +
2.0 * (T13 * T13 * T23 * T23 + T13 * T13 * T33 * T33 +
T23 * T23 * T33 * T33);
Coef(Low+3) = 4.0 * (Pow (T11, 3) * T12 + Pow (T21, 3) * T22 +
Pow (T31, 3) * T32 + T11 * T11 * T21 * T22 + T21 * T21 * T11 * T12 +
T11 * T11 * T31 * T32 + T31 * T31 * T11 * T12 + T21 * T21 * T31 * T32
+ T31 * T31 * T21 * T22);
Coef(Low+4) = 4.0 * (Pow (T11, 3) * T13 + Pow (T21, 3) * T23 +
Pow (T31, 3) * T33 + T11 * T11 * T21 * T23 + T21 * T21 * T11 * T13 +
T11 * T11 * T31 * T33 + T31 * T31 * T11 * T13 + T21 * T21 * T31 * T33
+ T31 * T31 * T21 * T23);
Coef(Low+5) = 4.0 * (Pow (T12, 3) * T11 + Pow (T22, 3) * T21 +
Pow (T32, 3) * T31 + T12 * T12 * T21 * T22 + T22 * T22 * T11 * T12 +
T12 * T12 * T31 * T32 + T32 * T32 * T11 * T12 + T22 * T22 * T31 * T32
+ T32 * T32 * T21 * T22);
Coef(Low+6) = 4.0 * (Pow (T12, 3) * T13 + Pow (T22, 3) * T23 +
Pow (T32, 3) * T33 + T12 * T12 * T22 * T23 + T22 * T22 * T12 * T13 +
T12 * T12 * T32 * T33 + T32 * T32 * T12 * T13 + T22 * T22 * T32 * T33
+ T32 * T32 * T22 * T23);
Coef(Low+7) = 4.0 * (Pow (T13, 3) * T11 + Pow (T23, 3) * T21 +
Pow (T33, 3) * T31 + T13 * T13 * T21 * T23 + T23 * T23 * T11 * T13 +
T13 * T13 * T31 * T33 + T33 * T33 * T11 * T13 + T23 * T23 * T31 * T33
+ T33 * T33 * T21 * T23);
Coef(Low+8) = 4.0 * (Pow (T13, 3) * T12 + Pow (T23, 3) * T22 +
Pow (T33, 3) * T32 + T13 * T13 * T22 * T23 + T23 * T23 * T12 * T13 +
T13 * T13 * T32 * T33 + T33 * T33 * T12 * T13 + T23 * T23 * T32 * T33
+ T33 * T33 * T22 * T23);
Coef(Low+9) = 6.0 * (T11 * T11 * T12 * T12 + T21 * T21 * T22 * T22 +
T31 * T31 * T32 * T32) + 8.0 * ( T11 * T12 * T21 * T22 +
T11 * T12 * T31 * T32 + T21 * T22 * T31 * T32) +
2.0 * (T11 * T11 * T22 * T22 + T11 * T11 * T32 * T32 +
T21 * T21 * T32 * T32 + T12 * T12 * T21 * T21 +
T12 * T12 * T31 * T31 + T22 * T22 * T31 * T31 );
Coef(Low+10) = 6.0 * (T11 * T11 * T13 * T13 + T21 * T21 * T23 * T23 +
T31 * T31 * T33 * T33) + 8.0 * ( T11 * T13 * T21 * T23 +
T11 * T13 * T31 * T33 + T21 * T23 * T31 * T33) +
2.0 * (T11 * T11 * T23 * T23 + T11 * T11 * T33 * T33 +
T21 * T21 * T33 * T33 + T13 * T13 * T21 * T21 +
T13 * T13 * T31 * T31 + T23 * T23 * T31 * T31);
Coef(Low+11) = 6.0 * (T12 * T12 * T13 * T13 + T22 * T22 * T23 * T23 +
T32 * T32 * T33 * T33) + 8.0 * ( T12 * T13 * T22 * T23 +
T12 * T23 * T32 * T33 + T22 * T23 * T32 * T33) +
2.0 * (T12 * T12 * T23 * T23 + T12 * T12 * T33 * T33 +
T22 * T22 * T33 * T33 + T13 * T13 * T22 * T22 +
T13 * T13 * T32 * T32 + T23 * T23 * T32 * T32);
Coef(Low+12) = 4.0 * (Pow (T11, 3) * T14 + Pow (T21, 3) * T24 +
Pow (T31, 3) * T34 + T11 * T11 * T21 * T24 + T11 * T11 * T31 * T34 +
T21 * T21 * T31 * T34 + T21 * T21 * T11 * T14 +
T31 * T31 * T11 * T34 + T31 * T31 * T21 * T24);
Coef(Low+13) = 4.0 * (Pow (T12, 3) * T14 + Pow (T22, 3) * T24 +
Pow (T32, 3) * T34 + T12 * T12 * T22 * T24 + T12 * T12 * T32 * T34 +
T22 * T22 * T32 * T34 + T22 * T22 * T12 * T14 +
T32 * T32 * T12 * T34 + T32 * T32 * T22 * T24);
Coef(Low+14) = 4.0 * (Pow (T13, 3) * T14 + Pow (T23, 3) * T24 +
Pow (T33, 3) * T34 + T13 * T13 * T23 * T24 + T13 * T13 * T33 * T34 +
T23 * T23 * T33 * T34 + T23 * T23 * T13 * T14 +
T33 * T33 * T13 * T34 + T33 * T33 * T23 * T24);
Coef(Low+15) = 4.0 * (T11 * T11 * T22 * T24 + T11 * T11 * T32 * T34 +
T21 * T21 * T32 * T34 + T21 * T21 * T12 * T14 + T31 * T31 * T12 * T14
+ T31 * T31 * T22 * T24);
Coef(Low+16) = 4.0 * (T11 * T11 * T23 * T24 + T11 * T11 * T33 * T34 +
T21 * T21 * T33 * T34 + T21 * T21 * T13 * T14 + T31 * T31 * T13 * T14
+ T31 * T31 * T23 * T24);
Coef(Low+17) = 4.0 * (T12 * T12 * T21 * T24 + T12 * T12 * T31 * T34 +
T22 * T22 * T31 * T34 + T22 * T22 * T11 * T14 + T32 * T32 * T11 * T14
+ T32 * T32 * T21 * T24);
Coef(Low+18) = 4.0 * (T12 * T12 * T23 * T24 + T12 * T12 * T33 * T34 +
T22 * T22 * T33 * T34 + T22 * T22 * T13 * T14 + T32 * T32 * T13 * T14
+ T32 * T32 * T23 * T24);
Coef(Low+19) = 4.0 * (T13 * T13 * T21 * T24 + T13 * T13 * T31 * T34 +
T23 * T23 * T31 * T34 + T23 * T23 * T11 * T14 + T33 * T33 * T11 * T14
+ T33 * T33 * T21 * T24);
Coef(Low+20) = 4.0 * (T13 * T13 * T22 * T24 + T13 * T13 * T32 * T34 +
T23 * T23 * T32 * T34 + T23 * T23 * T12 * T14 + T33 * T33 * T12 * T14
+ T33 * T33 * T22 * T24);
Coef(Low+21) = 6.0 * (T11 * T11 * T14 * T14 + T21 * T21 * T24 * T24 +
T31 * T31 * T34 * T34) + 2.0 * (T11 * T11 * T24 * T24 +
T11 * T11 * T34 * T34 + T21 * T21 * T34 * T34 + T21 * T21 * T14 * T14
+ T31 * T31 * T14 * T14 + T31 * T31 * T24 * T24 -
SumRadius * (T11 * T11 + T21 * T21) + SubRadius * T31 * T31);
Coef(Low+22) = 6.0 * (T12 * T12 * T14 * T14 + T22 * T22 * T24 * T24 +
T32 * T32 * T34 * T34) + 2.0 * (T12 * T12 * T24 * T24 +
T12 * T12 * T34 * T34 + T22 * T22 * T34 * T34 + T22 * T22 * T14 * T14
+ T32 * T32 * T14 * T14 + T32 * T32 * T24 * T24 -
SumRadius * (T12 * T12 + T22 * T22) + SubRadius * T32 * T32);
Coef(Low+23) = 6.0 * (T13 * T13 * T14 * T14 + T23 * T23 * T24 * T24 +
T33 * T33 * T34 * T34) + 2.0 * (T13 * T13 * T24 * T24 +
T13 * T13 * T34 * T34 + T23 * T23 * T34 * T34 + T23 * T23 * T14 * T14
+ T33 * T33 * T14 * T14 + T33 * T33 * T24 * T24 -
SumRadius * (T13 * T13 + T23 * T23) + SubRadius * T33 * T33);
Coef(Low+24) = 8.0 * (T11 * T14 * T22 * T24 + T11 * T14 * T32 * T34 +
T21 * T24 * T32 * T34 + T21 * T24 * T12 * T14 + T31 * T34 * T12 * T14
+ T31 * T34 *T22 * T24) + 4.0 * (T11 * T12 * T24 * T24 +
T11 * T12 * T34 * T34 + T21 * T22 * T34 * T34 + T21 * T22 * T14 * T14
+ T31 * T32 * T14 * T14 + T31 * T32 * T24 * T24 - SumRadius * (
T11 * T12 + T21 * T22) + SubRadius * T31 * T32);
Coef(Low+25) = 8.0 * (T11 * T14 * T23 * T24 + T11 * T14 * T33 * T34 +
T21 * T24 * T33 * T34 + T21 * T24 * T13 * T14 + T31 * T34 * T13 * T14
+ T31 * T34 *T23 * T24) + 4.0 * (T11 * T13 * T24 * T24 +
T11 * T13 * T34 * T34 + T21 * T23 * T34 * T34 + T21 * T23 * T14 * T14
+ T31 * T33 * T14 * T14 + T31 * T33 * T24 * T24 - SumRadius * (
T11 * T13 + T21 * T22) + SubRadius * T31 * T33);
Coef(Low+26) = 8.0 * (T12 * T14 * T23 * T24 + T12 * T14 * T33 * T34 +
T22 * T24 * T33 * T34 + T22 * T24 * T13 * T14 + T32 * T34 * T13 * T14
+ T32 * T34 *T23 * T24) + 4.0 * (T12 * T13 * T24 * T24 +
T12 * T13 * T34 * T34 + T22 * T23 * T34 * T34 + T22 * T23 * T14 * T14
+ T32 * T33 * T14 * T14 + T32 * T33 * T24 * T24 - SumRadius * (
T12 * T13 + T21 * T22) + SubRadius * T32 * T33);
Coef(Low+27) = 4.0 * (Pow (T14, 3) * T11 + Pow (T24, 3) * T21 +
Pow (T34, 3) * T31 + T11 * T14 * T24 * T24 + T11 * T14 * T34 * T34
+ T21 * T24 * T34 * T34 + T21 * T24 * T14 * T14 +
T31 * T34 * T14 * T14 + T31 * T34 * T24 * T24 + SubRadius * T31 * T34
- SumRadius * (T11 * T14 + T21 * T24));
Coef(Low+28) = 4.0 * (Pow (T14, 3) * T12 + Pow (T24, 3) * T22 +
Pow (T34, 3) * T32 + T12 * T14 * T24 * T24 + T12 * T14 * T34 * T34
+ T22 * T24 * T34 * T34 + T22 * T24 * T14 * T14 +
T32 * T34 * T14 * T14 + T32 * T34 * T24 * T24 + SubRadius * T32 * T34
- SumRadius * (T12 * T14 + T22 * T24));
Coef(Low+29) = 4.0 * (Pow (T14, 3) * T13 + Pow (T24, 3) * T23 +
Pow (T34, 3) * T33 + T13 * T14 * T24 * T24 + T13 * T14 * T34 * T34
+ T23 * T24 * T34 * T34 + T23 * T24 * T14 * T14 +
T33 * T34 * T14 * T14 + T33 * T34 * T24 * T24 + SubRadius * T33 * T34
- SumRadius * (T13 * T14 + T21 * T24));
Coef(Low+30) = Pow (T14, 4) + Pow (T24, 4) + Pow (T34, 4) + 2.0 * (
T14 * T14 * T24 * T24 + T14 * T14 * T34 * T34 + T24 * T24 * T34 * T34
- SumRadius * (T14 * T14 + T24 * T24) + SubRadius * T34 * T34 -
majorRadius * majorRadius * minorRadius * minorRadius);
}
void gp_Torus::Mirror (const gp_Pnt& P)
{ pos.Mirror (P); }
gp_Torus gp_Torus::Mirrored (const gp_Pnt& P) const
{
gp_Torus C = *this;
C.pos.Mirror (P);
return C;
}
void gp_Torus::Mirror (const gp_Ax1& A1)
{ pos.Mirror (A1); }
gp_Torus gp_Torus::Mirrored (const gp_Ax1& A1) const
{
gp_Torus C = *this;
C.pos.Mirror (A1);
return C;
}
void gp_Torus::Mirror (const gp_Ax2& A2)
{ pos.Mirror (A2); }
gp_Torus gp_Torus::Mirrored (const gp_Ax2& A2) const
{
gp_Torus C = *this;
C.pos.Mirror (A2);
return C;
}

153
src/gp/gp_Torus.lxx Executable file
View File

@@ -0,0 +1,153 @@
//File gp_Torus.lxx
inline gp_Torus::gp_Torus () :
majorRadius (RealLast()),
minorRadius (RealSmall())
{ }
inline gp_Torus::gp_Torus (const gp_Ax3& A3,
const Standard_Real MajorRadius,
const Standard_Real MinorRadius) :
pos(A3),
majorRadius (MajorRadius),
minorRadius (MinorRadius)
{
Standard_ConstructionError_Raise_if
(MinorRadius < 0.0 || MajorRadius < 0.0,"");
}
inline void gp_Torus::SetAxis (const gp_Ax1& A1)
{ pos.SetAxis (A1); }
inline void gp_Torus::SetLocation (const gp_Pnt& Loc)
{ pos.SetLocation (Loc); }
inline void gp_Torus::SetMajorRadius (const Standard_Real MajorRadius)
{
Standard_ConstructionError_Raise_if
(MajorRadius - minorRadius <= gp::Resolution(),"");
majorRadius = MajorRadius;
}
inline void gp_Torus::SetMinorRadius (const Standard_Real MinorRadius)
{
Standard_ConstructionError_Raise_if
(MinorRadius < 0.0 || majorRadius - MinorRadius <= gp::Resolution(),"");
minorRadius = MinorRadius;
}
inline void gp_Torus::SetPosition (const gp_Ax3& A3)
{ pos = A3; }
inline Standard_Real gp_Torus::Area () const
{ return 4.0 * Standard_PI * Standard_PI * minorRadius * majorRadius; }
inline void gp_Torus::UReverse()
{ pos.YReverse(); }
inline void gp_Torus::VReverse()
{ pos.ZReverse(); }
inline Standard_Boolean gp_Torus::Direct() const
{ return pos.Direct(); }
inline const gp_Ax1& gp_Torus::Axis () const
{ return pos.Axis(); }
inline const gp_Pnt& gp_Torus::Location () const
{ return pos.Location(); }
inline const gp_Ax3& gp_Torus::Position () const
{ return pos; }
inline Standard_Real gp_Torus::MajorRadius () const
{ return majorRadius; }
inline Standard_Real gp_Torus::MinorRadius () const
{ return minorRadius; }
inline Standard_Real gp_Torus::Volume () const
{ return (Standard_PI * minorRadius * minorRadius) * (2.0 * Standard_PI * majorRadius); }
inline gp_Ax1 gp_Torus::XAxis () const
{ return gp_Ax1(pos.Location(), pos.XDirection()); }
inline gp_Ax1 gp_Torus::YAxis () const
{ return gp_Ax1(pos.Location(), pos.YDirection()); }
inline void gp_Torus::Rotate (const gp_Ax1& A1,
const Standard_Real Ang)
{ pos.Rotate (A1, Ang); }
inline gp_Torus gp_Torus::Rotated (const gp_Ax1& A1,
const Standard_Real Ang) const
{
gp_Torus C = *this;
C.pos.Rotate (A1, Ang);
return C;
}
inline void gp_Torus::Scale (const gp_Pnt& P,
const Standard_Real S)
{
pos.Scale (P, S);
Standard_Real s = S;
if (s < 0) s = - s;
majorRadius *= s;
minorRadius *= s;
}
inline gp_Torus gp_Torus::Scaled (const gp_Pnt& P,
const Standard_Real S) const
{
gp_Torus C = *this;
C.pos.Scale (P, S);
C.majorRadius *= S;
if (C.majorRadius < 0) C.majorRadius = - C.majorRadius;
C.minorRadius *= S;
if (C.minorRadius < 0) C.minorRadius = - C.minorRadius;
return C;
}
inline void gp_Torus::Transform (const gp_Trsf& T)
{
pos.Transform (T);
Standard_Real t = T.ScaleFactor();
if(t < 0 ) t = - t;
minorRadius *= t;
majorRadius *= t;
}
inline gp_Torus gp_Torus::Transformed (const gp_Trsf& T) const
{
gp_Torus C = *this;
C.pos.Transform (T);
C.majorRadius *= T.ScaleFactor();
if (C.majorRadius < 0) C.majorRadius = - C.majorRadius;
C.minorRadius *= T.ScaleFactor();
if (C.minorRadius < 0) C.minorRadius = - C.minorRadius;
return C;
}
inline void gp_Torus::Translate (const gp_Vec& V)
{ pos.Translate (V); }
inline gp_Torus gp_Torus::Translated (const gp_Vec& V) const
{
gp_Torus C = *this;
C.pos.Translate (V);
return C;
}
inline void gp_Torus::Translate (const gp_Pnt& P1,
const gp_Pnt& P2)
{ pos.Translate (P1, P2); }
inline gp_Torus gp_Torus::Translated (const gp_Pnt& P1,
const gp_Pnt& P2) const
{
gp_Torus C = *this;
C.pos.Translate (P1, P2);
return C;
}

380
src/gp/gp_Trsf.cdl Executable file
View File

@@ -0,0 +1,380 @@
---Copyright: Matra Datavision 1991
class Trsf from gp inherits Storable
--- Purpose: Defines a non-persistent transformation in 3D space.
-- The following transformations are implemented :
-- . Translation, Rotation, Scale
-- . Symmetry with respect to a point, a line, a plane.
-- Complex transformations can be obtained by combining the
-- previous elementary transformations using the method
-- Multiply.
-- The transformations can be represented as follow :
--
-- V1 V2 V3 T XYZ XYZ
-- | a11 a12 a13 a14 | | x | | x'|
-- | a21 a22 a23 a24 | | y | | y'|
-- | a31 a32 a33 a34 | | z | = | z'|
-- | 0 0 0 1 | | 1 | | 1 |
--
-- where {V1, V2, V3} defines the vectorial part of the
-- transformation and T defines the translation part of the
-- transformation.
uses Ax1 from gp,
Ax2 from gp,
Ax3 from gp,
Mat from gp,
Pnt from gp,
TrsfForm from gp,
Vec from gp,
XYZ from gp,
Trsf2d from gp,
Quaternion from gp
raises ConstructionError from Standard,
OutOfRange from Standard
is
Create returns Trsf from gp;
---C++: inline
--- Purpose : Returns the identity transformation.
Create(T : Trsf2d from gp) returns Trsf from gp;
---C++: inline
---Purpose: Creates a 3D transformation from the 2D transformation T.
-- The resulting transformation has a homogeneous
-- vectorial part, V3, and a translation part, T3, built from T:
-- a11 a12
-- 0 a13
-- V3 = a21 a22 0 T3
-- = a23
-- 0 0 1.
-- 0
-- It also has the same scale factor as T. This
-- guarantees (by projection) that the transformation
-- which would be performed by T in a plane (2D space)
-- is performed by the resulting transformation in the xOy
-- plane of the 3D space, (i.e. in the plane defined by the
-- origin (0., 0., 0.) and the vectors DX (1., 0., 0.), and DY
-- (0., 1., 0.)). The scale factor is applied to the entire space.
SetMirror (me : in out; P : Pnt) is static;
---C++: inline
--- Purpose :
-- Makes the transformation into a symmetrical transformation.
-- P is the center of the symmetry.
SetMirror (me : in out; A1 : Ax1) is static;
--- Purpose :
-- Makes the transformation into a symmetrical transformation.
-- A1 is the center of the axial symmetry.
SetMirror (me : in out; A2 : Ax2) is static;
--- Purpose :
-- Makes the transformation into a symmetrical transformation.
-- A2 is the center of the planar symmetry
-- and defines the plane of symmetry by its origin, "X
-- Direction" and "Y Direction".
SetRotation (me : in out; A1 : Ax1; Ang : Real) is static;
--- Purpose :
-- Changes the transformation into a rotation.
-- A1 is the rotation axis and Ang is the angular value of the
-- rotation in radians.
SetRotation (me : in out; R : Quaternion) is static;
--- Purpose :
-- Changes the transformation into a rotation defined by quaternion.
-- Note that rotation is performed around origin, i.e.
-- no translation is involved.
SetScale (me : in out; P : Pnt; S : Real)
--- Purpose :
-- Changes the transformation into a scale.
-- P is the center of the scale and S is the scaling value.
-- Raises ConstructionError If <S> is null.
raises
ConstructionError from Standard
is static;
SetDisplacement (me : in out; FromSystem1, ToSystem2 : Ax3) is static;
--- Purpose :
-- Modifies this transformation so that it transforms the
-- coordinate system defined by FromSystem1 into the
-- one defined by ToSystem2. After this modification, this
-- transformation transforms:
-- - the origin of FromSystem1 into the origin of ToSystem2,
-- - the "X Direction" of FromSystem1 into the "X
-- Direction" of ToSystem2,
-- - the "Y Direction" of FromSystem1 into the "Y
-- Direction" of ToSystem2, and
-- - the "main Direction" of FromSystem1 into the "main
-- Direction" of ToSystem2.
-- Warning
-- When you know the coordinates of a point in one
-- coordinate system and you want to express these
-- coordinates in another one, do not use the
-- transformation resulting from this function. Use the
-- transformation that results from SetTransformation instead.
-- SetDisplacement and SetTransformation create
-- related transformations: the vectorial part of one is the
-- inverse of the vectorial part of the other.
SetTransformation (me : in out; FromSystem1, ToSystem2 : Ax3) is static;
--- Purpose : Modifies this transformation so that it transforms the
-- coordinates of any point, (x, y, z), relative to a source
-- coordinate system into the coordinates (x', y', z') which
-- are relative to a target coordinate system, but which
-- represent the same point
-- The transformation is from the coordinate
-- system "FromSystem1" to the coordinate system "ToSystem2".
-- Example :
-- In a C++ implementation :
-- Real x1, y1, z1; // are the coordinates of a point in the
-- // local system FromSystem1
-- Real x2, y2, z2; // are the coordinates of a point in the
-- // local system ToSystem2
-- gp_Pnt P1 (x1, y1, z1)
-- Trsf T;
-- T.SetTransformation (FromSystem1, ToSystem2);
-- gp_Pnt P2 = P1.Transformed (T);
-- P2.Coord (x2, y2, z2);
SetTransformation (me : in out; ToSystem : Ax3) is static;
--- Purpose : Modifies this transformation so that it transforms the
-- coordinates of any point, (x, y, z), relative to a source
-- coordinate system into the coordinates (x', y', z') which
-- are relative to a target coordinate system, but which
-- represent the same point
-- The transformation is from the default coordinate system
-- {P(0.,0.,0.), VX (1.,0.,0.), VY (0.,1.,0.), VZ (0., 0. ,1.) }
-- to the local coordinate system defined with the Ax3 ToSystem.
-- Use in the same way as the previous method. FromSystem1 is
-- defaulted to the absolute coordinate system.
SetTransformation (me : in out; R : Quaternion; T : Vec) is static;
--- Purpose :
-- Sets transformation by directly specified rotation and translation.
SetTranslation (me : in out; V : Vec) is static;
---C++: inline
--- Purpose :
-- Changes the transformation into a translation.
-- V is the vector of the translation.
SetTranslation (me : in out; P1, P2 : Pnt) is static;
---C++: inline
--- Purpose :
-- Makes the transformation into a translation where the translation vector
-- is the vector (P1, P2) defined from point P1 to point P2.
SetTranslationPart (me : in out; V : Vec) is static;
--- Purpose : Replaces the translation vector with the vector V.
SetScaleFactor (me : in out; S : Real)
--- Purpose : Modifies the scale factor.
-- Raises ConstructionError If S is null.
raises
ConstructionError from Standard
is static;
SetValues(me : in out;
a11, a12, a13, a14,
a21, a22, a23, a24,
a31, a32, a33, a34 : Real;
Tolang, TolDist : Real)
---Purpose: Sets the coefficients of the transformation. The
-- transformation of the point x,y,z is the point
-- x',y',z' with :
--
-- x' = a11 x + a12 y + a13 z + a14
-- y' = a21 x + a22 y + a23 z + a24
-- z' = a31 x + a32 y + a43 z + a34
--
-- Tolang and TolDist are used to test for null
-- angles and null distances to determine the form of
-- the transformation (identity, translation, etc..).
--
-- The method Value(i,j) will return aij.
-- Raises ConstructionError if the determinant of the aij is null. Or if
-- the matrix as not a uniform scale.
raises
ConstructionError from Standard
is static;
IsNegative (me) returns Boolean is static;
---C++: inline
--- Purpose : Returns true if the determinant of the vectorial part of
-- this transformation is negative.
Form (me) returns TrsfForm is static;
--- Purpose :
-- Returns the nature of the transformation. It can be: an
-- identity transformation, a rotation, a translation, a mirror
-- transformation (relative to a point, an axis or a plane), a
-- scaling transformation, or a compound transformation.
---C++: inline
ScaleFactor (me) returns Real is static;
--- Purpose : Returns the scale factor.
---C++: inline
TranslationPart (me) returns XYZ is static;
--- Purpose :
-- Returns the translation part of the transformation's matrix
---C++: inline
---C++: return const&
GetRotation (me; theAxis : out XYZ from gp;
theAngle: out Real from Standard)
returns Boolean from Standard is static;
--- Purpose :
-- Returns the boolean True if there is non-zero rotation.
-- In the presence of rotation, the output parameters store the axis
-- and the angle of rotation. The method always returns positive
-- value "theAngle", i.e., 0. < theAngle <= PI.
-- Note that this rotation is defined only by the vectorial part of
-- the transformation; generally you would need to check also the
-- translational part to obtain the axis (gp_Ax1) of rotation.
GetRotation (me) returns Quaternion from gp is static;
--- Purpose :
-- Returns quaternion representing rotational part of the transformation.
VectorialPart (me) returns Mat is static;
--- Purpose :
-- Returns the vectorial part of the transformation. It is
-- a 3*3 matrix which includes the scale factor.
HVectorialPart (me) returns Mat is static;
--- Purpose :
-- Computes the homogeneous vectorial part of the transformation.
-- It is a 3*3 matrix which doesn't include the scale factor.
-- In other words, the vectorial part of this transformation is equal
-- to its homogeneous vectorial part, multiplied by the scale factor.
-- The coefficients of this matrix must be multiplied by the
-- scale factor to obtain the coefficients of the transformation.
---C++: inline
---C++: return const&
Value (me; Row, Col : Integer) returns Real
---C++: inline
--- Purpose :
-- Returns the coefficients of the transformation's matrix.
-- It is a 3 rows * 4 columns matrix.
-- This coefficient includes the scale factor.
-- Raises OutOfRanged if Row < 1 or Row > 3 or Col < 1 or Col > 4
raises OutOfRange
is static;
Invert (me : in out) raises ConstructionError is static;
Inverted (me) returns Trsf raises ConstructionError is static;
--- Purpose :
-- Computes the reverse transformation
-- Raises an exception if the matrix of the transformation
-- is not inversible, it means that the scale factor is lower
-- or equal to Resolution from package gp.
-- Computes the transformation composed with T and <me>.
-- In a C++ implementation you can also write Tcomposed = <me> * T.
--- Example :
-- Trsf T1, T2, Tcomp; ...............
-- Tcomp = T2.Multiplied(T1); // or (Tcomp = T2 * T1)
-- Pnt P1(10.,3.,4.);
-- Pnt P2 = P1.Transformed(Tcomp); //using Tcomp
-- Pnt P3 = P1.Transformed(T1); //using T1 then T2
-- P3.Transform(T2); // P3 = P2 !!!
---C++: inline
Multiplied (me; T : Trsf) returns Trsf is static;
---C++: inline
---C++: alias operator *
Multiply (me : in out; T : Trsf) is static;
---C++: alias operator *=
--- Purpose :
-- Computes the transformation composed with T and <me>.
-- In a C++ implementation you can also write Tcomposed = <me> * T.
-- Example :
-- Trsf T1, T2, Tcomp; ...............
-- //composition :
-- Tcomp = T2.Multiplied(T1); // or (Tcomp = T2 * T1)
-- // transformation of a point
-- Pnt P1(10.,3.,4.);
-- Pnt P2 = P1.Transformed(Tcomp); //using Tcomp
-- Pnt P3 = P1.Transformed(T1); //using T1 then T2
-- P3.Transform(T2); // P3 = P2 !!!
-- Computes the transformation composed with <me> and T.
-- <me> = T * <me>
PreMultiply (me : in out; T : Trsf) is static;
--- Purpose :
-- Computes the transformation composed with <me> and T.
-- <me> = T * <me>
Power (me : in out; N : Integer) raises ConstructionError is static;
Powered (me : in out; N : Integer) returns Trsf
---C++: inline
--- Purpose :
-- Computes the following composition of transformations
-- <me> * <me> * .......* <me>, N time.
-- if N = 0 <me> = Identity
-- if N < 0 <me> = <me>.Inverse() *...........* <me>.Inverse().
--
-- Raises if N < 0 and if the matrix of the transformation not
-- inversible.
raises ConstructionError
is static;
Transforms (me; X, Y, Z : out Real) is static;
---C++: inline
Transforms (me; Coord : out XYZ) is static;
---C++: inline
--- Purpose : Transformation of a triplet XYZ with a Trsf
fields
scale : Real;
shape : TrsfForm;
matrix : Mat;
loc : XYZ;
friends
class GTrsf
end;

782
src/gp/gp_Trsf.cxx Executable file
View File

@@ -0,0 +1,782 @@
// File gp_Trsf.cxx, JCV 03/06/90
// JCV 30/08/90 Modif passage version C++ 2.0 sur Sun
// JCV 1/10/90 Changement de nom du package vgeom -> gp
// JCV 4/10/90 codage sur la forme de la transformation shape,Scaling,negative
// JCV 10/12/90 Modif introduction des classes Mat et XYZ dans gp
#define No_Standard_OutOfRange
#include <gp_Trsf.ixx>
#include <gp.hxx>
#include <Standard_ConstructionError.hxx>
//=======================================================================
//function : SetMirror
//purpose :
//=======================================================================
void gp_Trsf::SetMirror (const gp_Ax1& A1)
{
shape = gp_Ax1Mirror;
scale = 1;
loc = A1.Location().XYZ();
matrix.SetDot(A1.Direction().XYZ());
matrix.Multiply(-2);
matrix.SetDiagonal (matrix.Value (1,1) + 1,
matrix.Value (2,2) + 1,
matrix.Value (3,3) + 1);
loc.Multiply (matrix);
loc.Add (A1.Location().XYZ());
matrix.Multiply(-1);
}
//=======================================================================
//function : SetMirror
//purpose :
//=======================================================================
void gp_Trsf::SetMirror (const gp_Ax2& A2)
{
shape = gp_Ax2Mirror;
scale = -1;
loc = A2.Location().XYZ();
matrix.SetDot(A2.Direction().XYZ());
matrix.Multiply(2);
matrix.SetDiagonal (matrix.Value (1,1) - 1,
matrix.Value (2,2) - 1,
matrix.Value (3,3) - 1);
loc.Multiply (matrix);
loc.Add (A2.Location().XYZ());
}
//=======================================================================
//function : SetRotation
//purpose :
//=======================================================================
void gp_Trsf::SetRotation (const gp_Ax1& A1,
const Standard_Real Ang)
{
shape = gp_Rotation;
scale = 1.;
loc = A1.Location().XYZ();
matrix.SetRotation (A1.Direction().XYZ(), Ang);
loc.Reverse ();
loc.Multiply (matrix);
loc.Add (A1.Location().XYZ());
}
//=======================================================================
//function : SetRotation
//purpose :
//=======================================================================
void gp_Trsf::SetRotation (const gp_Quaternion& R)
{
shape = gp_Rotation;
scale = 1.;
loc.SetCoord (0., 0., 0.);
matrix = R.GetMatrix();
}
//=======================================================================
//function : SetScale
//purpose :
//=======================================================================
void gp_Trsf::SetScale (const gp_Pnt& P, const Standard_Real S)
{
shape = gp_Scale;
scale = S;
loc = P.XYZ();
Standard_Real As = scale;
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As <= gp::Resolution(),"gp_Trsf::SetScaleFactor");
matrix.SetIdentity ();
loc.Multiply (1-S);
}
//=======================================================================
//function : SetTransformation
//purpose :
//=======================================================================
void gp_Trsf::SetTransformation (const gp_Ax3& FromA1,
const gp_Ax3& ToA2)
{
shape = gp_CompoundTrsf;
scale = 1.0;
// matrix from XOY ToA2 :
matrix.SetCol (1, ToA2.XDirection().XYZ());
matrix.SetCol (2, ToA2.YDirection().XYZ());
matrix.SetCol (3, ToA2.Direction().XYZ());
loc = ToA2.Location().XYZ();
matrix.Transpose();
loc.Multiply (matrix);
loc.Reverse ();
// matrix FromA1 to XOY :
const gp_XYZ& xDir = FromA1.XDirection().XYZ();
const gp_XYZ& yDir = FromA1.YDirection().XYZ();
const gp_XYZ& zDir = FromA1.Direction().XYZ();
gp_Mat MA1 (xDir, yDir, zDir);
gp_XYZ MA1loc = FromA1.Location().XYZ();
// matrix * MA1 => FromA1 ToA2 :
MA1loc.Multiply (matrix);
loc.Add (MA1loc);
matrix.Multiply (MA1);
}
void gp_Trsf::SetTransformation (const gp_Ax3& A3)
{
shape = gp_CompoundTrsf;
scale = 1.0;
loc = A3.Location().XYZ();
matrix.SetCols (A3.XDirection().XYZ(),
A3.YDirection().XYZ(),
A3. Direction().XYZ());
matrix.Transpose();
loc.Multiply (matrix);
loc.Reverse ();
}
//=======================================================================
//function : SetTransformation
//purpose :
//=======================================================================
void gp_Trsf::SetTransformation (const gp_Quaternion& R, const gp_Vec& T)
{
shape = gp_CompoundTrsf;
scale = 1.;
loc = T.XYZ();
matrix = R.GetMatrix();
}
//=======================================================================
//function : SetDisplacement
//purpose :
//=======================================================================
void gp_Trsf::SetDisplacement (const gp_Ax3& FromA1,
const gp_Ax3& ToA2)
{
shape = gp_CompoundTrsf;
scale = 1.0;
// matrix from ToA2 to XOY :
matrix.SetCol (1, ToA2.XDirection().XYZ());
matrix.SetCol (2, ToA2.YDirection().XYZ());
matrix.SetCol (3, ToA2.Direction().XYZ());
loc = ToA2.Location().XYZ();
// matrix XOY to FromA1 :
const gp_XYZ& xDir = FromA1.XDirection().XYZ();
const gp_XYZ& yDir = FromA1.YDirection().XYZ();
const gp_XYZ& zDir = FromA1.Direction().XYZ();
gp_Mat MA1 (xDir, yDir, zDir);
MA1.Transpose();
gp_XYZ MA1loc = FromA1.Location().XYZ();
MA1loc.Multiply (MA1);
MA1loc.Reverse();
// matrix * MA1
MA1loc.Multiply (matrix);
loc.Add (MA1loc);
matrix.Multiply (MA1);
}
//=======================================================================
//function : SetTranslationPart
//purpose :
//=======================================================================
void gp_Trsf::SetTranslationPart (const gp_Vec& V) {
loc = V.XYZ();
Standard_Real X = loc.X();
if (X < 0) X = - X;
Standard_Real Y = loc.Y();
if (Y < 0) Y = - Y;
Standard_Real Z = loc.Z();
if (Z < 0) Z = - Z;
Standard_Boolean locnull =
(X <= gp::Resolution() &&
Y <= gp::Resolution() &&
Z <= gp::Resolution());
switch (shape) {
case gp_Identity :
if (!locnull) shape = gp_Translation;
break;
case gp_Translation :
if (locnull) shape = gp_Identity;
break;
case gp_Rotation :
case gp_PntMirror :
case gp_Ax1Mirror :
case gp_Ax2Mirror :
case gp_Scale :
case gp_CompoundTrsf :
case gp_Other :
break;
}
}
//=======================================================================
//function : SetScaleFactor
//purpose :
//=======================================================================
void gp_Trsf::SetScaleFactor (const Standard_Real S)
{
Standard_Real As = S;
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As <= gp::Resolution(),"gp_Trsf::SetScaleFactor");
scale = S;
As = scale - 1.;
if (As < 0) As = - As;
Standard_Boolean unit = As <= gp::Resolution();
As = scale + 1.;
if (As < 0) As = - As;
Standard_Boolean munit = As <= gp::Resolution();
switch (shape) {
case gp_Identity :
case gp_Translation :
if (!unit) shape = gp_Scale;
if (munit) shape = gp_PntMirror;
break;
case gp_Rotation :
if (!unit) shape = gp_CompoundTrsf;
break;
case gp_PntMirror :
case gp_Ax1Mirror :
case gp_Ax2Mirror :
if (!munit) shape = gp_Scale;
if (unit) shape = gp_Identity;
break;
case gp_Scale :
if (unit) shape = gp_Identity;
if (munit) shape = gp_PntMirror;
break;
case gp_CompoundTrsf :
break;
case gp_Other :
break;
}
}
//=======================================================================
//function : SetValues
//purpose :
// 06-01-1998 modified by PMN : On utilise TolDist pour evaluer si les coeffs
// sont nuls : c'est toujours mieux que gp::Resolution !
//=======================================================================
void gp_Trsf::SetValues(const Standard_Real a11,
const Standard_Real a12,
const Standard_Real a13,
const Standard_Real a14,
const Standard_Real a21,
const Standard_Real a22,
const Standard_Real a23,
const Standard_Real a24,
const Standard_Real a31,
const Standard_Real a32,
const Standard_Real a33,
const Standard_Real a34,
// const Standard_Real Tolang,
const Standard_Real ,
const Standard_Real
#ifndef No_Exception
TolDist
#endif
)
{
gp_XYZ col1(a11,a21,a31);
gp_XYZ col2(a12,a22,a32);
gp_XYZ col3(a13,a23,a33);
gp_XYZ col4(a14,a24,a34);
// compute the determinant
gp_Mat M(col1,col2,col3);
Standard_Real s = M.Determinant();
Standard_Real As = s;
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As < gp::Resolution(),"gp_Trsf::SeValues, null determinant");
if (s > 0)
s = Pow(s,1./3.);
else
s = -Pow(-s,1./3.);
M.Divide(s);
// check if the matrix is a rotation matrix
// the transposition should be the invert.
gp_Mat TM(M);
TM.Transpose();
TM.Multiply(M);
//
// don t trust the initial values !
//
gp_Mat anIdentity ;
anIdentity.SetIdentity() ;
TM.Subtract(anIdentity);
As = TM.Value(1,1);
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As > TolDist,"gp_Trsf::SeValues, non uniform");
As = TM.Value(1,2);
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As > TolDist,"gp_Trsf::SeValues, non uniform");
As = TM.Value(1,3);
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As > TolDist,"gp_Trsf::SeValues, non uniform");
As = TM.Value(2,1);
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As > TolDist,"gp_Trsf::SeValues, non uniform");
As = TM.Value(2,2);
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As > TolDist,"gp_Trsf::SeValues, non uniform");
As = TM.Value(2,3);
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As > TolDist,"gp_Trsf::SeValues, non uniform");
As = TM.Value(3,1);
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As > TolDist,"gp_Trsf::SeValues, non uniform");
As = TM.Value(3,2);
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As > TolDist,"gp_Trsf::SeValues, non uniform");
As = TM.Value(3,3);
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As > TolDist,"gp_Trsf::SeValues, non uniform");
scale = s;
shape = gp_CompoundTrsf;
matrix = M;
loc = col4;
}
//=======================================================================
//function : GetRotation
//purpose :
//=======================================================================
gp_Quaternion gp_Trsf::GetRotation () const
{
return gp_Quaternion (matrix);
}
//=======================================================================
//function : VectorialPart
//purpose :
//=======================================================================
gp_Mat gp_Trsf::VectorialPart () const
{
if (scale == 1.0) return matrix;
gp_Mat M = matrix;
if (shape == gp_Scale || shape == gp_PntMirror)
M.SetDiagonal(scale*M.Value(1,1),
scale*M.Value(2,2),
scale*M.Value(3,3));
else
M.Multiply (scale);
return M;
}
//=======================================================================
//function : Invert
//purpose :
//=======================================================================
void gp_Trsf::Invert()
{
// -1
// X' = scale * R * X + T => X = (R / scale) * ( X' - T)
//
// Pour les gp_Trsf puisque le scale est extrait de la gp_Matrice R
// on a toujours determinant (R) = 1 et R-1 = R transposee.
if (shape == gp_Identity) { }
else if (shape == gp_Translation || shape == gp_PntMirror) loc.Reverse();
else if (shape == gp_Scale) {
Standard_Real As = scale;
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As <= gp::Resolution(),"");
scale = 1.0 / scale;
loc.Multiply (-scale);
}
else {
Standard_Real As = scale;
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if
(As <= gp::Resolution(),"");
scale = 1.0 / scale;
matrix.Transpose ();
loc.Multiply (matrix);
loc.Multiply (-scale);
}
}
//=======================================================================
//function : Multiply
//purpose :
//=======================================================================
void gp_Trsf::Multiply(const gp_Trsf& T)
{
if (T.shape == gp_Identity) { }
else if (shape == gp_Identity) {
shape = T.shape;
scale = T.scale;
loc = T.loc;
matrix = T.matrix;
}
else if (shape == gp_Rotation && T.shape == gp_Rotation) {
if (loc.X() != 0.0 || loc.Y() != 0.0 || loc.Z() != 0.0) {
loc.Add (T.loc.Multiplied (matrix));
}
matrix.Multiply(T.matrix);
}
else if (shape == gp_Translation && T.shape == gp_Translation) {
loc.Add (T.loc);
}
else if (shape == gp_Scale && T.shape == gp_Scale) {
loc.Add (T.loc.Multiplied(scale));
scale = scale * T.scale;
}
else if (shape == gp_PntMirror && T.shape == gp_PntMirror) {
scale = 1.0;
shape = gp_Translation;
loc.Add (T.loc.Reversed());
}
else if (shape == gp_Ax1Mirror && T.shape == gp_Ax1Mirror) {
shape = gp_Rotation;
loc.Add (T.loc.Multiplied (matrix));
matrix.Multiply(T.matrix);
}
else if ((shape == gp_CompoundTrsf || shape == gp_Rotation ||
shape == gp_Ax1Mirror || shape == gp_Ax2Mirror)
&& T.shape == gp_Translation) {
gp_XYZ Tloc(T.loc);
Tloc.Multiply(matrix);
if (scale != 1.0) { Tloc.Multiply(scale); }
loc.Add (Tloc);
}
else if ((shape == gp_Scale || shape == gp_PntMirror)
&& T.shape == gp_Translation) {
gp_XYZ Tloc(T.loc);
Tloc.Multiply (scale);
loc.Add (Tloc);
}
else if (shape == gp_Translation &&
(T.shape == gp_CompoundTrsf || T.shape == gp_Rotation ||
T.shape == gp_Ax1Mirror || T.shape == gp_Ax2Mirror)) {
shape = gp_CompoundTrsf;
scale = T.scale;
loc.Add (T.loc);
matrix = T.matrix;
}
else if (shape == gp_Translation &&
(T.shape == gp_Scale || T.shape == gp_PntMirror)) {
shape = T.shape;
loc.Add (T.loc);
scale = T.scale;
}
else if ((shape == gp_PntMirror || shape == gp_Scale) &&
(T.shape == gp_PntMirror || T.shape == gp_Scale)) {
shape = gp_CompoundTrsf;
gp_XYZ Tloc(T.loc);
Tloc.Multiply (scale);
loc.Add (Tloc);
scale = scale * T.scale;
}
else if ((shape == gp_CompoundTrsf || shape == gp_Rotation ||
shape == gp_Ax1Mirror || shape == gp_Ax2Mirror)
&& (T.shape == gp_Scale || T.shape == gp_PntMirror)) {
shape = gp_CompoundTrsf;
gp_XYZ Tloc(T.loc);
if (scale == 1.0) {
scale = T.scale;
Tloc.Multiply(matrix);
}
else {
Tloc.Multiply (matrix);
Tloc.Multiply (scale);
scale = scale * T.scale;
}
loc.Add (Tloc);
}
else if ((T.shape == gp_CompoundTrsf || T.shape == gp_Rotation ||
T.shape == gp_Ax1Mirror || T.shape == gp_Ax2Mirror)
&& (shape == gp_Scale || shape == gp_PntMirror)) {
shape = gp_CompoundTrsf;
gp_XYZ Tloc(T.loc);
Tloc.Multiply(scale);
loc.Add (Tloc);
scale = scale * T.scale;
matrix = T.matrix;
}
else {
shape = gp_CompoundTrsf;
gp_XYZ Tloc(T.loc);
Tloc.Multiply (matrix);
if (scale != 1.0) {
Tloc.Multiply (scale);
scale = scale * T.scale;
}
else { scale = T.scale; }
loc.Add (Tloc);
matrix.Multiply(T.matrix);
}
}
//=======================================================================
//function : Power
//purpose :
//=======================================================================
void gp_Trsf::Power (const Standard_Integer N)
{
if (shape == gp_Identity) { }
else {
if (N == 0) {
scale = 1.0;
shape = gp_Identity;
matrix.SetIdentity();
loc = gp_XYZ (0.0, 0.0, 0.0);
}
else if (N == 1) { }
else if (N == -1) { Invert(); }
else {
if (N < 0) { Invert(); }
if (shape == gp_Translation) {
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_XYZ Temploc = loc;
while (1) {
if (IsOdd(Npower)) loc.Add (Temploc);
if (Npower == 1) break;
Temploc.Add (Temploc);
Npower = Npower/2;
}
}
else if (shape == gp_Scale) {
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_XYZ Temploc = loc;
Standard_Real Tempscale = scale;
while (1) {
if (IsOdd(Npower)) {
loc.Add (Temploc.Multiplied(scale));
scale = scale * Tempscale;
}
if (Npower == 1) break;
Temploc.Add (Temploc.Multiplied(Tempscale));
Tempscale = Tempscale * Tempscale;
Npower = Npower/2;
}
}
else if (shape == gp_Rotation) {
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_Mat Tempmatrix (matrix);
if (loc.X() == 0.0 && loc.Y() == 0.0 && loc.Z() == 0.0) {
while (1) {
if (IsOdd(Npower)) matrix.Multiply (Tempmatrix);
if (Npower == 1) break;
Tempmatrix.Multiply (Tempmatrix);
Npower = Npower/2;
}
}
else {
gp_XYZ Temploc = loc;
while (1) {
if (IsOdd(Npower)) {
loc.Add (Temploc.Multiplied (matrix));
matrix.Multiply (Tempmatrix);
}
if (Npower == 1) break;
Temploc.Add (Temploc.Multiplied (Tempmatrix));
Tempmatrix.Multiply (Tempmatrix);
Npower = Npower/2;
}
}
}
else if (shape == gp_PntMirror || shape == gp_Ax1Mirror ||
shape == gp_Ax2Mirror) {
if (IsEven (N)) {
shape = gp_Identity;
scale = 1.0;
matrix.SetIdentity ();
loc.SetX(0);
loc.SetY(0);
loc.SetZ(0);
}
}
else {
shape = gp_CompoundTrsf;
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_XYZ Temploc = loc;
Standard_Real Tempscale = scale;
gp_Mat Tempmatrix (matrix);
while (1) {
if (IsOdd(Npower)) {
loc.Add ((Temploc.Multiplied (matrix)).Multiplied (scale));
scale = scale * Tempscale;
matrix.Multiply (Tempmatrix);
}
if (Npower == 1) break;
Tempscale = Tempscale * Tempscale;
Temploc.Add ( (Temploc.Multiplied (Tempmatrix)).Multiplied
(Tempscale)
);
Tempmatrix.Multiply (Tempmatrix);
Npower = Npower/2;
}
}
}
}
}
//=======================================================================
//function : PreMultiply
//purpose :
//=======================================================================
void gp_Trsf::PreMultiply (const gp_Trsf& T)
{
if (T.shape == gp_Identity) { }
else if (shape == gp_Identity) {
shape = T.shape;
scale = T.scale;
loc = T.loc;
matrix = T.matrix;
}
else if (shape == gp_Rotation && T.shape == gp_Rotation) {
loc.Multiply (T.matrix);
loc.Add (T.loc);
matrix.PreMultiply(T.matrix);
}
else if (shape == gp_Translation && T.shape == gp_Translation) {
loc.Add (T.loc);
}
else if (shape == gp_Scale && T.shape == gp_Scale) {
loc.Multiply (T.scale);
loc.Add (T.loc);
scale = scale * T.scale;
}
else if (shape == gp_PntMirror && T.shape == gp_PntMirror) {
scale = 1.0;
shape = gp_Translation;
loc.Reverse();
loc.Add (T.loc);
}
else if (shape == gp_Ax1Mirror && T.shape == gp_Ax1Mirror) {
shape = gp_Rotation;
loc.Multiply (T.matrix);
loc.Add (T.loc);
matrix.PreMultiply(T.matrix);
}
else if ((shape == gp_CompoundTrsf || shape == gp_Rotation ||
shape == gp_Ax1Mirror || shape == gp_Ax2Mirror)
&& T.shape == gp_Translation) {
loc.Add (T.loc);
}
else if ((shape == gp_Scale || shape == gp_PntMirror)
&& T.shape == gp_Translation) {
loc.Add (T.loc);
}
else if (shape == gp_Translation &&
(T.shape == gp_CompoundTrsf || T.shape == gp_Rotation
|| T.shape == gp_Ax1Mirror || T.shape == gp_Ax2Mirror)) {
shape = gp_CompoundTrsf;
matrix = T.matrix;
if (T.scale == 1.0) loc.Multiply (T.matrix);
else {
scale = T.scale;
loc.Multiply (matrix);
loc.Multiply (scale);
}
loc.Add (T.loc);
}
else if ((T.shape == gp_Scale || T.shape == gp_PntMirror)
&& shape == gp_Translation) {
loc.Multiply (T.scale);
loc.Add (T.loc);
scale = T.scale;
shape = T.shape;
}
else if ((shape == gp_PntMirror || shape == gp_Scale) &&
(T.shape == gp_PntMirror || T.shape == gp_Scale)) {
shape = gp_CompoundTrsf;
loc.Multiply (T.scale);
loc.Add (T.loc);
scale = scale * T.scale;
}
else if ((shape == gp_CompoundTrsf || shape == gp_Rotation ||
shape == gp_Ax1Mirror || shape == gp_Ax2Mirror)
&& (T.shape == gp_Scale || T.shape == gp_PntMirror)) {
shape = gp_CompoundTrsf;
loc.Multiply (T.scale);
loc.Add (T.loc);
scale = scale * T.scale;
}
else if ((T.shape == gp_CompoundTrsf || T.shape == gp_Rotation ||
T.shape == gp_Ax1Mirror || T.shape == gp_Ax2Mirror)
&& (shape == gp_Scale || shape == gp_PntMirror)) {
shape = gp_CompoundTrsf;
matrix = T.matrix;
if (T.scale == 1.0) loc.Multiply (T.matrix);
else {
loc.Multiply (matrix);
loc.Multiply (T.scale);
scale = T.scale * scale;
}
loc.Add (T.loc);
}
else {
shape = gp_CompoundTrsf;
loc.Multiply (T.matrix);
if (T.scale != 1.0) {
loc.Multiply (T.scale); scale = scale * T.scale;
}
loc.Add (T.loc);
matrix.PreMultiply(T.matrix);
}
}
//=======================================================================
//function : GetRotation
//purpose : algorithm from A.Korn, M.Korn, "Mathematical Handbook for
// scientists and Engineers" McGraw-Hill, 1961, ch.14.10-2.
//=======================================================================
Standard_Boolean gp_Trsf::GetRotation (gp_XYZ& theAxis,
Standard_Real& theAngle) const
{
gp_Quaternion Q = GetRotation();
gp_Vec aVec;
Q.GetVectorAndAngle (aVec, theAngle);
theAxis = aVec.XYZ();
return Standard_True;
}

121
src/gp/gp_Trsf.lxx Executable file
View File

@@ -0,0 +1,121 @@
// File gp_Trsf.lxx, JCV 03/06/90
// Modif JCV 04/10/90 ajout des methodes Form Scale IsNegative
// Modif JCV 10/12/90 ajout de la methode Translationpart
#include <Standard_OutOfRange.hxx>
#include <gp_Trsf2d.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>
inline gp_Trsf::gp_Trsf () :
scale(1.0),
shape(gp_Identity),
matrix(1,0,0, 0,1,0, 0,0,1),
loc(0.0, 0.0, 0.0)
{}
inline gp_Trsf::gp_Trsf (const gp_Trsf2d& T) :
scale(T.ScaleFactor()),
shape(T.Form()),
loc(T.TranslationPart().X(),T.TranslationPart().Y(), 0.0)
{
const gp_Mat2d& M = T.HVectorialPart();
matrix(1,1) = M(1,1);
matrix(1,2) = M(1,2);
matrix(2,1) = M(2,1);
matrix(2,2) = M(2,2);
matrix(3,3) = 1.;
}
inline void gp_Trsf::SetMirror (const gp_Pnt& P)
{
shape = gp_PntMirror;
scale = -1.0;
loc = P.XYZ();
matrix.SetIdentity ();
loc.Multiply(2.0);
}
inline void gp_Trsf::SetTranslation (const gp_Vec& V)
{
shape = gp_Translation;
scale = 1.;
matrix.SetIdentity ();
loc = V.XYZ();
}
inline void gp_Trsf::SetTranslation(const gp_Pnt& P1,
const gp_Pnt& P2)
{
shape = gp_Translation;
scale = 1.0;
matrix.SetIdentity ();
loc = (P2.XYZ()).Subtracted (P1.XYZ());
}
inline Standard_Boolean gp_Trsf::IsNegative() const
{ return (scale < 0.0); }
inline const gp_XYZ& gp_Trsf::TranslationPart () const
{ return loc; }
inline const gp_Mat& gp_Trsf::HVectorialPart () const
{ return matrix; }
inline Standard_Real gp_Trsf::Value (const Standard_Integer Row,
const Standard_Integer Col) const
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 3 || Col < 1 || Col > 4, " ");
if (Col < 4) return scale * matrix.Value (Row, Col);
else return loc.Coord (Row);
}
inline gp_TrsfForm gp_Trsf::Form () const
{ return shape; }
inline Standard_Real gp_Trsf::ScaleFactor () const
{ return scale; }
inline gp_Trsf gp_Trsf::Inverted() const
{
gp_Trsf T = *this;
T.Invert();
return T;
}
inline gp_Trsf gp_Trsf::Multiplied (const gp_Trsf& T) const
{
gp_Trsf Tresult(*this);
Tresult.Multiply(T);
return Tresult;
}
inline gp_Trsf gp_Trsf::Powered (const Standard_Integer N)
{
gp_Trsf T = *this;
T.Power (N);
return T;
}
inline void gp_Trsf::Transforms (Standard_Real& X,
Standard_Real& Y,
Standard_Real& Z) const
{
gp_XYZ Triplet (X, Y, Z);
Triplet.Multiply (matrix);
if (scale != 1.0) Triplet.Multiply (scale);
Triplet.Add(loc);
X = Triplet.X();
Y = Triplet.Y();
Z = Triplet.Z();
}
inline void gp_Trsf::Transforms (gp_XYZ& Coord) const
{
Coord.Multiply (matrix);
if (scale != 1.0) Coord.Multiply (scale);
Coord.Add(loc);
}

248
src/gp/gp_Trsf2d.cdl Executable file
View File

@@ -0,0 +1,248 @@
---Copyright: Matra Datavision 1991
class Trsf2d from gp inherits Storable
--- Purpose :
-- Defines a non-persistent transformation in 2D space.
-- The following transformations are implemented :
-- . Translation, Rotation, Scale
-- . Symmetry with respect to a point and a line.
-- Complex transformations can be obtained by combining the
-- previous elementary transformations using the method Multiply.
-- The transformations can be represented as follow :
--
-- V1 V2 T XY XY
-- | a11 a12 a13 | | x | | x'|
-- | a21 a22 a23 | | y | | y'|
-- | 0 0 1 | | 1 | | 1 |
--
-- where {V1, V2} defines the vectorial part of the transformation
-- and T defines the translation part of the transformation.
uses Ax2d from gp,
Mat2d from gp,
Pnt2d from gp,
TrsfForm from gp,
Trsf from gp,
Vec2d from gp,
XY from gp
raises ConstructionError from Standard,
OutOfRange from Standard
is
Create returns Trsf2d from gp;
---C++: inline
--- Purpose : Returns identity transformation.
Create(T : Trsf from gp)
returns Trsf2d from gp
raises ConstructionError;
---C++: inline
---Purpose: Creates a 2d transformation in the XY plane from a
-- 3d transformation .
SetMirror (me : in out; P : Pnt2d) is static;
---C++: inline
--- Purpose :
-- Changes the transformation into a symmetrical transformation.
-- P is the center of the symmetry.
SetMirror (me : in out; A : Ax2d) is static;
--- Purpose :
-- Changes the transformation into a symmetrical transformation.
-- A is the center of the axial symmetry.
SetRotation (me : in out; P : Pnt2d; Ang : Real) is static;
---C++: inline
--- Purpose :
-- Changes the transformation into a rotation.
-- P is the rotation's center and Ang is the angular value of the
-- rotation in radian.
SetScale (me : in out; P : Pnt2d; S : Real) is static;
---C++: inline
--- Purpose :
-- Changes the transformation into a scale.
-- P is the center of the scale and S is the scaling value.
SetTransformation (me : in out; FromSystem1, ToSystem2 : Ax2d) is static;
--- Purpose :
-- Changes a transformation allowing passage from the coordinate
-- system "FromSystem1" to the coordinate system "ToSystem2".
SetTransformation (me : in out; ToSystem : Ax2d) is static;
--- Purpose :
-- Changes the transformation allowing passage from the basic
-- coordinate system
-- {P(0.,0.,0.), VX (1.,0.,0.), VY (0.,1.,0.)}
-- to the local coordinate system defined with the Ax2d ToSystem.
SetTranslation (me : in out; V : Vec2d) is static;
---C++: inline
--- Purpose :
-- Changes the transformation into a translation.
-- V is the vector of the translation.
SetTranslation (me: in out; P1, P2 : Pnt2d) is static;
---C++: inline
--- Purpose :
-- Makes the transformation into a translation from
-- the point P1 to the point P2.
SetTranslationPart (me : in out; V : Vec2d) is static;
--- Purpose : Replaces the translation vector with V.
SetScaleFactor (me : in out; S : Real) is static;
--- Purpose : Modifies the scale factor.
IsNegative (me) returns Boolean is static;
--- Purpose : Returns true if the determinant of the vectorial part of
-- this transformation is negative..
---C++: inline
Form (me) returns TrsfForm is static;
--- Purpose :
-- Returns the nature of the transformation. It can be an
-- identity transformation, a rotation, a translation, a mirror
-- (relative to a point or an axis), a scaling transformation,
-- or a compound transformation.
---C++: inline
ScaleFactor (me) returns Real is static;
--- Purpose : Returns the scale factor.
---C++: inline
TranslationPart (me) returns XY is static;
--- Purpose :
-- Returns the translation part of the transformation's matrix
---C++: inline
---C++: return const&
VectorialPart (me) returns Mat2d is static;
--- Purpose :
-- Returns the vectorial part of the transformation. It is a
-- 2*2 matrix which includes the scale factor.
HVectorialPart (me) returns Mat2d is static;
--- Purpose :
-- Returns the homogeneous vectorial part of the transformation.
-- It is a 2*2 matrix which doesn't include the scale factor.
-- The coefficients of this matrix must be multiplied by the
-- scale factor to obtain the coefficients of the transformation.
---C++: inline
---C++: return const&
RotationPart (me) returns Real is static;
--- Purpose :
-- Returns the angle corresponding to the rotational component
-- of the transformation matrix (operation opposite to SetRotation()).
Value (me; Row, Col : Integer) returns Real
---C++: inline
--- Purpose :
-- Returns the coefficients of the transformation's matrix.
-- It is a 2 rows * 3 columns matrix.
-- Raises OutOfRange if Row < 1 or Row > 2 or Col < 1 or Col > 3
raises OutOfRange
is static;
Invert (me : in out) raises ConstructionError is static;
Inverted (me) returns Trsf2d raises ConstructionError is static;
--- Purpose :
-- Computes the reverse transformation.
-- Raises an exception if the matrix of the transformation
-- is not inversible, it means that the scale factor is lower
-- or equal to Resolution from package gp.
---C++: inline
Multiplied (me; T : Trsf2d) returns Trsf2d is static;
---C++: inline
---C++: alias operator *
Multiply (me : in out; T : Trsf2d) is static;
---C++: alias operator *=
--- Purpose :
-- Computes the transformation composed from <T> and <me>.
-- In a C++ implementation you can also write Tcomposed = <me> * T.
-- Example :
-- Trsf2d T1, T2, Tcomp; ...............
-- //composition :
-- Tcomp = T2.Multiplied(T1); // or (Tcomp = T2 * T1)
-- // transformation of a point
-- Pnt2d P1(10.,3.,4.);
-- Pnt2d P2 = P1.Transformed(Tcomp); //using Tcomp
-- Pnt2d P3 = P1.Transformed(T1); //using T1 then T2
-- P3.Transform(T2); // P3 = P2 !!!
PreMultiply (me : in out; T : Trsf2d) is static;
--- Purpose :
-- Computes the transformation composed from <me> and T.
-- <me> = T * <me>
Power (me : in out; N : Integer) raises ConstructionError is static;
Powered (me : in out; N : Integer) returns Trsf2d
raises ConstructionError
is static;
--- Purpose :
-- Computes the following composition of transformations
-- <me> * <me> * .......* <me>, N time.
-- if N = 0 <me> = Identity
-- if N < 0 <me> = <me>.Inverse() *...........* <me>.Inverse().
--
-- Raises if N < 0 and if the matrix of the transformation not
-- inversible.
---C++: inline
Transforms (me; X, Y : out Real) is static;
---C++: inline
Transforms (me; Coord : out XY) is static;
---C++: inline
--- Purpose : Transforms a doublet XY with a Trsf2d
fields
scale : Real;
shape : TrsfForm;
matrix : Mat2d;
loc : XY;
friends
class GTrsf2d
end;

481
src/gp/gp_Trsf2d.cxx Executable file
View File

@@ -0,0 +1,481 @@
// File gp_Ax2d.cxx, JCV 06/90
// File gp_Trsf.cxx, REG 03/06/90 nouvelle version
// JCV 08/01/91 Modif introduction des classes Mat2d et XY dans gp
#define No_Standard_OutOfRange
#include <gp_Trsf2d.ixx>
#include <gp.hxx>
#include <Standard_ConstructionError.hxx>
void gp_Trsf2d::SetMirror (const gp_Ax2d& A)
{
shape = gp_Ax1Mirror;
scale = - 1.0;
const gp_Dir2d& V = A.Direction ();
const gp_Pnt2d& P = A.Location ();
Standard_Real VX = V.X();
Standard_Real VY = V.Y();
Standard_Real X0 = P.X();
Standard_Real Y0 = P.Y();
matrix.SetCol (1, gp_XY (1.0 - 2.0 * VX * VX, -2.0 * VX * VY));
matrix.SetCol (2, gp_XY (-2.0 * VX * VY, 1.0 - 2.0 * VY * VY));
loc.SetCoord (-2.0 * ((VX * VX - 1.0) * X0 + (VX * VY * Y0)),
-2.0 * ((VX * VY * X0) + (VY * VY - 1.0) * Y0));
}
void gp_Trsf2d::SetTransformation (const gp_Ax2d& FromA1,
const gp_Ax2d& ToA2)
{
shape = gp_CompoundTrsf;
scale = 1.0;
//matrix from XOY to A2 :
const gp_XY& V1 = ToA2.Direction().XY();
gp_XY V2 (-V1.Y(), V1.X());
matrix.SetCol (1, V1);
matrix.SetCol (2, V2);
loc = ToA2.Location().XY();
matrix.Transpose();
loc.Multiply (matrix);
loc.Reverse();
//matrix FromA1 to XOY
const gp_XY& V3 = FromA1.Direction().XY();
gp_XY V4 (-V3.Y(), V3.X());
gp_Mat2d MA1 (V3, V4);
gp_XY MA1loc = FromA1.Location().XY();
//matrix * MA1 => FromA1 ToA2
MA1loc.Multiply (matrix);
loc.Add (MA1loc);
matrix.Multiply (MA1);
}
void gp_Trsf2d::SetTransformation (const gp_Ax2d& A)
{
shape = gp_CompoundTrsf;
scale = 1.0;
const gp_XY& V1 = A.Direction().XY();
gp_XY V2 (-V1.Y(), V1.X());
matrix.SetCol (1, V1);
matrix.SetCol (2, V2);
loc = A.Location().XY();
matrix.Transpose();
loc.Multiply (matrix);
loc.Reverse();
}
void gp_Trsf2d::SetTranslationPart (const gp_Vec2d& V)
{
loc = V.XY();
Standard_Real X = loc.X();
if (X < 0) X = - X;
Standard_Real Y = loc.Y();
if (Y < 0) Y = - Y;
if (X <= gp::Resolution() && Y <= gp::Resolution()) {
if (shape == gp_Identity || shape == gp_PntMirror ||
shape == gp_Scale || shape == gp_Rotation ||
shape == gp_Ax1Mirror ) { }
else if (shape == gp_Translation) { shape = gp_Identity; }
else { shape = gp_CompoundTrsf; }
}
else {
if (shape == gp_Translation || shape == gp_Scale ||
shape == gp_PntMirror) { }
else if (shape == gp_Identity) { shape = gp_Translation; }
else { shape = gp_CompoundTrsf; }
}
}
void gp_Trsf2d::SetScaleFactor (const Standard_Real S)
{
if (S == 1.0) {
Standard_Real X = loc.X();
if (X < 0) X = - X;
Standard_Real Y = loc.Y();
if (Y < 0) Y = - Y;
if (X <= gp::Resolution() && Y <= gp::Resolution()) {
if (shape == gp_Identity || shape == gp_Rotation) { }
else if (shape == gp_Scale) { shape = gp_Identity; }
else if (shape == gp_PntMirror) { shape = gp_Translation; }
else { shape = gp_CompoundTrsf; }
}
else {
if (shape == gp_Identity || shape == gp_Rotation ||
shape == gp_Scale) { }
else if (shape == gp_PntMirror) { shape = gp_Translation; }
else { shape = gp_CompoundTrsf; }
}
}
else if (S == -1) {
if (shape == gp_PntMirror || shape == gp_Ax1Mirror) { }
else if (shape == gp_Identity || shape == gp_Scale) {
shape = gp_PntMirror;
}
else { shape = gp_CompoundTrsf; }
}
else {
if (shape == gp_Scale) { }
else if (shape == gp_Identity || shape == gp_Translation ||
shape == gp_PntMirror) { shape = gp_Scale; }
else { shape = gp_CompoundTrsf; }
}
scale = S;
}
gp_Mat2d gp_Trsf2d::VectorialPart () const
{
if (scale == 1.0) return matrix;
gp_Mat2d M = matrix;
if (shape == gp_Scale || shape == gp_PntMirror)
M.SetDiagonal (matrix.Value(1,1) * scale, matrix.Value(2,2) * scale);
else
M.Multiply (scale);
return M;
}
Standard_Real gp_Trsf2d::RotationPart () const
{
return ATan2 ( matrix.Value(2,1), matrix.Value(1,1) );
}
void gp_Trsf2d::Invert()
{
// -1
// X' = scale * R * X + T => X = (R / scale) * ( X' - T)
//
// Pour les gp_Trsf2d puisque le scale est extrait de la matrice R
// on a toujours determinant (R) = 1 et R-1 = R transposee.
if (shape == gp_Identity) { }
else if ( shape == gp_Translation || shape == gp_PntMirror) {
loc.Reverse();
}
else if ( shape == gp_Scale) {
Standard_Real As = scale;
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if(As <= gp::Resolution(),"");
scale = 1.0 / scale;
loc.Multiply (-scale);
}
else {
Standard_Real As = scale;
if (As < 0) As = - As;
Standard_ConstructionError_Raise_if(As <= gp::Resolution(),"");
scale = 1.0 / scale;
matrix.Transpose();
loc.Multiply (matrix);
loc.Multiply (-scale);
}
}
void gp_Trsf2d::Multiply(const gp_Trsf2d& T)
{
if (T.shape == gp_Identity) { }
else if (shape == gp_Identity) {
shape = T.shape;
scale = T.scale;
loc = T.loc;
matrix = T.matrix;
}
else if (shape == gp_Rotation && T.shape == gp_Rotation) {
if (loc.X() != 0.0 || loc.Y() != 0.0) {
loc.Add (T.loc.Multiplied (matrix));
}
matrix.Multiply(T.matrix);
}
else if (shape == gp_Translation && T.shape == gp_Translation) {
loc.Add (T.loc);
}
else if (shape == gp_Scale && T.shape == gp_Scale) {
loc.Add (T.loc.Multiplied(scale));
scale = scale * T.scale;
}
else if (shape == gp_PntMirror && T.shape == gp_PntMirror) {
scale = 1.0;
shape = gp_Translation;
loc.Add (T.loc.Reversed());
}
else if (shape == gp_Ax1Mirror && T.shape == gp_Ax1Mirror) {
shape = gp_Rotation;
loc.Add (T.loc.Multiplied (matrix));
matrix.Multiply(T.matrix);
}
else if ((shape == gp_CompoundTrsf || shape == gp_Rotation ||
shape == gp_Ax1Mirror) && T.shape == gp_Translation) {
gp_XY Tloc (T.loc);
Tloc.Multiply (matrix);
if (scale != 1.0) Tloc.Multiply (scale);
loc.Add (Tloc);
}
else if ((shape == gp_Scale || shape == gp_PntMirror)
&& T.shape == gp_Translation) {
gp_XY Tloc (T.loc);
Tloc.Multiply (scale);
loc.Add (Tloc);
}
else if (shape == gp_Translation &&
(T.shape == gp_CompoundTrsf ||
T.shape == gp_Rotation || T.shape == gp_Ax1Mirror)) {
shape = gp_CompoundTrsf;
scale = T.scale;
loc.Add (T.loc);
matrix = T.matrix;
}
else if (shape == gp_Translation &&
(T.shape == gp_Scale || T.shape == gp_PntMirror)) {
shape = T.shape;
loc.Add (T.loc);
scale = T.scale;
}
else if ((shape == gp_PntMirror || shape == gp_Scale) &&
(T.shape == gp_PntMirror || T.shape == gp_Scale)) {
shape = gp_CompoundTrsf;
gp_XY Tloc (T.loc);
Tloc.Multiply (scale);
loc.Add (Tloc);
scale = scale * T.scale;
}
else if ((shape == gp_CompoundTrsf || shape == gp_Rotation ||
shape == gp_Ax1Mirror)
&& (T.shape == gp_Scale || T.shape == gp_PntMirror)) {
shape = gp_CompoundTrsf;
gp_XY Tloc (T.loc);
Tloc.Multiply(matrix);
if (scale == 1.0) scale = T.scale;
else {
Tloc.Multiply (scale);
scale = scale * T.scale;
}
loc.Add (Tloc);
}
else if ((T.shape == gp_CompoundTrsf || T.shape == gp_Rotation ||
T.shape == gp_Ax1Mirror)
&& (shape == gp_Scale || shape == gp_PntMirror)) {
shape = gp_CompoundTrsf;
gp_XY Tloc (T.loc);
Tloc.Multiply (scale);
scale = scale * T.scale;
loc.Add (Tloc);
matrix = T.matrix;
}
else {
shape = gp_CompoundTrsf;
gp_XY Tloc (T.loc);
Tloc.Multiply (matrix);
if (scale != 1.0) {
Tloc.Multiply (scale);
scale = scale * T.scale;
}
else { scale = T.scale; }
loc.Add (Tloc);
matrix.Multiply (T.matrix);
}
}
void gp_Trsf2d::Power (const Standard_Integer N)
{
if (shape == gp_Identity) { }
else {
if (N == 0) {
scale = 1.0;
shape = gp_Identity;
matrix.SetIdentity();
loc = gp_XY (0.0, 0.0);
}
else if (N == 1) { }
else if (N == -1) Invert();
else {
if (N < 0) Invert();
if (shape == gp_Translation) {
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_XY Temploc = loc;
while (1) {
if (IsOdd(Npower)) loc.Add (Temploc);
if (Npower == 1) break;
Temploc.Add (Temploc);
Npower = Npower/2;
}
}
else if (shape == gp_Scale) {
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_XY Temploc = loc;
Standard_Real Tempscale = scale;
while (1) {
if (IsOdd(Npower)) {
loc.Add (Temploc.Multiplied(scale));
scale = scale * Tempscale;
}
if (Npower == 1) break;
Temploc.Add (Temploc.Multiplied(Tempscale));
Tempscale = Tempscale * Tempscale;
Npower = Npower/2;
}
}
else if (shape == gp_Rotation) {
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
gp_Mat2d Tempmatrix (matrix);
if (loc.X() == 0.0 && loc.Y() == 0.0) {
while (1) {
if (IsOdd(Npower)) matrix.Multiply (Tempmatrix);
if (Npower == 1) break;
Tempmatrix.Multiply (Tempmatrix);
Npower = Npower/2;
}
}
else {
gp_XY Temploc = loc;
while (1) {
if (IsOdd(Npower)) {
loc.Add (Temploc.Multiplied (matrix));
matrix.Multiply (Tempmatrix);
}
if (Npower == 1) break;
Temploc.Add (Temploc.Multiplied (Tempmatrix));
Tempmatrix.Multiply (Tempmatrix);
Npower = Npower/2;
}
}
}
else if (shape == gp_PntMirror || shape == gp_Ax1Mirror) {
if (IsEven (N)) {
shape = gp_Identity;
scale = 1.0;
matrix.SetIdentity ();
loc.SetCoord (0.0, 0.0);
}
}
else {
shape = gp_CompoundTrsf;
Standard_Integer Npower = N;
if (Npower < 0) Npower = - Npower;
Npower--;
matrix.SetDiagonal (scale*matrix.Value(1,1),
scale*matrix.Value(2,2));
gp_XY Temploc = loc;
Standard_Real Tempscale = scale;
gp_Mat2d Tempmatrix (matrix);
while (1) {
if (IsOdd(Npower)) {
loc.Add ((Temploc.Multiplied (matrix)).Multiplied (scale));
scale = scale * Tempscale;
matrix.Multiply (Tempmatrix);
}
if (Npower == 1) break;
Tempscale = Tempscale * Tempscale;
Temploc.Add ( (Temploc.Multiplied (Tempmatrix)).Multiplied
(Tempscale)
);
Tempmatrix.Multiply (Tempmatrix);
Npower = Npower/2;
}
}
}
}
}
void gp_Trsf2d::PreMultiply (const gp_Trsf2d& T)
{
if (T.shape == gp_Identity) { }
else if (shape == gp_Identity) {
shape = T.shape;
scale = T.scale;
loc = T.loc;
matrix = T.matrix;
}
else if (shape == gp_Rotation && T.shape == gp_Rotation) {
loc.Multiply (T.matrix);
loc.Add (T.loc);
matrix.PreMultiply(T.matrix);
}
else if (shape == gp_Translation && T.shape == gp_Translation) {
loc.Add (T.loc);
}
else if (shape == gp_Scale && T.shape == gp_Scale) {
loc.Multiply (T.scale);
loc.Add (T.loc);
scale = scale * T.scale;
}
else if (shape == gp_PntMirror && T.shape == gp_PntMirror) {
scale = 1.0;
shape = gp_Translation;
loc.Reverse();
loc.Add (T.loc);
}
else if (shape == gp_Ax1Mirror && T.shape == gp_Ax1Mirror) {
shape = gp_Rotation;
loc.Multiply (T.matrix);
loc.Add (T.loc);
matrix.PreMultiply(T.matrix);
}
else if ((shape == gp_CompoundTrsf || shape == gp_Rotation ||
shape == gp_Ax1Mirror) && T.shape == gp_Translation) {
loc.Add (T.loc);
}
else if ((shape == gp_Scale || shape == gp_PntMirror)
&& T.shape == gp_Translation) {
loc.Add (T.loc);
}
else if (shape == gp_Translation &&
(T.shape == gp_CompoundTrsf ||
T.shape == gp_Rotation || T.shape == gp_Ax1Mirror)) {
shape = gp_CompoundTrsf;
matrix = T.matrix;
if (T.scale == 1.0) loc.Multiply (T.matrix);
else {
scale = T.scale;
loc.Multiply (matrix);
loc.Multiply (scale);
}
loc.Add (T.loc);
}
else if ((T.shape == gp_Scale || T.shape == gp_PntMirror)
&& shape == gp_Translation) {
loc.Multiply (T.scale);
loc.Add (T.loc);
scale = T.scale;
shape = T.shape;
}
else if ((shape == gp_PntMirror || shape == gp_Scale) &&
(T.shape == gp_PntMirror || T.shape == gp_Scale)) {
shape = gp_CompoundTrsf;
loc.Multiply (T.scale);
loc.Add (T.loc);
scale = scale * T.scale;
}
else if ((shape == gp_CompoundTrsf || shape == gp_Rotation ||
shape == gp_Ax1Mirror)
&& (T.shape == gp_Scale || T.shape == gp_PntMirror)) {
shape = gp_CompoundTrsf;
loc.Multiply (T.scale);
loc.Add (T.loc);
scale = scale * T.scale;
}
else if ((T.shape == gp_CompoundTrsf || T.shape == gp_Rotation ||
T.shape == gp_Ax1Mirror)
&& (shape == gp_Scale || shape == gp_PntMirror)) {
shape = gp_CompoundTrsf;
matrix = T.matrix;
if (T.scale == 1.0) loc.Multiply (T.matrix);
else {
loc.Multiply (matrix);
loc.Multiply (T.scale);
scale = T.scale * scale;
}
loc.Add (T.loc);
}
else {
shape = gp_CompoundTrsf;
loc.Multiply (T.matrix);
if (T.scale != 1.0) {
loc.Multiply(T.scale); scale = scale * T.scale;
}
loc.Add (T.loc);
matrix.PreMultiply(T.matrix);
}
}

133
src/gp/gp_Trsf2d.lxx Executable file
View File

@@ -0,0 +1,133 @@
// File gp_Trsf2d.lxx, JCV 08/01/91
#include <gp_Trsf.hxx>
#include <gp_Pnt2d.hxx>
inline gp_Trsf2d::gp_Trsf2d () {
shape = gp_Identity;
scale = 1.0;
matrix.SetIdentity ();
loc.SetCoord (0.0, 0.0);
}
inline gp_Trsf2d::gp_Trsf2d (const gp_Trsf& T) :
scale(T.ScaleFactor()),
shape(T.Form()),
loc(T.TranslationPart().X(),T.TranslationPart().Y())
{
const gp_Mat& M = T.HVectorialPart();
matrix(1,1) = M(1,1);
matrix(1,2) = M(1,2);
matrix(2,1) = M(2,1);
matrix(2,2) = M(2,2);
}
inline void gp_Trsf2d::SetMirror(const gp_Pnt2d& P)
{
shape = gp_PntMirror;
scale = -1.0;
matrix.SetIdentity ();
loc = P.XY();
loc.Multiply (2.0);
}
inline void gp_Trsf2d::SetRotation (const gp_Pnt2d& P,
const Standard_Real Ang)
{
shape = gp_Rotation;
scale = 1.0;
loc = P.XY ();
loc.Reverse ();
matrix.SetRotation (Ang);
loc.Multiply (matrix);
loc.Add (P.XY());
}
inline void gp_Trsf2d::SetScale (const gp_Pnt2d& P,
const Standard_Real S)
{
shape = gp_Scale;
scale = S;
matrix.SetIdentity ();
loc = P.XY ();
loc.Multiply (1.0 - S);
}
inline void gp_Trsf2d::SetTranslation(const gp_Vec2d& V)
{
shape = gp_Translation;
scale = 1.0;
matrix.SetIdentity ();
loc = V.XY ();
}
inline void gp_Trsf2d::SetTranslation (const gp_Pnt2d& P1,
const gp_Pnt2d& P2)
{
shape = gp_Translation;
scale = 1.0;
matrix.SetIdentity ();
loc = (P2.XY()).Subtracted (P1.XY());
}
inline Standard_Boolean gp_Trsf2d::IsNegative() const
{ return (matrix.Determinant() < 0.0); }
inline const gp_XY& gp_Trsf2d::TranslationPart () const
{ return loc; }
inline const gp_Mat2d& gp_Trsf2d::HVectorialPart () const
{ return matrix; }
inline Standard_Real gp_Trsf2d::Value (const Standard_Integer Row,
const Standard_Integer Col) const
{
Standard_OutOfRange_Raise_if
(Row < 1 || Row > 2 || Col < 1 || Col > 3, " ");
if (Col < 3) return scale * matrix.Value (Row, Col);
else return loc.Coord (Row);
}
inline gp_TrsfForm gp_Trsf2d::Form() const
{ return shape; }
inline Standard_Real gp_Trsf2d::ScaleFactor() const
{ return scale; }
inline gp_Trsf2d gp_Trsf2d::Inverted() const
{
gp_Trsf2d T = *this;
T.Invert();
return T;
}
inline gp_Trsf2d gp_Trsf2d::Multiplied (const gp_Trsf2d& T) const {
gp_Trsf2d Tresult(*this);
Tresult.Multiply(T);
return Tresult;
}
inline gp_Trsf2d gp_Trsf2d::Powered (const Standard_Integer N)
{
gp_Trsf2d T = *this;
T.Power (N);
return T;
}
inline void gp_Trsf2d::Transforms (Standard_Real& X,
Standard_Real& Y) const
{
gp_XY Doublet (X, Y);
Doublet.Multiply (matrix);
if (scale != 1.0) Doublet.Multiply (scale);
Doublet.Add(loc);
Doublet.Coord (X, Y);
}
inline void gp_Trsf2d::Transforms (gp_XY& Coord) const
{
Coord.Multiply (matrix);
if (scale != 1.0) Coord.Multiply (scale);
Coord.Add(loc);
}

Some files were not shown because too many files have changed in this diff Show More