日本語 English
KVKV-X

Vector FUN library

What Is a Vector?

A vector is a quantity with magnitude and direction.
On PLCs it is used for robot coordinates, camera coordinates, workpiece position calculation and more.

Use cases

  • Robot position calculation
  • Camera coordinate transformation
  • Workpiece orientation calculation
  • Rotation matrix calculation
  • Quaternion calculation

List

Create a 3D vector (Vector3D)

KV
vector3dFB
KV-X
vector3dFBKVX
Input
x
X axis
y
Y axis
z
Z axis
Output
outVector
Direction vector

Structures

sVectorDirection vector
xX axis
yY axis
zZ axis

Addition (vecADD)

KV
Vector addition FUN block (KV)
KV-X
Vector addition FUN block (KV-X)
Input
vector1
Vector 1
vector2
Vector 2
Output
outVector
Direction vector

[Example]
vector1 = [3, 2, 1]
vector2 = [1, 4, 2]

outVector = [4, 6, 3]

[Formula]
\[ \overrightarrow{a}+\overrightarrow{b}=(a_x+b_x,\ a_y+b_y,\ a_z+b_z) \]

Subtraction (vecSUB)

KV
Vector subtraction FUN block (KV)
KV-X
Vector subtraction FUN block (KV-X)
Input
vector1
Vector 1
vector2
Vector 2
Output
outVector
Direction vector

[Example]
vector1 = [3, 2, 1]
vector2 = [1, 4, 2]

outVector = [2, -2, -1]

[Formula]
\[ \overrightarrow{a}-\overrightarrow{b}=(a_x-b_x,\ a_y-b_y,\ a_z-b_z) \]

Scalar multiplication (vecMUL)

KV
Vector scalar multiplication FUN block (KV)
KV-X
Vector scalar multiplication FUN block (KV-X)
Input
vector
Vectors
kk
Multiplier
Output
outVector
Direction vector

[Example]
vector = [3, 2, 1]
kk = 2

outVector = [6, 4, 2]

[Formula]
\[ k\overrightarrow{a}=(ka_x,\ ka_y,\ ka_z) \]

Hadamard product (vecMultiply)

KV
Vector Hadamard product FUN block (KV)
KV-X
Vector Hadamard product FUN block (KV-X)
Input
vector1
Vector 1
vector2
Vector 2
Output
outVector
Direction vector

[Example]
vector1 = [3, 2, 1]
vector2 = [1, 4, 2]

outVector = [3, 8, 2]

[Formula]
\[ \overrightarrow{a}\odot\overrightarrow{b}=(a_xb_x,\ a_yb_y,\ a_zb_z) \]

Cross product (vecCross)

  • Generating normal vectors
  • Determining the orientation of a surface
  • Creating a right-handed coordinate system
  • Robot orientation calculation
KV
Vector cross product FUN block (KV)
KV-X
Vector cross product FUN block (KV-X)
Input
vector1
Vector 1
vector2
Vector 2
Output
outVector
Direction vector

[Example] vector1 = [3, 2, 1]
vector2 = [1, 4, 2]

outVector = [0, -5, 10]

[Formula]
\[ \overrightarrow{a} \times \overrightarrow{b}= \begin{pmatrix} a_yb_z-a_zb_y \\ a_zb_x-a_xb_z \\ a_xb_y-a_yb_x \end{pmatrix} \]

Comparison (vecEQ)

Returns TRUE if all elements match exactly.

KV
Vector comparison FUN block (KV)
KV-X
Vector comparison FUN block (KV-X)
Input
vector1
Vector 1
vector2
Vector 2
[Formula]
\[ (a_x,a_y,a_z)=(b_x,b_y,b_z)=TRUE \]

Dot product (vecDot)

The dot product represents the relationship between the directions and magnitudes of vectors.
For normalized vectors, the relationship is as follows.

  • 1 → same direction
  • 0 → orthogonal
  • -1 → opposite direction
KV
Vector dot product FUN block (KV)
KV-X
Vector dot product FUN block (KV-X)
Input
vector1
Vector 1
vector2
Vector 2
Output
result
Result

[Example]
vector1 = [3, 2, 1]
vector2 = [1, 4, 2]

result = 13

[Formula]
\[ result = a_xb_x+a_yb_y+a_zb_z \]

Norm (vecNorm)

KV
Vector norm FUN block (KV)
KV-X
Vector norm FUN block (KV-X)
Input
vector
Vectors
Output
result
Result

[Example]
vector1 = [3, 2, 1]

result = 3.742

[Formula]
\[ result = \sqrt{a_x^2+a_y^2+a_z^2} \] Unit vector \[ \hat{a} = \frac{\vec a}{|\vec a|} \]

Related pages

Download

keisanKVXLib.kufb (library only)

* Operation on the KV-X was verified with the simulator


Comments