1. TOP
  2. KEYENCE
  3. KV-X/KV
  4. 計算
  5. 3D

KVKV-X

3D


2点の距離 (Distance3D)

KV
distance3DFB
KV-X
distance3DFBKVX
入力
pointA
点A [x,y,z]
pointB
点B [x,y,z]
出力
distance
2点間の距離

【例】
pointA [8, 2, 2]
pointB [2, 7, 9]

distance 10.488

【 計算式 】
\[ distance = \sqrt{(B_x-A_x)^2+(B_y-A_y)^2+(B_z-A_z)^2} \] 計算式ではA[0]を\(A_x\)、A[1]を\(A_y\)、A[2]を\(A_z\)と記述しています

3点を通る円の中心 (GetCenter3D)

KV
getCenter3DFB
KV-X
getCenter3DFBKVX
入力
pointA
点A [x,y,z]
pointB
点B [x,y,z]
pointC
点C [x,y,z]
出力
point0
中心 [x,y,z]

【例】
pointA [0, 0, 2]
pointB [1, 0, 0]
pointC [0, 1, 2]

point0 [0.5, 0.5, 1.0]

【 計算式 】
\begin{align} \overrightarrow{AB}=& \begin{pmatrix} B_x-A_x \\ B_y-A_y \\ B_z-A_z \end{pmatrix} \\ \overrightarrow{AC}=& \begin{pmatrix} C_x-A_x \\ C_y-A_y \\ C_z-A_z \end{pmatrix} \\ \overrightarrow{ABAC}=&\overrightarrow{AB}\times \overrightarrow{AC} \\ \end{align} 3元連立方程式を解きます \[ \begin{bmatrix} 2AB_x & 2AB_y & 2AB_z \\ 2AC_x & 2AC_y & 2AC_z \\ ABAC_x & ABAC_y & ABAC_z \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} B^2-A^2 \\ C^2-A^2 \\ ABAC\circ A \end{bmatrix} \] \(\times \) は外積(クロス積)、\(\circ \) はアダマール積(成分ごとの積)

X Y Z 軸で回転 (matRotateXYZ)

X軸で回転

Y軸で回転

Z軸で回転

KV
matRotateXYZFB
KV-X
dmatRotateXYZFBKVX
入力
point
回転前の座標 [x,y,z]
axis
回転軸 0=X 1=Y 2=Z
angle
回転角度
出力
out
移動後の座標 [x,y,z]

【例】
point [1.2, 0.8, 0.5]
axis 0(X軸)
angle 270.0

out [1.2, 0.5, -0.8]

【 計算式 】
X軸周り \[ out= \begin{bmatrix} 1 & 0 & 0 \\ 0 & cos{\theta} & -sin{\theta} \\ 0 & sin{\theta} & cos{\theta} \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ \end{bmatrix} \] Y軸周り \[ out= \begin{bmatrix} cos{\theta} & 0 & sin{\theta} \\ 0 & 1 & 0 \\ -sin{\theta} & 0 & cos{\theta} \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ \end{bmatrix} \] Z軸周り \[ out= \begin{bmatrix} cos{\theta} & -sin{\theta} & 0 \\ sin{\theta} & cos{\theta} & 0 \\ 0 & 0 & 0 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ \end{bmatrix} \]

オイラー角で回転 (matRotateEuler)

KV
EulerToMatrixFB
matRotateEulerFB
KV-X
EulerToMatrixFBKVX
matRotateEulerFBKVX
EulerToMatrix (オイラー角から行列に変換)
入力
eulerAngle
オイラー角 [roll, pitch, yaw]
order
回転順
(0:XYZ, 1:XZY, 2:YXZ,
3:YZX, 4:ZXY, 5:ZYX)
出力
out
回転行列
matRotateEuler (オイラー角で回転)
入力
point
回転前の座標 [x,y,z]
mat
回転行列
出力
out
移動後の座標 [x,y,z]

【例】
eulerAngle [90, 60, 120]
order 0 (XYZ)

point [2, 1, 1]

out [-0.067, -2.12, 1.23]

【 計算式 】
\[ out= \begin{bmatrix} m00 & m01 & m02 \\ m10 & m11 & m12 \\ m20 & m21 & m22 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ \end{bmatrix} \]

【 ラダー例 】

euler_prg
euler_prgKVX

クォータニオンで回転 (qtRotate)

KV
qtRotateFB
KV-X
qtRotateFBKVX
入力
vector
回転軸の方向ベクトル [x,y,z]
point
回転前の座標 [x,y,z]
angle
回転角度
出力
outPoint
移動後の座標 [x,y,z]

【例】
vector [-0.2, 1.0, 1.0]
point [1.2, 1.0, 0.5]
angle 270.0

out [0.227, -0.293, 1.598]

【 計算式 】
元のベクトル \[ Q1= \begin{bmatrix} q_w \\ q_x \\ q_y \\ q_z \\ \end{bmatrix} = \begin{bmatrix} 0 \\ x \\ y \\ z \\ \end{bmatrix} = \begin{bmatrix} 0 \\ point.x \\ point.y \\ point.z \\ \end{bmatrix} \] 回転軸(単位ベクトル) \[ T= \begin{bmatrix} vector.x \\ vector.y \\ vector.z \\ \end{bmatrix} \] 回転を表すクォータニオン \[ R= \begin{bmatrix} q_w \\ q_x \\ q_y \\ q_z \\ \end{bmatrix} = \begin{bmatrix} cos\frac{\theta}{2} \\ sin\frac{\theta}{2} T_x \\ sin\frac{\theta}{2} T_y \\ sin\frac{\theta}{2} T_z \\ \end{bmatrix} \] 回転の計算
\[ out = R \times Q1 \times \bar{R} \]

螺旋 (Spiral)


KV
SpiralFB
KV-X
SpiralFBKVX
入力
angle
回転角度
dx
1周で増加するX軸方向の距離
dz
1周で増加するZ軸方向の距離
stype
種類
出力
out
移動後の座標 [x,y,z]
【 計算式 】
\begin{align} \theta = \frac{\pi}{180} \times Angle \\ r= \frac{dx}{360} \\ h= \frac{dz}{360} \end{align} コイル \begin{align} x= r \times \cos\theta \\ y= r \times \sin\theta \\ z= h \times Angle \end{align} 等間隔 \begin{align} x= r\theta \times cos\theta \\ y= r\theta \times sin\theta \\ z = h \times Angle \end{align} 平方根 \begin{align} x= r \sqrt{\theta} \times cos\theta \\ y= r \sqrt{\theta} \times sin\theta \\ z = h \times Angle \end{align} 指数関数 \begin{align} a= 1.1 \\ x= r \times a^{\theta} \times cos\theta \\ y= r \times a^{\theta} \times sin\theta \\ z = h \times Angle \end{align}

この記事へのコメント