回転 (rotation)

 回転には,X軸を中心に回転,Y軸を中心に回転,Z軸を中心に回転,などがあり,それぞれ次の変換行列で表わされます。

        X軸を中心に回転 
        fig140.gif
        Y軸を中心に回転 
        fig141.gif
        Z軸を中心に回転 
        fig142.gif

 Nのような文字を,左下奥を原点に合わせて描き,右上前の点をPとします。この点Pの座標(1.0, 2.0, 2.0)は文字Nの大きさになっています。そして,X軸,Y軸,Z軸は,それぞれ,赤,緑,青で表現されています。

fig080.gif
        | characterN pointP xyzAxes compoundObject |
        characterN := JunOpenGL3dObject characterN.
        characterN paint: ColorValue magenta.
        characterN := characterN translatedBy: characterN boundingBox corner.
        pointP := JunOpenGL3dObject cube.
        pointP := pointP scaledBy: 0.1.
        pointP := pointP translatedBy: characterN boundingBox corner.
        xyzAxes := JunOpenGL3dObject axes.
        xyzAxes := xyzAxes scaledBy: 3.5.
        compoundObject := JunOpenGL3dCompoundObject new.
        compoundObject add: characterN.
        compoundObject add: xyzAxes.
        compoundObject add: pointP.
        compoundObject show.
        Transcript cr; show: pointP boundingBox center printString

 この文字NをX軸を中心に30度回転してみましょう。点Pの座標は(1.0, 0.732, 2.732)になります。rotateX:のメッセージを使って,Jun3dTransformationのインスタンスを作成し,文字Nに作用させます。すなわち,文字Nにtransform:のメッセージを送ります。同様に点Pも回転しておきます。

fig150.gif
        | characterN pointP aTransformation xyzAxes compoundObject |
        characterN := JunOpenGL3dObject characterN.
        characterN paint: ColorValue magenta.
        characterN := characterN translatedBy: characterN boundingBox corner.
        pointP := JunOpenGL3dObject cube.
        pointP := pointP scaledBy: 0.1.
        pointP := pointP translatedBy: characterN boundingBox corner.
        aTransformation := Jun3dTransformation rotateX: (JunAngle fromDeg: 30).
        characterN := characterN transform: aTransformation.
        pointP := pointP transform: aTransformation.
        xyzAxes := JunOpenGL3dObject axes.
        xyzAxes := xyzAxes scaledBy: 3.5.
        compoundObject := JunOpenGL3dCompoundObject new.
        compoundObject add: characterN.
        compoundObject add: xyzAxes.
        compoundObject add: pointP.
        compoundObject show.
        Transcript cr; show: pointP boundingBox center printString

 元の文字NをY軸を中心に30度回転してみましょう。rotateY:のメッセージを使います。点Pの座標は(1.866, 2.0, 1.232)になります。

fig160.gif
        | characterN pointP aTransformation xyzAxes compoundObject |
        characterN := JunOpenGL3dObject characterN.
        characterN paint: ColorValue magenta.
        characterN := characterN translatedBy: characterN boundingBox corner.
        pointP := JunOpenGL3dObject cube.
        pointP := pointP scaledBy: 0.1.
        pointP := pointP translatedBy: characterN boundingBox corner.
        aTransformation := Jun3dTransformation rotateY: (JunAngle fromDeg: 30).
        characterN := characterN transform: aTransformation.
        pointP := pointP transform: aTransformation.
        xyzAxes := JunOpenGL3dObject axes.
        xyzAxes := xyzAxes scaledBy: 3.5.
        compoundObject := JunOpenGL3dCompoundObject new.
        compoundObject add: characterN.
        compoundObject add: xyzAxes.
        compoundObject add: pointP.
        compoundObject show.
        Transcript cr; show: pointP boundingBox center printString

 元の文字NをZ軸を中心に30度回転してみましょう。rotateZ:のメッセージを使います。点Pの座標は(-0.134, 2.232, 2.0)になります。

fig170.gif
        | characterN pointP aTransformation xyzAxes compoundObject |
        characterN := JunOpenGL3dObject characterN.
        characterN paint: ColorValue magenta.
        characterN := characterN translatedBy: characterN boundingBox corner.
        pointP := JunOpenGL3dObject cube.
        pointP := pointP scaledBy: 0.1.
        pointP := pointP translatedBy: characterN boundingBox corner.
        aTransformation := Jun3dTransformation rotateZ: (JunAngle fromDeg: 30).
        characterN := characterN transform: aTransformation.
        pointP := pointP transform: aTransformation.
        xyzAxes := JunOpenGL3dObject axes.
        xyzAxes := xyzAxes scaledBy: 3.5.
        compoundObject := JunOpenGL3dCompoundObject new.
        compoundObject add: characterN.
        compoundObject add: xyzAxes.
        compoundObject add: pointP.
        compoundObject show.
        Transcript cr; show: pointP boundingBox center printString

 複数軸を中心に回転させる場合には,座標変換の順序すなわち変換行列の結合順序が重要になります。X軸,Y軸,Z軸と回転させるのと,Z軸,Y軸,X軸と回転させるのでは,結果が丸っ切り異なります。

fig180.gif
        | characterN pointP aTransformation xyzAxes compoundObject |
        characterN := JunOpenGL3dObject characterN.
        characterN paint: ColorValue magenta.
        characterN := characterN translatedBy: characterN boundingBox corner.
        pointP := JunOpenGL3dObject cube.
        pointP := pointP scaledBy: 0.1.
        pointP := pointP translatedBy: characterN boundingBox corner.
        aTransformation := ((Jun3dTransformation rotateX: (JunAngle fromDeg: 30))
                                product: (Jun3dTransformation rotateY: (JunAngle fromDeg: 30)))
                                product: (Jun3dTransformation rotateZ: (JunAngle fromDeg: 30)).
        characterN := characterN transform: aTransformation.
        pointP := pointP transform: aTransformation.
        xyzAxes := JunOpenGL3dObject axes.
        xyzAxes := xyzAxes scaledBy: 3.5.
        compoundObject := JunOpenGL3dCompoundObject new.
        compoundObject add: characterN.
        compoundObject add: xyzAxes.
        compoundObject add: pointP.
        compoundObject show.
        Transcript cr; show: pointP boundingBox center printString
fig190.gif
        | characterN pointP aTransformation xyzAxes compoundObject |
        characterN := JunOpenGL3dObject characterN.
        characterN paint: ColorValue magenta.
        characterN := characterN translatedBy: characterN boundingBox corner.
        pointP := JunOpenGL3dObject cube.
        pointP := pointP scaledBy: 0.1.
        pointP := pointP translatedBy: characterN boundingBox corner.
        aTransformation := ((Jun3dTransformation rotateZ: (JunAngle fromDeg: 30))
                                product: (Jun3dTransformation rotateY: (JunAngle fromDeg: 30)))
                                product: (Jun3dTransformation rotateX: (JunAngle fromDeg: 30)).
        characterN := characterN transform: aTransformation.
        pointP := pointP transform: aTransformation.
        xyzAxes := JunOpenGL3dObject axes.
        xyzAxes := xyzAxes scaledBy: 3.5.
        compoundObject := JunOpenGL3dCompoundObject new.
        compoundObject add: characterN.
        compoundObject add: xyzAxes.
        compoundObject add: pointP.
        compoundObject show.
        Transcript cr; show: pointP boundingBox center printString

 ある直線すなわち任意の軸に回転するには,rotate:around:のメッセージを使うと便利です。文字Nを直線((0,0,0),(1,2,2))を中心にして30度回転させてみましょう。文字Nを対角線を中心に回転させていることになりますから,点Pの座標(1.0, 2.0, 2.0)に変化はありません。

fig200.gif
        | characterN pointP aLine aTransformation xyzAxes aPolyline compoundObject |
        characterN := JunOpenGL3dObject characterN.
        characterN paint: ColorValue magenta.
        characterN := characterN translatedBy: characterN boundingBox corner.
        pointP := JunOpenGL3dObject cube.
        pointP := pointP scaledBy: 0.1.
        pointP := pointP translatedBy: characterN boundingBox corner.
        aLine := Jun3dLine from: 0 , 0 , 0 to: characterN boundingBox corner.
        aTransformation := Jun3dTransformation rotate: (JunAngle fromDeg: 30)
                                around: aLine.
        characterN := characterN transform: aTransformation.
        pointP := pointP transform: aTransformation.
        xyzAxes := JunOpenGL3dObject axes.
        xyzAxes := xyzAxes scaledBy: 3.5.
        aPolyline := JunOpenGL3dPolyline vertexes: (Array with: (aLine atT: -2)
                                        with: (aLine atT: 2)).
        aPolyline paint: ColorValue cyan.
        compoundObject := JunOpenGL3dCompoundObject new.
        compoundObject add: characterN.
        compoundObject add: xyzAxes.
        compoundObject add: pointP.
        compoundObject add: aPolyline.
        compoundObject show.
        Transcript cr; show: pointP boundingBox center printString

参照 (see also)


1997年11月06日 文責: 青木 淳