Forum Replies Created
-
AuthorPosts
-
26 March 2019 at 23:20 in reply to: Rotating an object with an angular velocity and conserving collisions #13271chrissimBlocked
Hi Hugo
Yes this is definitely what I was looking for, in this case you are using the AffineMovementConstraint to perform the rotation around the x-axis?
But is it possible to rotate an object and have that object deform due to collision? Because the way I understood this method of rotating, it constrains the rotating object and will not permit deformation. Or is it not possible for the rotating object itself to undergo deformations?
Chris
19 March 2019 at 21:00 in reply to: Rotating an object with an angular velocity and conserving collisions #13231chrissimBlockedThanks for the reply Hugo
I started working on a method of creating a rotation using different rotation matrices and implementing it in a python script to utilize the animation time steps for an incremental rotation.
I can rotate an object around a specific angle as well as conserve collisions it causes in other objects. But since I am applying fixed constraints on the rotating object it is not possible for it to deform itself. I have to apply fixed constraint to the rotating object since otherwise the mesh will loose coherence and shoot away in space.
I was curious is there a way already implemented in SOFA to rotate an object and have it deform? In this case I would like the cylinder, which I am rotating to deform as well.
This is the rotation matrix I am using to rotate and object around a specific vector in space. This is done by creating a rotation matrix according to the vector that is input (compared to a unit vector) and the angle that the object should be rotated from its base. I have also included a transformation so as to move the rotation base to a specific point in space.
def createRotationMatrix(self, b, ab_angle): if (b[0] == 1 and b[1] == 0 and b[2] == 0): a_vec = np.array([0, 1, 0]) b_vec = np.array([b[2], b[1], b[0]]) else: a_vec = np.array([1, 0, 0]) b_vec = np.array([b[0], b[2], -b[1]]) cross = np.cross(a_vec, b_vec) vx = np.array([[0,-cross[2],cross[1]],[cross[2],0,-cross[0]],[-cross[1],cross[0],0]]) R = np.identity(3)*np.cos(ab_angle) + (1-np.cos(ab_angle))*np.outer(cross,cross) + np.sin(ab_angle)*vx rotMatrix = np.identity(4) rotMatrix[0:3,:-1] = R if self.transform is not None: rotMatrix = np.matmul(np.matmul(self.transform,rotMatrix), self.transform_inv) return rotMatrix
This is the animation of the object rotation I have implemented. I have setup the rotation to be performed over 500 steps and create an new rotation matrix for each new time step. This will ensure that the object that is rotating does not change in length but only gets rotated in a small angle. Through the variation of the amount of time steps the rotation speed can be adjusted and the object rotated faster or slower.
There is probably a more elegant way of doing a rotation, but this seems to perform the rotation without issue and keeps collisions with other objects intact.def onBeginAnimationStep(self, deltaTime): posX=[] posY=[] posZ=[] if (self.counter == 2): self.state += 1 steps = 500 b = np.array([1, 0, 0]) ab_angle = -math.pi/4 if (self.state <= steps): angle = self.state*(ab_angle)/steps rotMatrix = self.createRotationMatrix(b, angle) modelTransposed = np.transpose(self.modelPosition) size = modelTransposed.shape[1] modelTransposed = np.concatenate((modelTransposed, np.ones((1,size))), axis=0) modelRotated = np.matmul(rotMatrix,modelTransposed) modelRotated = np.transpose(modelRotated) print str(self.state) for i in range(size): posX.append(modelRotated[i][0]) posY.append(modelRotated[i][1]) posZ.append(modelRotated[i][2]) allPos = '' for i in range(size): allPos = allPos + str(posX[i]) + ' ' + str(posY[i]) + ' ' + str(posZ[i]) + ' ' self.model.getObject('mecha_model').findData('position').value = allPos self.counter = 0 else: self.counter += 1 return 0;
I have attached a dropbox link with the python file as well as the objects I am rotating and testing the collision with. If you have any recommendations of what could be changed to improve this rotation method I would be more than happy to try implementing that.
https://www.dropbox.com/sh/0mpjhdtaree9kel/AABnrI3i32gQaWsUzWy1AKXQa?dl=0
Chris
-
AuthorPosts