AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
AMCAX Kernel 1.0.0.0
Loading...
Searching...
No Matches
Geometry Foundation

Coord

Construction

Using the default constructor will result in the origin of coordinates. You need to input floating-point numbers when constructing. Also, all geometries only support input of floating-point numbers, which will not be specifically mentioned in the future.

Coord3(Three-Dimensional Coordinate)

AMCAX::Coord3 crd1(0.0, 0.0, 2.0);
Coord3d Coord3
3D coordinate
Definition CoordT.hpp:2809

Coord2(Two-Dimensional Coordinate)

AMCAX::Coord2 crd2d(0.0,1.0);
Coord2d Coord2
2D coordinate
Definition CoordT.hpp:2806

Get and Modify

Get

You can use the following two methods to get the value of a particular dimension of the coordinate.

AMCAX::Coord3 crd(0.0, 1.0, 2.0);
double x = crd.X();
double y = crd.Y();
double z = crd.Z();
double x2 = crd[0];
double y2 = crd[1];
double z2 = crd[2];

Modify

You can modify the value of a particular dimension of the coordinate using the following two methods.

AMCAX::Coord3 crd(0.0, 1.0, 2.0);
crd.SetXYZ(1.0, 0.0, 2.1);
crd.SetX(0.5);
crd.SetY(0.5);
crd.SetZ(0.5);

Common Function

Operation

Support addition, subtraction, scalar multiplication, dot product, cross product, and also support == and !=.

Addition and Subtraction

AMCAX::Coord3 crd1(2.0, 1.0, 2.0);
AMCAX::Coord3 crd2(0.2, 1.0, 1.0);
//+
AMCAX::Coord3 crd3 = crd1 + crd2;
//-
AMCAX::Coord3 crd4 = crd1 - crd2;

Scalar Multiplication

AMCAX::Coord3 crd5 = crd1 * 0.5;

Dot Product

double t = crd1.Dot(crd2);

Cross Product

AMCAX::Coord3 crd6 = crd1.Cross(crd2);

== and !=

== and != can be used to compare coordinates and their respective dimensions.

double result1 = crd1 == crd2;
std::cout << result1 << std::endl;
double result2 = crd1 != crd2;
std::cout << result2 << std::endl;
double result3 = crd1.Y() == crd2.Y();
std::cout << result3 << std::endl;

Norm

The kernel support calculating the norm (magnitude) of the coordinate and normalizing the coordinate.

Magnitude

double length = crd1.Norm();

Normalization

There are two ways to normalize a coordinate: one does not change the coordinate itself and creates a new coordinate, while the other directly modifies the coordinate.

AMCAX::Coord3 crd2 = crd.Normalized();
//change
crd.Normalize();

Output and Input

The kernel support outputting coordinates using << and inputting with >>.

Output

std::cout << crd1 << std::endl;

Input

std::istringstream is("0.0 1.0 2.0");
is >> crd7;

Point

Construction

Using the default constructor will result in the origin. It can either be directly created or constructed based on Coord3/Coord2.

Coord3(Three-Dimensional Point)

AMCAX::Point3 p1(0.0, 1.0, 2.0);
AMCAX::Coord3 crd1(0.0, 1.0, 2.0);
AMCAX::Point3 p2(crd1);
PointT< double, 3 > Point3
3D point
Definition PointT.hpp:459

Coord2(Two-Dimensional Point)

AMCAX::Point2 p3(0.0, 1.0);
AMCAX::Coord2 crd2(0.0, 1.0);
AMCAX::Point2 p4(crd2);
PointT< double, 2 > Point2
2D point
Definition PointT.hpp:456

Get and Modify

Get

You can use the following two methods to get the value of a particular dimension of the point.

AMCAX::Point3 p1(0.0, 1.0, 2.0);
double x = p1.X();
double y = p1.Y();
double z = p1.Z();
double x2 = p1[0];
double y2 = p2[1];
double z2 = p3[2];

Modify

You can modify the value of a particular dimension of the point using the following two methods.

AMCAX::Point3 p1(0.0, 1.0, 2.0);
p1.SetCoord(1.0, 0.0, 2.1);
p1.SetX(0.5);
p1.SetY(0.5);
p1.SetZ(0.5);

Common Function

Operation

The kernel does not support arithmetic operations (addition, subtraction, multiplication, division) on points. In fact, most geometries do not support arithmetic operations, except for Coord. This will not be explained further. However, if you need to perform arithmetic on points, you can first obtain the point's Coord, then perform operations on the Coord:

AMCAX::Point3 p1(0.0, 1.0, 2.0);
AMCAX::Point3 p2(1.0, 2.0, 2.0);
const Coord3& crd3 = p1.Coord();
const Coord3& crd4 = p2.Coord();
const Coord3& crd5 = crd3 + crd4;
AMCAX::Point3 p3(crd5);

Calculate the Distance Between Two Points

AMCAX::Point3 p1(0.0, 1.0, 2.0);
AMCAX::Point3 p2(1.0, 2.0, 2.0);
double dis = p1.Distance(p2);

Transformation

Most geometries support transformations such as translation, rotation, mirror, and scale, which will not be explained further.

Translation Transformation

AMCAX::TopoShape box = AMCAX::MakeBox(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
trans.SetTranslation(AMCAX::Vector3(1.0, 0.0, 0.0));
Class of making a box.
Definition MakeBox.hpp:18
Base class of shape, containing an underlying shape with a location and an orientation.
Definition TopoShape.hpp:15
Class of transforming a shape.
Definition TransformShape.hpp:12
constexpr void SetTranslation(const VectorT< OtherScalar, DIM > &vec) noexcept
Set the transformation as the translation.
Definition TransformationT.hpp:311
TransformationT< double, 3 > Transformation3
3D transformation
Definition TransformationT.hpp:1102
VectorT< double, 3 > Vector3
3D vector
Definition VectorT.hpp:707

Rotation Transformation

AMCAX::TopoShape box = AMCAX::MakeBox(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
trans.SetRotation(AMCAX::Axis3(), M_PI * 0.25);
void SetRotation(const PointT< OtherScalar, DIM > &point, const OtherScalar2 &angle) noexcept
Set the transformation as rotation around a point with an angle in 2D.
Definition TransformationT.hpp:138
AxisT< double, 3 > Axis3
3D axis
Definition AxisT.hpp:423

Mirror Transformation

Point Mirror
AMCAX::TopoShape box = AMCAX::MakeBox(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
trans.SetMirror(AMCAX::Point3(10.,10.,10.));
constexpr void SetMirror(const PointT< OtherScalar, DIM > &point) noexcept
Set the transformation as mirroring by point.
Definition TransformationT.hpp:89
Axis Mirror
AMCAX::TopoShape box = AMCAX::MakeBox(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
trans.SetMirror(AMCAX::Axis3(AMCAX::Point3(10.0, 20.0, 30.0), AMCAX::Direction3(0.0, 1.0, 1.0)));
DirectionT< double, 3 > Direction3
3D direction
Definition DirectionT.hpp:587
Plane Mirror
AMCAX::TopoShape box = AMCAX::MakeBox(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
trans.SetMirror(AMCAX::Frame3(AMCAX::Point3(10.0, 10.0, 10.0), AMCAX::Direction3(0.0, 0.0, 1.0)));
FrameT< double, 3 > Frame3
3D frame
Definition FrameT.hpp:885

Uniform Scale Transformation

AMCAX::TopoShape box = AMCAX::MakeBox(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
trans.SetScale(AMCAX::Point3(), 0.5);
void SetScale(const PointT< OtherScalar, DIM > &point, const OtherScalar2 &s)
Set the transformation as the scaling from a point.
Definition TransformationT.hpp:224

Composite Transformation

The formula for composite transformation is sRx+bsRx+b, where ss is the scaling factor, RR is the rotation matrix, xx is the coordinate to be transformed, and bb is the translation vector.

For example, constructing the following transformation: first rotate around the x-axis by π/4π/4, then scale by a factor of 0.2, and finally translate 1 unit along the x-axis:

AMCAX::TopoShape box = AMCAX::MakeBox(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
trans.SetRotationPart(AMCAX::QuaternionT<double>(AMCAX::Coord3(1.0, 0.0, 0.0), M_PI * 0.25));
trans.SetScaleFactor(0.2);
trans.SetTranslationPart(AMCAX::Vector3(1.0, 0.0, 0.0));
Class of quaternion.
Definition QuaternionT.hpp:19
void SetScaleFactor(const OtherScalar &s)
The the scale factor.
Definition TransformationT.hpp:376
constexpr void SetTranslationPart(const VectorT< OtherScalar, DIM > &vec) noexcept
Set the translation part of the transformation.
Definition TransformationT.hpp:337
void SetRotationPart(const QuaternionT< OtherScalar > &q) noexcept
Set the rotation part of the transformation from a quaternion in 3D.
Definition TransformationT.hpp:176

Transforming an Object from Local Coordinate System to Global (or Another Coordinate System)

Construct a transformation so that the object in the local coordinate system f2={O=(1,0,0), OZ=(1,1,0), OX=(0,0,1)}is transformed to the global coordinate system:

AMCAX::Frame3 f2(AMCAX::Point3(1.0, 0.0, 0.0), AMCAX::Direction3(0.5, 0.5, 0.0), AMCAX::Direction3(0.0, 0.0, 1.0));
trans1.SetTransformation(f2, f1);
constexpr void SetTransformation(const AxisT< OtherScalar, DIM > &axisFrom, const AxisT< OtherScalar2, DIM > &axisTo) noexcept
Set the transformation as the coordinate transformation between two local coordinate systems in 2D.
Definition TransformationT.hpp:254

Transforming Frame 1 by Translating and Rotating to Frame 2

Construct a transformation to change the global coordinate frame to another frame f2={O=(1,0,0), OZ=(1,1,0), OX=(0,0,1)}:

AMCAX::Frame3 f2(AMCAX::Point3(1.0, 0.0, 0.0), AMCAX::Direction3(0.5, 0.5, 0.0), AMCAX::Direction3(0.0, 0.0, 1.0));
AMCAX::TopoShape box11 = AMCAX::MakeBox(f1, 2.0, 2.0, 2.0);
trans2.SetDisplacement(f1, f2);
AMCAX::TopoShape box12 = AMCAX::TransformShape(box11, trans2);
constexpr void SetDisplacement(const FrameT< OtherScalar, DIM > &frameFrom, const FrameT< OtherScalar2, DIM > &frameTo) noexcept
Set the transformation as the transformation of two frames in 3D.
Definition TransformationT.hpp:239

Multiplying Transformations

trans1 * trans2。which applies trans2 first, then trans1:

AMCAX::TopoShape box = AMCAX::MakeBox(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
trans11.SetScaleFactor(0.2);
trans22.SetMirror(AMCAX::Point3(10., 10., 10.));
AMCAX::TopoShape bbox = AMCAX::TransformShape(box, trans11*trans22);

Vector and Direction

Vector3 refers to a mathematical vector with both direction and length, while Direction3 has only direction, with a magnitude of 1.0.

Construction

AMCAX::Vector3 vec; // (0.0,0.0,0.0)
AMCAX::Direction3 dir; // (1.0, 0.0, 0.0)
std::cout << vec << ' ' << dir << std::endl;
AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
AMCAX::Direction3 dir1(0.1, 2.0, -3.3); // automatically normalized
std::cout << vec1 << ' ' << dir1 << std::endl;
AMCAX::Vector3 vec2(dir1);
AMCAX::Direction3 dir2(vec1);
std::cout << vec2 << ' ' << dir2 << std::endl;
AMCAX::Point3 p1(0.0, 0.0, 0.0);
AMCAX::Point3 p2(1.0, 0.0, 0.0);
AMCAX::Vector3 vec3(p1, p2); // build vector P1P2
std::cout << vec3 << std::endl;

Get and Modify

The access and modification methods for vectors and directions are similar to the Coord class, except that directions are automatically normalized.

Get

To get a particular dimension's value of a vector or direction:

AMCAX::Vector3 vec; // (0.0,0.0,0.0)
AMCAX::Direction3 dir; // (1.0, 0.0, 0.0)
//vector
double x = vec.X();
double y = vec.Y();
double z = vec.Z();
double x2 = vec[0];
double y2 = vec[1];
double z2 = vec[2];
//direction
double x3 = dir.X();
double y3 = dir.Y();
double z3 = dir.Z();
double x4 = dir[0];
double y4 = dir[1];
double z4 = dir[2];
constexpr const Scalar & Z() const noexcept
Get the z component, only available when DIM >= 3.
Definition DirectionT.hpp:198
constexpr const Scalar & Y() const noexcept
Get the y component, only available when DIM >= 2.
Definition DirectionT.hpp:190
constexpr const Scalar & X() const noexcept
Get the x component, only available when DIM >= 1.
Definition DirectionT.hpp:182
constexpr const Scalar & Y() const noexcept
Get y-coordinate, only available when DIM >= 2.
Definition VectorT.hpp:158
constexpr const Scalar & Z() const noexcept
Get z-coordinate, only available when DIM >= 3.
Definition VectorT.hpp:166
constexpr const Scalar & X() const noexcept
Get x-coordinate, only available when DIM >= 1.
Definition VectorT.hpp:150

Modify

To modify a particular dimension's value of a vector or direction:

//vector
vec.SetCoord(0.1, 2.0, -3.3);
vec.SetX(0.1);
vec.SetY(2.0);
vec.SetZ(-3.3);
//direction
dir.SetCoord(0.1, 2.0, -3.3);
dir.SetX(0.1);
dir.SetY(2.0);
dir.SetZ(-3.3);
void SetX(const OtherScalar &x)
Set x component of the direction, with normalization, only available when DIM >= 1.
Definition DirectionT.hpp:128
void SetY(const OtherScalar &y)
Set y component of the direction, with normalization, only available when DIM >= 2.
Definition DirectionT.hpp:140
void SetCoord(T &&... vs)
Set the coordinate by components, with normalization.
Definition DirectionT.hpp:77
void SetZ(const OtherScalar &z)
Set z component of the direction, with normalization, only available when DIM >= 3.
Definition DirectionT.hpp:152
constexpr void SetZ(const OtherScalar &z) &noexcept
Set z-coordinate, only available when DIM >= 3.
Definition VectorT.hpp:117
constexpr void SetY(const OtherScalar &y) &noexcept
Set y-coordinate, only available when DIM >= 2.
Definition VectorT.hpp:108
constexpr void SetCoord(T &&... vs) &noexcept
Set the component values.
Definition VectorT.hpp:81
constexpr void SetX(const OtherScalar &x) &noexcept
Set x-coordinate, only available when DIM >= 1.
Definition VectorT.hpp:99

Common Operation

Operation

Vectors can be added, subtracted, and scaled by a number. Directions do not support addition and subtraction. Both vectors and directions support dot and cross products, similar to the Coord class.

Addition and Subtraction

AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
AMCAX::Vector3 vecc(2.1, 1.5, 2.3);
//+
AMCAX::Vector3 vecc1 = vecc + vec1;
//-
AMCAX::Vector3 vecc2 = vecc - vec1;

Scalar Multiplication

AMCAX::Vector3 vecc(2.1, 1.5, 2.3);
AMCAX::Vector3 vecc3 = vecc * 2.0;

Dot Product

//vector
AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
AMCAX::Vector3 vecc(2.1, 1.5, 2.3);
double t = vecc.Dot(vec1);
//direction
AMCAX::Direction3 dir1(0.1, 2.0, -3.3);
AMCAX::Direction3 dirr(2.3, 1.6, 1.3);
double t2 = dirr.Dot(dir1);

Cross Product

//vector
AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
AMCAX::Vector3 vecc(2.1, 1.5, 2.3);
AMCAX::Vector3 vecc4 = vecc.Cross(vec1);
//direction
AMCAX::Direction3 dir1(0.1, 2.0, -3.3);
AMCAX::Direction3 dirr(2.3, 1.6, 1.3);
AMCAX::Direction3 dirr2 = dirr.Cross(dir1);

Angle

The kernel supports computing angles. The Angle() method calculates the angle between vectors, with a range of [0.0, pi]. The AngleWithRef() method computes the angle with a reference direction in 2D, with a range of [-pi, pi]. The sign of the angle depends on whether the coordinate system is right-handed or left-handed.

AMCAX::Direction3 ddir(1.0, 0.0, 0.0), other_dir(0.0, 0.5, 0.5), ref_dir(0.0, 0.0, 1.0);
double angle1 = ddir.Angle(other_dir);
double angle2 = ddir.AngleWithRef(other_dir, ref_dir);

Note: In 2D, only Angle() should be used to calculate rotation.
Additionally, the methods IsOpposite() and IsParallel() can be used to check if vectors or directions are opposite or parallel:

//vector
AMCAX::VectorT<double, 3> v1(1.0, 2.0, 3.0);
AMCAX::VectorT<double, 3> v2(-1.0, -2.0, -3.0);
AMCAX::VectorT<double, 3> v3(2.0, 4.0, 6.0);
//IsOpposite
bool op1 = v1.IsOpposite(v2, 0.1);
std::cout << op1 << std::endl;
//IsParallel
bool pa1 = v1.IsParallel(v3, 0.1);
std::cout << pa1 << std::endl;
//direction
AMCAX::DirectionT<double, 3> d1(1.0, 2.0, 3.0);
AMCAX::DirectionT<double, 3> d2(-1.0, -2.0, -3.0);
AMCAX::DirectionT<double, 3> d3(2.0, 4.0, 6.0);
//IsOpposite
bool op2 = d1.IsOpposite(d2,0.1);
std::cout << op2 << std::endl;
//IsParallel
bool pa2 = d1.IsParallel(d3, 0.1);
std::cout << pa2 << std::endl;
Class of direction, i.e. the unit vector.
Definition VectorT.hpp:17
Template class of vector.
Definition VectorT.hpp:30

Magnitude

Vector can compute their magnitude and be normalized, similar to the Coord class.

Magnitude

AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
double length = vec1.Norm();

Normalization

AMCAX::Vector3 vec1(0.1, 2.0, -3.3);
AMCAX::Vector3 vn = vec1.Normalized();
//change
vec1.Normalize();

Axis

Axis3 is an axis in 3D space, equivalent to a Point3 plus a Direction3. Construction is as follows:

AMCAX::Axis3 axis(p, dir);
//get
AMCAX::Point3 p1 = axis.Location();
AMCAX::Direction3 dir1 = axis.Direction();

The kernel also supports computing the angle and magnitude of axis:

AMCAX::Axis3 axis(p, dir);
AMCAX::Axis3 axis2(AMCAX::Point3(1.0, 2.0, 3.0), AMCAX::Direction3(0.0, 1.0, 1.0));
double angle = axis.Angle(axis2);

Frame

Definition

Frame3 is a frame in 3D space, consisting of a point and three mutually perpendicular directions.

The world coordinate system {O; x, y, z} is a commonly used frame, and the default constructor of Frame3 creates this frame:

const AMCAX::Point3& p = frame.Location();
//get
const AMCAX::Direction3& x = frame.XDirection();
const AMCAX::Direction3& y = frame.YDirection();
const AMCAX::Direction3& z = frame.Direction();
AMCAX::Frame3 frame2(p, z, x);
constexpr const DirectionT< Scalar, DIM > & XDirection() const noexcept
Get the x direction, only available when DIM >= 1.
Definition FrameT.hpp:449
constexpr const PointT< Scalar, DIM > & Location() const noexcept
Get the location.
Definition FrameT.hpp:433
constexpr const DirectionT< Scalar, DIM > & YDirection() const noexcept
Get the y direction, only available when DIM >= 2.
Definition FrameT.hpp:457
constexpr const DirectionT< Scalar, DIM > & Direction() const noexcept
Get the main direction (z direction) in 3D.
Definition FrameT.hpp:441

Note: If the input z-axis is not perpendicular to the x-axis, the algorithm will compute the y-axis as the cross product of z and x, and compute x as the cross product of y and z.

Right-Handed and Left-Handed Systems

The left image shows a right-handed system, and the right image shows a left-handed system (with blue, green, and red representing the x, y, and z axes respectively). The most common local coordinate system is the right-handed system. To determine if a frame is right-handed, curl the fingers of the right hand from x to y, and if the thumb points in the z direction, it is a right-handed system.

The way we kernel to get whether a standard frame is right-handed or not is:

bool isRightHand = frame.IsDirect();
constexpr bool IsDirect() const noexcept
Is the 3D frame right-handed.
Definition FrameT.hpp:520

Local Coordinate System

A frame can represent a local coordinate system, which simplifies the construction of spatial curves and surfaces.

Transformation

There are three main transformations: transforming from a local coordinate system to the global coordinate system, transforming from one local coordinate system to another, and constructing affine transformations to translate, rotate, or mirror one frame to another. Refer to the transformation section above for more details.

3D Parametric Curve

Common Functions

Obtaining Parameter Range

AMCAX::Geom3Curve::FirstParameter is used to obtain the starting parameter of the curve, and AMCAX::Geom3Curve::LastParameter is used to obtain the ending parameter of the curve.

//1
std::vector<AMCAX::Point3> pts22 = {
AMCAX::Point3(0.5, 0.5,0.3),
AMCAX::Point3(1.0, 3.0,0.4),
AMCAX::Point3(3.0, 1.0,0.1),
AMCAX::Point3(3.8,2.0,0.6),
AMCAX::Point3(2.5,3.5,0.8),
AMCAX::Point3(1.0,0.5,0.9),
AMCAX::Point3(0.3,2.0,0.5)
};
std::vector<double> weights = { 1.0, 2.0, 3.0, 4.0, 3.0, 2.0, 1.0 };
std::vector<double> knots = { 0.0, 0.25, 0.5, 1.0 };
std::vector<int> mults = { 4, 1, 2, 4 };
std::shared_ptr< AMCAX::Geom3BSplineCurve> bspline = std::make_shared< AMCAX::Geom3BSplineCurve>(pts22, weights, knots, mults, 3);
double fp = bspline->FirstParameter();
double lp = bspline->LastParameter();
std::cout << fp <<"," << lp << std::endl;//0,1
//2
std::shared_ptr< AMCAX::Geom3Parabola >parabola = p.Value();
AMCAX::Geom3TrimmedCurve trimcurve(parabola, -2.0, 2.0);
double fp2 = trimcurve.FirstParameter();
double lp2 = trimcurve.LastParameter();
std::cout << fp2 << "," << lp2 << std::endl;//-2,2
Class of 3D trimmed curve.
Definition Geom3TrimmedCurve.hpp:12
Class of making 3D geometric parabolas.
Definition MakeGeom3Parabola.hpp:13

Evaluation and Differentiation

AMCAX::Geom3Curve::Value or AMCAX::Geom3Curve::D0 is used for evaluation, while AMCAX::Geom3Curve::D1, AMCAX::Geom3Curve::D2, AMCAX::Geom3Curve::D3, and AMCAX::Geom3Curve::DN are used for differentiation.

//1
double t = 0.4 * (fp + lp);
AMCAX::Point3 p1 = bspline->Value(t);
AMCAX::Vector3 d1, d2, d3;
bspline->D0(t, p2);
bspline->D1(t, p2, d1);
bspline->D2(t, p2, d1, d2);
bspline->D3(t, p2, d1, d2, d3);
int deriv = 4;
AMCAX::Vector3 dn = bspline->DN(t, deriv);
//2
double t2 = 1.5;
AMCAX::Point3 p3 = trimcurve.Value(t2);
AMCAX::Vector3 dd1, dd2, dd3;
trimcurve.D0(t2, p4);
trimcurve.D1(t2, p4, dd1);
trimcurve.D2(t2, p4, dd1, dd2);
trimcurve.D3(t2, p4, dd1, dd2, dd3);
int deriv2 = 4;
AMCAX::Vector3 ddn = trimcurve.DN(t2, deriv2);

Obtaining Type

AMCAX::Geom3Curve::Type is used to obtain the type of the curve, such as line, circle, ellipse, parabola, etc. The curve types can be referred to the enumeration class CurveType.

std::cout << int(bspline->Type()) << ";" << int(trimcurve.Type());//7;8

Closedness and Periodicity

AMCAX::Geom3Curve::IsClosed is used to determine if the curve is closed (the starting point and the ending point are the same), and AMCAX::Geom3Curve::IsPeriodic is used to determine if the curve is periodic.

std::cout <<bspline->IsClosed()<< ";" << bspline->IsPeriodic();//0;0
std::cout <<trimcurve.IsClosed()<< ";" << trimcurve.IsPeriodic();//0;0

Reverse

AMCAX::Geom3Curve::Reverse is used to reverse the Geom3Curve, modifying itself, while AMCAX::Geom3Curve::Reversed is used to obtain a reversed Geom3Curve without altering the original. After reversal, the starting and ending points of the curve are swapped. For general curves, the parameter range of the curve remains unchanged, whereas for trimmed curves, the parameter range may change. For example, a trimmed line originally with a parameter range from -1 to 3 will have a parameter range from -3 to 1 after reversal.

//1
//reversed
auto reverse = bspline->Reversed();
double fp3 = reverse->FirstParameter();
double lp3 = reverse->LastParameter();
std::cout << fp3 << "," << lp3 << std::endl;//0,1
std::cout << bspline->Value(fp) << std::endl;//0.5 0.5 0.3
std::cout << bspline->Value(lp) << std::endl;//0.3 2 0.5
std::cout<<reverse->Value(fp3)<<std::endl;//0.3 2 0.5
std::cout<<reverse->Value(lp3)<<std::endl;//0.5 0.5 0.3
//reverse
bspline->Reverse();
double fp4 = bspline->FirstParameter();
double lp4 = bspline->LastParameter();
std::cout << fp4 << "," << lp4 << std::endl;//0,1
std::cout << reverse->Value(fp4) << std::endl;//0.3 2 0.5
std::cout << reverse->Value(lp4) << std::endl;//0.5 0.5 0.3
//2
auto line2 = std::make_shared<AMCAX::Geom3Line>(AMCAX::Point3(0., 0., 0.), AMCAX::Direction3(1., 0., 0.));
auto trimline2 = std::make_shared<AMCAX::Geom3TrimmedCurve>(line2, -1.0, 3.0);
std::cout << trimline2->Value(-1.0) << std::endl;//-1 0 0
std::cout << trimline2->Value(3.0) << std::endl;//3 0 0
//reversed
auto reverse2 = trimline2->Reversed();
double fp5 = reverse2->FirstParameter();
double lp5 = reverse2->LastParameter();
std::cout << fp5 << "," << lp5 << std::endl;//-3,1
std::cout << reverse2->Value(fp5) << std::endl;//3 0 0
std::cout << reverse2->Value(lp5) << std::endl;//-1 0 0
//reverse
trimline2->Reverse();
double fp6 = trimline2->FirstParameter();
double lp6 = trimline2->LastParameter();
std::cout << fp6 << "," << lp6 << std::endl;//-3,1
std::cout << trimline2->Value(fp6) << std::endl;//3 0 0
std::cout <<trimline2->Value(lp6) << std::endl;//-1 0 0

Here, we explain why the parameter range of the trimmed line changes to -3 to 1 after reversal. This is because when reversing a trimmed curve, the reversal is first applied to its basis curve (an infinitely long line), and then the parameters of the reversed starting and ending points are used to determine the parameter range after reversal.

Additionally, if you want to calculate the symmetric parameter for a given parameter, you can use AMCAX::Geom3Curve::ReversedParameter to achieve this.

std::cout << trimline->ReversedParameter(0.5) << std::endl;//-0.5

Subclasses

Geom3Line

Geom3Line is an infinitely long 3D line defined by a Point3 and a Direction3. The parameter at the Point3 is 0.0, and the parameter is positive in the direction of Direction3, with the parameter varying consistently with the length. The parameter domain of the line is infinite.

auto line = std::make_shared<AMCAX::Geom3Line>(AMCAX::Point3(0., 1., 1.), AMCAX::Direction3(1., 2., 3.));
auto trimline = std::make_shared<AMCAX::Geom3TrimmedCurve>(line, 0.0, 1.0);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge(trimline), "trimline.brep");
Class of making an edge.
Definition MakeEdge.hpp:24
static AMCAX_API bool Write(const TopoShape &s, std::ostream &os, int format=3)
Write a shape to a stream.

Geom3Circle

Geom3Circle is a circle in 3D space, defined by a frame and a radius, i.e., a standard circle on the XOY plane of the frame (with the center at the origin of the frame, and a point on the circle lying on the x-axis when the parameter is 0, rotating counterclockwise as the parameter increases). The parameter domain of the circle is [0, 2*pi), representing the parametric coordinates of the circle.

auto circle = std::make_shared<AMCAX::Geom3Circle>(AMCAX::Frame3(), 1.0);

Geom3Ellipse

Geom3Ellipse is an ellipse in 3D space, defined by a frame and its major and minor radii, i.e., a standard ellipse on the XOY plane of the frame (with the center at the origin of the frame, and a point on the ellipse lying on the x-axis when the parameter is 0, rotating counterclockwise as the parameter increases). The parameter domain of the ellipse is [0, 2*pi), representing the parametric coordinates of the ellipse.

auto ellipse = std::make_shared<AMCAX::Geom3Ellipse>(AMCAX::Frame3(), 2.0,1.0);

Geom3Hyperbola

Geom3Hyperbola represents the right branch of a hyperbola in 3D space, defined by a frame and the radii of the real and imaginary axes, i.e., the right branch of a standard hyperbola on the XOY plane of the frame (with the center at the origin of the frame, and a point on the hyperbola lying on the positive half of the x-axis when the parameter is 0, rotating counterclockwise as the parameter increases, and the y-coordinate on the XOY plane becoming larger as the parameter increases). If you want to obtain the left branch of the hyperbola, you can use AMCAX::Geom3Hyperbola::OtherBranch. The parameter domain of the hyperbola is [-∞, +∞], representing the parametric coordinates of the hyperbola.

auto hyperbola = std::make_shared<AMCAX::Geom3Hyperbola>(AMCAX::Frame3(), 2.0, 1.0);
auto trimhyperbola = std::make_shared<AMCAX::Geom3TrimmedCurve>(hyperbola, 0.0, 2.0);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge(trimhyperbola), "trimhyperbola.brep");

Geom3Parabola

Geom3Parabola is a parabola in 3-dimensional space, defined by a reference frame and focal distance. Specifically, it is the standard parabola in the XOY plane of the reference frame (with the vertex at the origin of the reference frame, the axis of symmetry along the x-axis, and a parameter of 0 corresponding to a point on the parabola at the origin). As the parameter increases, the point moves along the parabola, and the y-coordinate on the XOY plane increases with larger parameter values. The domain of the parameter for the parabola is [-∞, +∞], representing the parameter coordinates of the parabola.

auto parabola2 = std::make_shared<AMCAX::Geom3Parabola>(AMCAX::Frame3(), 1.0);
auto trimparabola = std::make_shared<AMCAX::Geom3TrimmedCurve>(parabola2, -2.0, 2.0);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge(trimparabola), "trimparabola.brep");

Geom3BezierCurve

Geom3BezierCurve is a Bezier curve in 3D space, defined by control points and optional weights. The degree of the curve is one less than the number of control points; for example, if there are 4 control points, the curve is a cubic Bezier curve. Additionally, the parameter domain of the Bezier curve is [0,1]. When the parameter t=0, the curve is at the starting point (the first control point), and when t=1, the curve is at the ending point (the last control point). For a standard Bezier curve, its knot vector is {0, 1}, and the multiplicity of each knot is the degree plus one.

std::vector<AMCAX::Point3> pts3 = {
AMCAX::Point3(0.0, 0.0,0.0),
AMCAX::Point3(2.0, 2.0,2.0),
AMCAX::Point3(4.0, 3.0,5.0),
AMCAX::Point3(6.0,2.0,4.0)
};
auto bezier = std::make_shared<AMCAX::Geom3BezierCurve>(pts3);

Geom3BSplineCurve

Geom3BSplineCurve is a BSpline curve in 3D space, defined by control points, a knot vector, knot multiplicities, and optional weights.

std::vector<AMCAX::Point3> pts = {
AMCAX::Point3(0.5, 0.5,0.3),
AMCAX::Point3(1.0, 3.0,0.4),
AMCAX::Point3(3.0, 1.0,0.1),
AMCAX::Point3(3.8,2.0,0.6),
AMCAX::Point3(2.5,3.5,0.8),
AMCAX::Point3(1.0,0.5,0.9),
AMCAX::Point3(0.3,2.0,0.5)
};
std::vector<double> weights2 = { 1.0, 2.0, 3.0, 4.0, 3.0, 2.0, 1.0 };
std::vector<double> knots2 = { 0.0, 0.25, 0.5, 1.0 };
std::vector<int> mults2 = { 4, 1, 2, 4 };
auto bspline2 = std::make_shared< AMCAX::Geom3BSplineCurve>(pts, weights2, knots2, mults2, 3);

Geom3TrimmedCurve

Geom3TrimmedCurve is a trimmed curve in 3D space, consisting of the original curve and two trimming parameters. It should be noted that the trimmed curve is always non-periodic, even if the trimming is done on a circle with the parameters [0, 2pi]. Additionally, periodic curves can be trimmed beyond their defined domain, such as with a circle.

auto circle = std::make_shared<AMCAX::Geom3Circle>(AMCAX::Frame3(), 1.0);
auto trimcircle2 = std::make_shared<AMCAX::Geom3TrimmedCurve>(circle, -M_PI / 4, M_PI * 3 / 4);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge(trimcircle2), "trimcircle2.brep");

Geom3OffsetCurve

Geom3OffsetCurve is an offset curve in 3D space, composed of the original curve, offset distance, and reference direction. Its function is to offset the original curve by a specified distance in a direction perpendicular to the tangent, with the offset direction being the cross product of the tangent and the reference direction, as shown in the figure below. Here, the blue arrow represents the tangent, the green arrow represents the reference direction, and the red arrow represents the cross product direction, which is the offset direction.

Taking a standard circle on the xoy plane as an example, when the reference direction is oz, the offset direction is outward. Below is the result after offsetting:

Additionally, if you want to obtain the original curve of the offset curve, you can use AMCAX::Geom3OffsetCurve::BasisCurve.

auto circle2 = std::make_shared<AMCAX::Geom3Circle>(AMCAX::Frame3(), 2.0);
double offset = 1.5;
AMCAX::Direction3 direction(0.0, 0.0, 1.0);
auto circleoffset = std::make_shared<AMCAX::Geom3OffsetCurve>(circle2, offset, direction);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge(circleoffset), "circleoffset.brep");
auto basiscircle = circleoffset->BasisCurve();

2D Parametric Curve

Common Functions

Obtaining Parameter Range

AMCAX::Geom2Curve::FirstParameter is used to obtain the starting parameter of the curve, and AMCAX::Geom2Curve::LastParameter is used to obtain the ending parameter of the curve.

//1
std::vector<AMCAX::Point2> pts22 = {
AMCAX::Point2(0.5, 0.5),
AMCAX::Point2(1.0, 3.0),
AMCAX::Point2(3.0, 1.0),
AMCAX::Point2(3.8,2.0),
AMCAX::Point2(2.5,3.5),
AMCAX::Point2(1.0,0.5),
AMCAX::Point2(0.3,2.0)
};
std::vector<double> knots = { 0.0, 0.25, 0.5,0.75,1.0 };
std::vector<int> mults = { 4, 1, 1,1,4 };
std::shared_ptr< AMCAX::Geom2BSplineCurve> bspline2 = std::make_shared< AMCAX::Geom2BSplineCurve>(pts22, knots, mults, 3);
double fp = bspline2->FirstParameter();
double lp = bspline2->LastParameter();
std::cout << fp <<"," << lp << std::endl;//0,1
//2
std::shared_ptr< AMCAX::Geom2Parabola >parabola2 = std::make_shared< AMCAX::Geom2Parabola>(AMCAX::Frame2(), 2.0);
AMCAX::Geom2TrimmedCurve trimcurve(parabola2, -2.0, 2.0);
double fp2 = trimcurve.FirstParameter();
double lp2 = trimcurve.LastParameter();
std::cout << fp2 << "," << lp2 << std::endl;//-2,2
Class of 2D trimmed curve.
Definition Geom2TrimmedCurve.hpp:12
FrameT< double, 2 > Frame2
2D frame
Definition FrameT.hpp:882

Evaluation and Differentiation

AMCAX::Geom2Curve::Value or AMCAX::Geom2Curve::D0 are used for evaluation, while AMCAX::Geom2Curve::D1, AMCAX::Geom2Curve::D2, AMCAX::Geom2Curve::D3, AMCAX::Geom2Curve::DN are used for differentiation.

//1
double t = 0.4 * (fp + lp);
AMCAX::Point2 p1 = bspline2->Value(t);
AMCAX::Vector2 d1, d2, d3;
bspline2->D0(t, p2);
bspline2->D1(t, p2, d1);
bspline2->D2(t, p2, d1, d2);
bspline2->D3(t, p2, d1, d2, d3);
int deriv = 4;
AMCAX::Vector2 dn = bspline2->DN(t, deriv);
//2
double t2 = 1.5;
AMCAX::Point2 p3 = trimcurve.Value(t2);
AMCAX::Vector2 dd1, dd2, dd3;
trimcurve.D0(t2, p4);
trimcurve.D1(t2, p4, dd1);
trimcurve.D2(t2, p4, dd1, dd2);
trimcurve.D3(t2, p4, dd1, dd2, dd3);
int deriv2 = 4;
AMCAX::Vector2 ddn = trimcurve.DN(t2, deriv2);
VectorT< double, 2 > Vector2
2D vector
Definition VectorT.hpp:704

Getting Curve Type

AMCAX::Geom2Curve::Type is used to obtain the type of the curve, such as line, circle, ellipse, parabola, etc. Curve types can be referenced from the enum class CurveType.

std::cout << int(bspline2->Type()) << ";" << int(trimcurve.Type());//7;8

Closedness and Periodicity

AMCAX::Geom2Curve::IsClosed is used to determine whether the curve is closed (whether the start and end points are the same), and AMCAX::Geom2Curve::IsPeriodic is used to determine if the curve is periodic.

std::cout <<bspline2->IsClosed()<< ";" << bspline2->IsPeriodic();//0;0
std::cout <<trimcurve.IsClosed()<< ";" << trimcurve.IsPeriodic();//0;0

Reversal

AMCAX::Geom2Curve::Reverse is used to reverse the Geom2Curve and change it, while AMCAX::Geom2Curve::Reversed returns the reversed Geom2Curve without modifying the original. After reversing, the start and end points of the curve are swapped. For general curves, the parameter range remains unchanged, but for trimmed curves, the parameter range might change. For example, a trimmed line with a parameter range from -1 to 3 will have its range reversed to -3 to 1.

//1
std::vector<AMCAX::Point2> pts3 = {
AMCAX::Point2(0.0, 0.0),
AMCAX::Point2(2.0, 2.0),
AMCAX::Point2(4.0, 3.0),
};
auto bezier2 = std::make_shared<AMCAX::Geom2BezierCurve>(pts3);
std::cout << bezier2->FirstParameter() << std::endl;//0
std::cout << bezier2->LastParameter() << std::endl;//1
// reversed
auto reversebezier = bezier2->Reversed();
std::cout << reversebezier->FirstParameter() << std::endl;//0
std::cout << reversebezier->LastParameter() << std::endl;//1
std::cout << reversebezier->Value(0) << std::endl;//4 3
std::cout << reversebezier->Value(1) << std::endl;//0 0
//reverse
bezier2->Reverse();
std::cout << bezier2->FirstParameter() << std::endl;//0
std::cout << bezier2->LastParameter() << std::endl;//1
std::cout << bezier2->StartPoint() << std::endl;//4 3
std::cout << bezier2->EndPoint() << std::endl;//0 0
//2
auto line2 = std::make_shared<AMCAX::Geom2Line>(AMCAX::Point2(0., 0.), AMCAX::Direction2(1., 0.));
auto trimline2 = std::make_shared<AMCAX::Geom2TrimmedCurve>(line2, -1., 3.);
std::cout << trimline2->StartPoint() << std::endl;//-1 0
std::cout << trimline2->EndPoint()<< std::endl;//3 0
// reversed
auto reverseline = trimline2->Reversed();
std::cout << reverseline->FirstParameter() << std::endl;//-3
std::cout << reverseline->LastParameter() << std::endl;//1
std::cout << reverseline->Value(-3) << std::endl;//3 0
std::cout << reverseline->Value(1) << std::endl;//-1 0
//reverse
trimline2->Reverse();
std::cout << trimline2->FirstParameter() << std::endl;//-3
std::cout << trimline2->LastParameter() << std::endl;//1
std::cout << trimline2->StartPoint() << std::endl;//3 0
std::cout << trimline2->EndPoint() << std::endl;//-1 0
DirectionT< double, 2 > Direction2
2D direction
Definition DirectionT.hpp:584

Here, we explain the reason why the parameter range of a trimmed line changes from -3 to 1 after reversal. This is because, when reversing a trimmed curve, it first reverses its basiscurve (the infinitely long line) and then determines the reversed parameter range based on the start and end parameters of the trimmed curve.

Additionally, to calculate the symmetric parameter for a given parameter, you can use AMCAX::Geom2Curve::ReversedParameter:

std::cout<<trimline2->ReversedParameter(0.5)<<std::endl;//-0.5

Subclasses

Except for Geom2OffsetCurve, the others are similar to their 3D counterparts.

Geom2Line

Geom2Line is an infinitely long 2D line defined by a Point2 and a Direction2. The parameter at Point2 is 0.0, and the parameter increases in the direction of Direction2. The parameter variation corresponds to the length variation. The parameter domain of the line is infinite.

auto line = std::make_shared<AMCAX::Geom2Line>(AMCAX::Point2(0., 1.), AMCAX::Direction2(1., 2.));
auto trimline = std::make_shared<AMCAX::Geom2TrimmedCurve>(line, 0.0, 1.0);
Class of making a 2D edge.
Definition MakeEdge2d.hpp:22

Geom2Circle

Geom2Circle is a circle in 2D space, defined by a frame and a radius. It represents a standard circle in the XOY plane of the frame (the center at the frame origin, the point on the x-axis when the parameter is 0, and the point rotates counterclockwise as the parameter increases). The parameter domain of the circle is [0, 2*pi), representing the parametric coordinates of the circle.

auto circle = std::make_shared<AMCAX::Geom2Circle>(AMCAX::Frame2(), 1.0);

Geom2Ellipse

Geom2Ellipse is an ellipse in 2D space, defined by a frame and the major and minor radii. It represents a standard ellipse in the XOY plane of the frame (the center at the frame origin, the point on the x-axis when the parameter is 0, and the point rotates counterclockwise as the parameter increases). The parameter domain of the ellipse is [0, 2*pi), representing the parametric coordinates of the ellipse.

auto ellipse = std::make_shared<AMCAX::Geom2Ellipse>(AMCAX::Frame2(), 2.0,1.0);

Geom2Hyperbola

Geom2Hyperbola is the right branch of a hyperbola in 2D space, defined by a frame and the radii of the real and imaginary axes. It represents the right branch of a standard hyperbola in the XOY plane of the frame (the center at the frame origin, the point on the positive x-axis when the parameter is 0, and the point moves along the right branch of the hyperbola as the parameter increases. As the parameter increases, the y-coordinate in the XOY plane also increases). To obtain the left branch of the hyperbola, you can use AMCAX::Geom2Hyperbola::OtherBranch. The parameter domain of the hyperbola is [-∞, +∞], representing the parametric coordinates of the hyperbola.

auto hyperbola = std::make_shared<AMCAX::Geom2Hyperbola>(AMCAX::Frame2(), 2.0, 1.0);
auto trimhyperbola = std::make_shared<AMCAX::Geom2TrimmedCurve>(hyperbola, 0.0, 2.0);
AMCAX::Hyperbola2 otherbranch= hyperbola->OtherBranch();
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge2d(trimhyperbola), "trimhyperbola.brep");
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge2d(otherbranch,0.0,2.0), "otherbranch.brep");
HyperbolaS< 2 > Hyperbola2
2D hyperbola
Definition HyperbolaT.hpp:298

Geom2Parabola

Geom2Parabola is a parabola in 2D space, defined by a frame and the focal distance. It represents a standard parabola in the XOY plane of the frame (the vertex at the frame origin, with the axis of symmetry along the x-axis, the point at the origin when the parameter is 0, and the point moves along the parabola as the parameter increases. As the parameter increases, the y-coordinate in the XOY plane also increases). The parameter domain of the parabola is [-∞, +∞], representing the parametric coordinates of the parabola.

auto parabola = std::make_shared<AMCAX::Geom2Parabola>(AMCAX::Frame2(), 1.0);
auto trimparabola = std::make_shared<AMCAX::Geom2TrimmedCurve>(hyperbola, -2.0, 2.0);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge2d(trimparabola), "trimparabola.brep");

Geom2BezierCurve

Geom2BezierCurve is a Bezier curve in 2D space, defined by control points and optional weights. The degree of the curve is the number of control points minus one; for example, with 4 control points, the curve is a 3rd degree Bezier curve. The parameter domain of a Bezier curve is [0,1]. When the parameter t = 0, the curve is at the start point (the first control point), and when t = 1, the curve is at the endpoint (the last control point). For standard Bezier curves, the node vector is {0, 1}, and the multiplicity of each node is the degree + 1.

std::vector<AMCAX::Point2> pts = {
AMCAX::Point2(0.0, 0.0),
AMCAX::Point2(2.0, 2.0),
AMCAX::Point2(4.0, 3.0),
};
auto bezier = std::make_shared<AMCAX::Geom2BezierCurve>(pts);

Geom2BSplineCurve

Geom2BSplineCurve is a B-Spline curve in 2D space, defined by control points, knots, knot multiplicities, curve degree, and optional weights.

std::vector<AMCAX::Point2> pts2 = {
AMCAX::Point2(0.5, 0.5),
AMCAX::Point2(1.0, 3.0),
AMCAX::Point2(3.0, 1.0),
AMCAX::Point2(3.8,2.0),
AMCAX::Point2(2.5,3.5),
AMCAX::Point2(1.0,0.5),
AMCAX::Point2(0.3,2.0)
};
std::vector<double> knots2 = { 0.0, 0.25, 0.5,0.75,1.0 };
std::vector<int> mults2 = { 4, 1, 1,1,4 };
auto bspline = std::make_shared< AMCAX::Geom2BSplineCurve>(pts2, knots2, mults2, 3);

Geom2TrimmedCurve

Geom2TrimmedCurve is a trimmed curve in 2D space, defined by an original curve and two trimming parameters. Similar to 3D, the trimmed curve is always non-periodic, and periodic curves can be trimmed beyond the domain. For example, for a circle:

auto circle = std::make_shared<AMCAX::Geom2Circle>(AMCAX::Frame2(), 1.0);
auto trimcircle2 = std::make_shared<AMCAX::Geom2TrimmedCurve>(circle, -M_PI / 4, M_PI * 3 / 4);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge2d(trimcircle2), "trimcircle2.brep");

Geom2OffsetCurve

Geom2OffsetCurve is an offset curve in 2D space, defined by the original curve and an offset distance. The offset direction is a 90° clockwise rotation of the tangent. Additionally, to obtain the original curve of the offset curve, you can use AMCAX::Geom2OffsetCurve::BasisCurve .

auto circle2 = std::make_shared<AMCAX::Geom2Circle>(AMCAX::Frame2(), 2.0);
double offset = 1.5;
auto circleoffset = std::make_shared<AMCAX::Geom2OffsetCurve>(circle2, offset);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeEdge2d(circleoffset), "circleoffset.brep");
auto basiscircle = circleoffset->BasisCurve();

3D Parametric Surface

Common Functions

Getting Parameter Range

Bounds() gets the full parameter range. FirstUParameter() gets the starting U parameter, LastUParameter() gets the ending U parameter, FirstVParameter() gets the starting V parameter, and LastVParameter() gets the ending V parameter.

AMCAX::Geom3CylindricalSurface CylindricalSurface4(AMCAX::Frame3(), 2.0);
double u1=0., u2=0., v1=0., v2=0.;
CylindricalSurface4.Bounds(u1, u2, v1, v2);
std::cout << u1 << "-" << u2 << std::endl;//0-6.28319
std::cout << v1 << "-" << v2 << std::endl;//-1e+100-1e+100
std::cout<<CylindricalSurface4.FirstUParameter()<<std::endl;//0
std::cout<<CylindricalSurface4.LastUParameter()<<std::endl;//6.28319
std::cout<<CylindricalSurface4.FirstVParameter()<<std::endl;//-1e+100
std::cout<<CylindricalSurface4.LastVParameter()<<std::endl;//1e+100
Class of 3D cylindrical surface.
Definition Geom3CylindricalSurface.hpp:14

Evaluation and Derivatives

Use Value or D0 to evaluate, and D1, D2, D3, DN to get derivatives.

AMCAX::Geom3CylindricalSurface CylindricalSurface4(AMCAX::Frame3(), 2.0);
//value D0
std::cout << CylindricalSurface4.Value(1., 2.) << std::endl;//1.0806 1.68294 2
CylindricalSurface4.D0(1., 2., p1);
std::cout << p1 << std::endl;//1.0806 1.68294 2
//D1
CylindricalSurface4.D1(1., 2., p2, du1, dv1);
std::cout << p2 << std::endl;//1.0806 1.68294 2
std::cout << du1 << std::endl;//-1.68294 1.0806 0
std::cout << dv1 << std::endl;//0 0 1
//D2
CylindricalSurface4.D2(1., 2., p3, du2, dv2,duu1,duv1,dvv1);
std::cout << p3 << std::endl;//1.0806 1.68294 2
std::cout << du2 << std::endl;//-1.68294 1.0806 0
std::cout << dv2 << std::endl;//0 0 1
std::cout << duu1 << std::endl;//-1.0806 -1.68294 -0
std::cout << duv1 << std::endl;//0 0 0
std::cout << dvv1 << std::endl;//0 0 0
//D3
CylindricalSurface4.D3(1., 2., p4, du3, dv3, duu2, duv2, dvv2,duuu,duuv,duvv,dvvv);
std::cout << p4 << std::endl;//1.0806 1.68294 2
std::cout << du3 << std::endl;//-1.68294 1.0806 0
std::cout << dv3 << std::endl;//0 0 1
std::cout << duu2 << std::endl;//-1.0806 -1.68294 -0
std::cout << duv2 << std::endl;//0 0 0
std::cout << dvv2 << std::endl;//0 0 0
std::cout << duuu << std::endl;//1.98294 -1.0806 0
std::cout << duuv << std::endl;//0 0 0
std::cout << duvv << std::endl;//0 0 0
std::cout << dvvv << std::endl;//0 0 0
//DN
int nu = 4, nv = 4;
std::cout << CylindricalSurface4.DN(1., 2., nu, nv) << std::endl;//0 0 0

Getting Type

Type() gets the type, such as plane, sphere, etc.

std::cout << int(CylindricalSurface4.Type()) << std::endl;//2

Closedness and Periodicity

IsUClosed() gets the closure in the U direction, IsUPeriodic() gets the periodicity in the U direction, IsVClosed() gets the closure in the V direction, IsVPeriodic() gets the periodicity in the V direction.

std::cout << CylindricalSurface4.IsUClosed() << std::endl;//1
std::cout << CylindricalSurface4.IsUPeriodic() << std::endl;//1
std::cout << CylindricalSurface4.IsVClosed() << std::endl;//0
std::cout << CylindricalSurface4.IsVPeriodic() << std::endl;//0

Reverse

UReverse() reverses the U direction, and VReverse() reverses the V direction. After reversing, the starting and ending parameters of U and V will not change, only the coordinates will be flipped.

std::cout << CylindricalSurface4.Value(CylindricalSurface4.FirstUParameter(), CylindricalSurface4.FirstVParameter()) << std::endl;// 2 0 -1e+100
std::cout << CylindricalSurface4.Value(CylindricalSurface4.LastUParameter(), CylindricalSurface4.LastVParameter()) << std::endl;//2 -4.89859e
CylindricalSurface4.UReverse();
CylindricalSurface4.VReverse();
std::cout << CylindricalSurface4.Value(CylindricalSurface4.FirstUParameter(), CylindricalSurface4.FirstVParameter()) << std::endl;//2 0 1e+100
std::cout << CylindricalSurface4.Value(CylindricalSurface4.LastUParameter(), CylindricalSurface4.LastVParameter()) << std::endl;//2 4.89859e-16 -1e+100

Additionally, UReversedParameter(t) computes the symmetric parameter of t in the u direction, while VReversedParameter(t) computes the symmetric parameter of t in the v direction.

std::cout << CylindricalSurface4.UReversedParameter(2.) << std::endl;//4.28319
std::cout << CylindricalSurface4.VReversedParameter(2.) << std::endl;//-2

Iso-parametric Curves

UIso() returns the u iso-parameteric curve, which is the spatial curve corresponding to a straight line u = u0 in the parameter domain, and VIso() returns the v iso-parametric curve, which is the spatial curve corresponding to a straight line v = v0 in the parameter domain.

std::shared_ptr< AMCAX::Geom3Curve >uiso = CylindricalSurface4.UIso(2.);
std::shared_ptr< AMCAX::Geom3Curve >viso = CylindricalSurface4.VIso(2.);

In the above example, the UIso is a line parallel to the Z-axis located on the side of the cylinder, and the VIso is a circle with radius r = 2.0 located at height v = 2.0.

Subclasses

Geom3Plane

Geom3Plane is a plane in 3D space with an infinite parameter domain. The plane can be created based on AMCAX::Frame3, with the XOY plane as the surface and the OZ axis as the normal. The u direction corresponds to the OX direction, and the v direction corresponds to the OY direction. The 3D space point at (u, v) = (0, 0) is the origin of the Frame3 coordinate system.

AMCAX::Geom3Plane plane(frame);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeFace(plane.GetPlane(), 0., 2., 0., 2.), "plane.brep");
Class of 3D plane.
Definition Geom3Plane.hpp:14
Class of making a face.
Definition MakeFace.hpp:22

Geom3SphericalSurface

Geom3SphericalSurface is a sphere in 3D space with a parameter domain of [0, 2π) x [-π/2, π/2]. The parameters correspond to spherical coordinates. The sphere can be created using AMCAX::Frame3 and a radius. The origin of Frame3 is the center of the sphere. The circle in the XOY plane corresponds to an iso-parameteric curve with v = 0, while the semicircle in the XOZ plane corresponds to the iso-parameteric curve with u = 0. The positive u direction corresponds to a rotation of the OX axis towards the OY axis, and the positive v direction corresponds to a rotation from -OZ to OZ.

AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeFace(SphericalSurface.GetSphere(), 0., 1., 0., 1.), "SphericalSurface.brep");
Class of 3D spherical surface.
Definition Geom3SphericalSurface.hpp:14

Geom3CylindricalSurface

Geom3CylindricalSurface is a cylindrical surface (infinite length) in 3D space with a parameter domain of [0, 2π) x [-∞, ∞]. The parameters correspond to cylindrical coordinates. The cylinder surface can be created using AMCAX::Frame3 and a radius. The circle in the XOY plane corresponds to an iso-parameteric curve with v = 0. The positive u direction corresponds to a rotation from the OX axis towards the OY axis, while the v direction corresponds to the positive z direction. The change in v corresponds to the change in arc length.

AMCAX::Geom3CylindricalSurface CylindricalSurface(AMCAX::Frame3(), 2.0);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeFace(CylindricalSurface.GetCylinder(), 0., 2., 0., 2.), "CylindricalSurface.brep");

Geom3ConicalSurface

Geom3ConicalSurface is a conical surface (infinite length) in 3D space with a parameter domain of [0, 2π) x [-∞, ∞]. The conical surface can be created using Frame3, the radius of the circle in the XOY plane, and the half-angle. The circle in the XOY plane corresponds to an iso-parameteric curve with v = 0. The positive u direction corresponds to a rotation from the OX axis towards the OY axis, while the positive v direction corresponds to an inclined line, forming an acute angle with the z direction.

AMCAX::Geom3ConicalSurface ConicalSurface(AMCAX::Frame3(), 2.0, 45.0 * M_PI / 180.0);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeFace(ConicalSurface.GetCone(), 0., 2., 0., 2.), "ConicalSurface.brep");
Class of 3D conical surface.
Definition Geom3ConicalSurface.hpp:14

Geom3ToroidalSurface

Geom3ToroidalSurface is a toroidal surface (doughnut shape) in 3D space with a parameter domain of [0, 2π) x [0, 2π]. The toroidal surface can be created using Frame3, the large radius, and the small radius. The standard circle in the XOY plane corresponds to an iso-parameteric curve with v = 0, while the standard circle in the XOZ plane corresponds to an iso-parameteric curve with u = 0.

AMCAX::Geom3ToroidalSurface ToroidalSurface(AMCAX::Frame3(), 2.0, 1.0);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeFace(ToroidalSurface.GetTorus(), 0., 2., 0., 2.), "ToroidalSurface.brep");
Class of 3D toroidal surface.
Definition Geom3ToroidalSurface.hpp:14

Geom3BezierSurface

Geom3BezierSurface is a Bezier surface in 3D space with a parameter domain of [0, 1] x [0, 1]. The Bezier surface can be created using control points and optional weights. When creating it, make sure the number of weights matches the number of control points. If all weights are equal (e.g., all equal to 1), the rational Bezier surface degenerates into a standard Bezier surface.

poles(0, 0).SetCoord(0.0, 0.0, 0.0);
poles(0, 1).SetCoord(1.0, 0.0, 2.0);
poles(0, 2).SetCoord(2.0, 0.0, 1.0);
poles(0, 3).SetCoord(3.0, 0.0, 0.0);
poles(1, 0).SetCoord(0.0, 1.0, 1.0);
poles(1, 1).SetCoord(1.0, 1.0, 3.0);
poles(1, 2).SetCoord(2.0, 1.0, 2.0);
poles(1, 3).SetCoord(3.0, 1.0, 1.0);
poles(2, 0).SetCoord(0.0, 2.0, 1.0);
poles(2, 1).SetCoord(1.0, 2.0, 2.0);
poles(2, 2).SetCoord(2.0, 2.0, 3.0);
poles(2, 3).SetCoord(3.0, 2.0, 1.0);
poles(3, 0).SetCoord(0.0, 3.0, 0.0);
poles(3, 1).SetCoord(1.0, 3.0, 1.0);
poles(3, 2).SetCoord(2.0, 3.0, 1.0);
poles(3, 3).SetCoord(3.0, 3.0, 0.0);
AMCAX::Array2<double> weights(4, 4);
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
weights(i, j) = 1.0;
}
}
std::shared_ptr<AMCAX::Geom3BezierSurface> BezierSurface = std::make_shared<AMCAX::Geom3BezierSurface>(poles, weights);
Template class of two dimensional array.
Definition Array2.hpp:17
static constexpr double Confusion() noexcept
Get the confusion tolerance.
Definition Precision.hpp:122

Geom3BSplineSurface

Geom3BSplineSurface is a B-Spline surface in 3D space. The B-Spline surface can be created based on control points, knot vectors, knot multiplicities, and curve degrees. The following conditions must be met when creating it: The length of UKnots = the length of UMultiplicities; The length of VKnots = the length of VMultiplicities;sum(UMultiplicities) = Poles.Rows() + UDegree + 1;sum(VMultiplicities) = Poles.Cols() + VDegree + 1;The knot vectors must be monotonically increasing, and the multiplicity of each knot cannot exceed the degree of the curve.

poles2(0, 0).SetCoord(0.0, 0.0, 0.0);
poles2(0, 1).SetCoord(0.666667, 1., 0.333333);
poles2(0, 2).SetCoord(-0.666667, 0., -0.333333);
poles2(0, 3).SetCoord(0.0, 1., 0.0);
poles2(1, 0).SetCoord(0.666667, 1., 0.333333);
poles2(1, 1).SetCoord(1.44444, 2.22222, 0.777778);
poles2(1, 2).SetCoord(-1.22222, 1.22222, 0.111111);
poles2(1, 3).SetCoord(-0.666667, 2., 0.333333);
poles2(2, 0).SetCoord(0.333333, 1., -0.333333);
poles2(2, 1).SetCoord(1.11111, 0.222222, 0.111111);
poles2(2, 2).SetCoord(2.44444, 3.22222, 0.777778);
poles2(2, 3).SetCoord(1.66667, 2., 0.333333);
poles2(3, 0).SetCoord(1., 0.0, 0.0);
poles2(3, 1).SetCoord(1.66667, -1., 0.333333);
poles2(3, 2).SetCoord(1.66667, 2., 0.333333);
poles2(3, 3).SetCoord(1., 1., 0.);
std::vector<double> uknots = { 0.0, 1.0 };
std::vector<int> umults = { 4, 4 };
std::vector<double> vknots = { 0.0, 1.0 };
std::vector<int> vmults = { 4, 4 };
std::shared_ptr<AMCAX::Geom3BSplineSurface> BSplineSurface = std::make_shared<AMCAX::Geom3BSplineSurface>(poles2, uknots, vknots, umults, vmults, 3, 3);

Geom3SurfaceOfExtrusion

Geom3SurfaceOfExtrusion is an extrusion surface (stretch surface) in 3D space (infinite), which can be created based on a base curve (Geom3Curve) and extrusion direction. The u-direction is the parameter direction of the base curve, and the v-direction is the extrusion reverse. The isoparametric line v=0 corresponds to the base curve, and any u-isoparametric line is a straight line. The u parameter domain corresponds to the base curve's parameter domain, while the v parameter domain is infinite.

std::shared_ptr<AMCAX::Geom3Curve> curve = std::make_shared<AMCAX::Geom3Circle>(AMCAX::Frame3(), 1.0);
std::shared_ptr<AMCAX::Geom3SurfaceOfExtrusion> SurfaceOfExtrusion = std::make_shared<AMCAX::Geom3SurfaceOfExtrusion>(curve, AMCAX::Direction3(0.0, 0.0, 1.0));
std::shared_ptr<AMCAX::Geom3TrimmedSurface> trimex = std::make_shared<AMCAX::Geom3TrimmedSurface>(SurfaceOfExtrusion, 0., 2*M_PI, 0., 5.);

Geom3SurfaceOfRevolution

Geom3SurfaceOfRevolution is a surface of revolution in 3D space. It can be created based on a base curve (Geom3Curve) and an axis of rotation. The u parameter domain is [0, 2π), and the v parameter domain is the domain of the base curve. Each v-isoparametric line is a circle with its center on the rotation axis, and each u-isoparametric line can be generated by rotating the base curve around the axis.

AMCAX::Direction3 dir(1.0, 0.0, 0.0);
std::shared_ptr<AMCAX::Geom3Curve> curve2 = std::make_shared<AMCAX::Geom3Circle>(AMCAX::Frame3(), 1.0);
std::shared_ptr<AMCAX::Geom3TrimmedCurve> trimCurve = std::make_shared<AMCAX::Geom3TrimmedCurve>(curve2, 0.0, M_PI/4);
AMCAX::Axis3 axis(p, dir);
std::shared_ptr<AMCAX::Geom3SurfaceOfRevolution> SurfaceOfRevolution = std::make_shared<AMCAX::Geom3SurfaceOfRevolution>(trimCurve, axis);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeFace(SurfaceOfRevolution, AMCAX::Precision::Confusion()), "SurfaceOfRevolution.brep");

Geom3TrimmedSurface

Geom3TrimmedSurface is a trimmed surface in 3D space, created from an original surface with trimming parameters. You can trim in the u-direction, v-direction, or both u and v directions. To access the original surface, you can use AMCAX::Geom3TrimmedSurface::BasisSurface.

std::shared_ptr<AMCAX::Geom3CylindricalSurface> CylindricalSurface2= std::make_shared< AMCAX::Geom3CylindricalSurface>(AMCAX::Frame3(), 3.0);
std::shared_ptr<AMCAX::Geom3TrimmedSurface> TrimmedSurface = std::make_shared<AMCAX::Geom3TrimmedSurface>(CylindricalSurface2, 0., 5., false);
auto basis = TrimmedSurface->BasisSurface();

Geom3OffsetSurface

Geom3OffsetSurface is an offset surface in 3D space, which moves every point of the original surface along its normal direction by a certain distance. To access the original surface, you can use AMCAX::Geom3OffsetSurface::BasisSurface.

std::shared_ptr<AMCAX::Geom3CylindricalSurface> CylindricalSurface3 = std::make_shared< AMCAX::Geom3CylindricalSurface>(AMCAX::Frame3(), 2.0);
std::shared_ptr<AMCAX::Geom3TrimmedSurface> TrimmedSurface2 = std::make_shared<AMCAX::Geom3TrimmedSurface>(CylindricalSurface3, 0., 5., false);
AMCAX::OCCTIO::OCCTTool::Write(AMCAX::MakeFace(TrimmedSurface2, AMCAX::Precision::Confusion()), "TrimmedSurface2.brep");
std::shared_ptr<AMCAX::Geom3OffsetSurface> offsetsurface1 = std::make_shared<AMCAX::Geom3OffsetSurface>(TrimmedSurface2, 2.);
auto basis2 = offsetsurface1->BasisSurface();

To obtain the equivalent surface after offsetting, such as a sphere or cylinder, you can use AMCAX::Geom3OffsetSurface::Surface.

AMCAX::Geom3OffsetSurface offs(TrimmedSurface2, 2.);
std::shared_ptr<AMCAX::Geom3Surface> offsetsurface2 = offs.Surface();
Class of 3D offset surface.
Definition Geom3OffsetSurface.hpp:18

In fact, all the offset surfaces (plane, sphere, cylinder, cone, torus, extrusion, revolution, Bezier, BSpline) mentioned above can be represented by the original surface type. However, only equivalent surfaces of trimmed or non-trimmed planes, cylinders, cones, spheres, and tori are implemented, while the others will return a null pointer.