Vector Arithmetic and Vector Drawings
This program uses vector arithmetic to calculate vertices of a regular triangle.
Then it displays those vertices as discs. Then, it connects the vertices with lines
of different colors.
This program draws three circles with three loops, employing
slightly different computations in each one.
In all three loops, the member function .rotdg
from type vector2D rotates the vector
v.
In the first loop, the member function .add
from type point2D calculates the position of
a point on a circle, by adding the vector vr
to the circle's center point.
In the second loop, the arithmetic operator +
is used instead of the member function .add to
add a vector to a point.
In the last loop, the intermediate variable vr
is eliminated by substitution.
Arithmetic operator + can be used instead
of the memeber function .add to add points and vectors.
However, not all combinations of types are allowed.
Arithmetic operator + can add two vectors,
resulting in a new vector. It can not add two points.
Also, operator + can move a point by a vector.
In this case, the point must be a left operand of operator +
, and the vector must be a right operand. The opposite order is not allowed.
Operator - can be used in the same way as
operator +.
Uncomment the commented lines to see the error descriptions.
This program draws three half-lines, employing
slightly different computations in each one.
In all the loops, line points are drawn by the function
discp.
The vector mv represents
the difference between two line points.
In the first loop, the member function .mul
from type vector2D calculates the position of
a point on a line, by multiplying the vector mv.
In the second loop, the arithmetic operator *
is used instead of the member function .mul to
multiply the vector mv.
The third line is decorative. It is drawn with a blue-red color gradient.
Arithmetic operator * can be used instead
of the memeber function .mul to multiply vectors.
However, not all combinations of types are allowed.
Operator * can multipliy a vector by a number,
or a number by a vector. The result is a new vector. Points can not be multiplied.
Operator / can divide a vector by a number,
where the vector is a left operand and the number is a right operand.
The opposite is not allowed. Points can not be divided.
Uncomment the erroneous lines to see error descriptions.
This program combines a linear and a circular motion into a single one.
This program combines two circular motions into a single motion.
The first circular motion has an amplitude of 200, and the second one has an amplitude of 50.
This program combines two circular motions into a single motion.
In this case, both circular motions have the same amplitude equal to 150.
This program draws lines that connect two concentric circular motions.
Here is the random jumping rotating zombie program.
To slow down the jumping-around speed, change the value of variable
speedMul to 0.5, or even to 0.3.
This size of this program prevents easy analysis.
Besides that, the program employs linear interpolation,
which involves a bit of mathematics.
But, if you feel like it, with some peristence you can
analyze and understand the program.
The resulting position is linearly interpolated between positions
posStart and posEnd.
This can be easily observed while the program is running,
especially when it is slowed down.
The formula for linear interpolation between any two numbers,
for example between angles a1 and a2 is:
In this formula, t is some number between 0 and 1. When t is close to 0, the resulting angle is close to angle
a1. When t is close to 1, the resulting angle is close to angle a2.