I have canvas with several cutom controls inherited from panel class, dynamically added to it at runtime with rendertransform=(.5,.5). But when apply translate transform (50,50) and rotate it by 100 degrees, it does not rotate on its place, it rotates in radius of 50, why?
Am I doing wrong something ?
Transformations are not commutative, you should apply the rotation before applying the translation.
Often you have a TransformGroup, then you can just change the order of its children, if this is somehow not an option because some transform is "inherited" from a parent you can nullify prior transforms using their inverse (in the case of a translation that should move the target back to the origin), then you can rotate it in place, and apply the original transform again.
The documentation is your friend, here is what can be found for TransformGroups:
In a composite transformation, the order of individual transformations is important. For example, if you first rotate, then scale, then translate, you get a different result than if you first translate, then rotate, then scale. One reason order is significant is that transformations like rotation and scaling are done with respect to the origin of the coordinate system. Scaling an object that is centered at the origin produces a different result than scaling an object that has been moved away from the origin. Similarly, rotating an object that is centered at the origin produces a different result than rotating an object that has been moved away from the origin.
If it rotates with a radius of 50, it's because your origin is wrong.
You just need to change the origin of your RotateTransform by setting the CenterX and CenterY properties both to 50 in this case.
Related
I was having the problem mentioned above and found that many of the tutorials are mentioning implementing the procedure on the centre of the canvas or world origin.
The question is how to perform that in any location successfully?
If you are familiar with blender the simple answer for you is - keep the Origins at the same place for both Centre and Orbital objects and make sure to apply the transforms.
For others-
Shift + Right-click to move the 3d Cursor to the desired location.
Create the Object that is to be Orbited or rotated.
Shape it as desired, then selecting that press Ctrl + A and press All Transforms,that will move it's origin to the world Origin, to correct that In object mode select the object and Rightclick then select Set Origin. and select the centre of mass to keep it in a visible field. (You can always edit your object in edit mode that will not destroy your array but minor modification will be required. ) (centring the origin isn't mandatory at this step, described to inform the process)
Place the 3d cursor at the point of the Orbital object from which it should face the centre. (to perform in complex object go to edit mode and select with vertex or edge or face selection and press Shift+S and select "Cursor to selected")
Having the cursor at desired point Create a cube or anything that will help to visualise the rotation. The cube will be exactly placed on the 3d cursor as well as its origin. Scale it as required. and apply all transforms as previous and reposition the origin to the 3D cursor.
Select the Orbital object and set its origin to the 3d cursor too.
If required provide some spacing to the Orbital object from the centre object (cube).
(but it will be helpful to visualize if you do that after creating the array, going to the edit mode of the orbital object)
Selecting the Orbital object assign Array modifier. Provide the desired number of objects under Count and make all axis of Relative offset 0 to get all orbital objects in the same plane. (relative offset comes pre-selected)
Tick Object Offset and with the Dropper select the Cube.
Now if the array doses strange things like the image below
It means either both of your Center and Orbital objects don't have origin At the same point (here 3d cursor) or You forgot to Apply the transforms for the objects.
Now you can rotate the cube to get the desired arrangement in circular form.
To provide the spacing from the centre object, go to the orbital object and press Tab for edit mode there selecting the original and move it along the upward axis allow you to have spacing. Because moving objects in edit mode don't affect the origin. that is still at the 3d cursor
Not only spacing you can do various formations rotating, moving the orbital object in edit mode.
Play with relative offset to get various looks.
The videos skim over setting origin and checking and re-checking transforms and origin points. This is a really important step and even following your detailed instructions it took a few tries to get it right.
This circular array modification is really tricky to get, but once learned it is a great tool for speeding up workflow.
Thanks for this
I have translate the object by applying the transform on 3DObject. It translate the objects correctly buy rotation of that object is getting disturb means in opposite direction. I want to rotate the 3DObject on its center not on viewport3d center.
Make sure you apply the translation and rotation in the correct order.
Move the Object so that its center is at the origin (0,0,0)
Rotate the Object
Translate the Object anywhere you want
If you do this using matrices, multiply the matrices in reverse order!
I'm working on a project that allows users to drawing something, and save it in the database.
Basically, the user draws on a canvas, the canvas is 5 time bigger than the screen size, and the canvas is still in the center of the screen (or the screen is in the center of the canvas).
In order to make it flexible for the canvas size (we want to change the size of the canvas in the future), we want to set the center of the canvas as the Origin Point, that is, (0, 0) is in the center of the canvas. So when the mouse clicks somewhere, the point I get is measured based on the center of the canvas.
Maybe you would say:
Canvas.RenderTransformOrigin = (.5,.5). But I'm not asking the rotating center, so it's not the solution.
Canvas.RenderTransform = TranslateTransform (Canvas.Width/2.0, Canvas.Height/2.0). But this just move all the objects on the canvas to the center.
You may also say that, why don't we just translate the MouseClick points with an offset Canvas.Width/2.0, Canvas.Height/2.0, and then translate them back when rendering. We could do that, but too much effort, because we have a lot of other operations to be implemented, so every time we have to translate back and forth.
It looks like you have thought of almost every possible approach to this problem, however, I will see if I can add just one more!
The Canvas properties, Left and Top, which dictate an elements position are attached properties. You could create your own attached properties, OffsetLeft, OffsetTop which allow you to position elements based on the origin you require. These would be simple to implement, when they are get / set, just handle their change event to set the respective Canvas attached properties.
So I have a FrameworkElement to which I apply a template that has a thumb. I calculate the angle and then I set the RenderTransfrom property equal to a RotationTranform. Once I do the rotation and want to do another rotation, the changes don't stick, that it the element returns to its initial position. How can I make the changes stick after a transformation has been applied. Any help would be appreciated. Thank you.
Do transformations affect the actual element or are they only a rendering thing? Also do they affect the bounding box of the element? I tried a layout transformation and still the same result.
You can only have one tranform at a time, but if you need multiple transfomations you can use a TransformGroup to add whatever transforms you need.
Alternatively you can use a MatrixTransform whose Matrix you can manipulate (those changes will not be reversible but as there is only one transformation in total it should have a higher performance).
What I would like to do is the following:
Change the points of the four corners of an image.
What is possible now, is to change the top left corner. But that will only move the image.
I want to transform the image by changing the corner coordinates.
The effect will be a 3d-kind transformation.
A skew transformation will not do, I want to be able to position the corners freely.
Is this possible?
I don't think you can just place corners of an image arbitarily and have it distort accordingly. It might be better if you specified the effect you are trying to acheive.
There are couple of options which may or may not suit.
Would a Matrix3DProjection serve your purpose (as well as do a lot a math for you)?
Would using the image to Fill a path or using a path to clip the image get the effect you want.