math - Why translating matrix on Z axis is not the same as changing position on the Z axis by same number? -


i have mesh has origin point @ bottom. want move -132 on z axis. if change position of mesh on correct position. if translate on z axis -132, mesh off 20. why not getting same result?

the way translating matrix:

matrix = new three.matrix4().maketranslation( 0, 0, -132 ) mesh.geometry.applymatrix( matrix ); 

here image of mesh: enter image description here

and here image after translation 132. it's off 20. enter image description here

some more info: position of mesh at: 419, -830, 500

and rotation is: 0, -0.52, 0

so z coordinate @ 500; have move down -132. if move moving position down 132 on correct position. want translate matrix origin point down 132. here matrix:

"matrix": [0.8660253882408142,0,0.5,0,0,1,0,0,-0.5,0,0.8660253882408142,0,419,-830,500,1] 

update after further clarifications , chat

the whole proint 3d transformatins not commutative. means translating , rotating different rotating , translating (will produce different results). in special cases these can coincide (e.g origins @ 0,0,0 , on..), in general have different results.

furthermore there issue relative coordinates , nesting 3d objects inside other 3d objects. final (world) transform of object affected whether inside other object or not.

finally, actual mesh position (local transform) versus vertices position plays role in way mesh (and geometry) (eventualy) projected onto 2d, projection angle changes (see above).

as clarified, question shifting mesh in such way shift origin, further transformations (e.g rotations) can done respect shifted origin. standard way achieve behaviour, in 3d programing, include pivots or wrappers around mesh , position mesh relatively inside respect wrapper. apply further transformations (e.g rotations) on wrapper itself. gives effect mesh rotating respect axis (instead of center).

the way happens wrapper indeed rotates around own origin (i.e @ 0,0,0) mesh inside shifted appears rotating respect axis. common example of modelling 3d car wheel, can rotate around own axis (i.e spinning) translates rest of car. 1 adds wrapper around wheel, wrapper indeed translated rest of car, wheel rotated inside wrapper if no translation present (kind of reverse situation of need here, same difference).

you may optionaly want check mod3 pivot modifier creates custom pivots origin points/axes (ps i'm author of port). wheel modifier included in mod3 solves described above wheel problem in 3d.

to use wrapper 3d object in code this:

// create pivot wrapper var pivot = new three.object3d(); pivot.name = "pivot"; pivot.add( mesh ); scene.add( pivot );  // shift mesh inside pivot mesh.position.set(0,0,-132); // position wrapper in scene,  // position in place mesh pivot.position.set(419, -830, 500); pivot.rotation.set(0, -0.52, 0); // mesh appears rotated around z = -132 axis instead of center // because wrapper rotated around center, // center coincides shifted mesh z = -132 

a related answer here


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -