Basic usage of ACGE Library

Source: Internet
Author: User

The following example shows the most basic functions and operations for points, vectors, and arrays, and these examples use three-dimensional objects, but most functions and operations apply to two-dimensional objects.
For points and vectors, the default constructor initializes all coordinates to 0. They can also initialize individual coordinates at the time of creation, as follows:

Acgepoint3d P1 (2.0,5.0,-7.5), P2, p3 (1.0,2.0,3.0);
Acgevector3d v1 (3.0,4.0,5.0), V2 (0.0,1.0,-1.0), V3;

Point and Vector classes also provide +, + = 、-、-= operation. With these operations, we can use them just like an internal variable type such as int and double. The following example is the addition and subtraction of points and vectors:

P2 = p1 + v1; P2 is the P1 and the V1 and
P1 + = V1; Add the V1 to P1.
P3-= v1; Subtract v1 from P3
V3 = v1 + v2; V3 is the V1 and the V2 and
V1 + = v2; Add the V2 to V1.
V3 = V1-v2; Set V3 to V1 and v2

There are no addition operations at two points, but one point can be converted to a vector, and then it can be added to another point:

P1 + = P2.asvector ();

The following example shows how to get a vector in the opposite direction:

v2 =-V1; Set V2 is the inverse vector of the V1
V1.negate (); This operation is equivalent to V1 =-V1

The following example shows different ways to scale a vector:

V1 *= 2.0; The length of the V1 is magnified twice times
V3 = v1/2.0; The length of the V3 is half the length of v1.
V1.normalize (); Make v1 into a unit vector

Points and Vector classes also have some functions for distance or length:

Double len = V2.length (); Length of V2
Len = P1.distanceto (p2); Distance from P1 to P2

The function below is useful for finding the angle between the two three-dimensional vectors, which returns the angle between V1 and V2, which is rotated counterclockwise around the V3 axis, and V3 is assumed to be perpendicular to the plane determined by V1 and V2:

Angle = V1.angleto (V2,V3);

The following functions return Boolean values (True or FALSE), which are generally used in the IF statement:

if (V1.iszerolength ())
if (V1.isparallelto (v2))
if (V1.isperpendicularto (v2))

Basic vector manipulation functions for vector classes:

Len = V1.dotproduct (v2);
V3 = V1.crossproduct (v2);

The default constructor for a distance array Initializes an array of units from the matrix:

Acgematrix3d mat1, MAT2, MAT3;

The following operation rotates the P3 around the line determined by P1 and V1 90 degrees:

Mat1.settorotation (kpi/2.0, v1, p1);
P3 = mat1 * P2;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.