• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

IncrementRotation

chirayu

Well-Known Member
Hi All,


I was trying to rotate an object but only within a specific angle. I am using the Application.OnKeys code along with Activesheet.Shapes(1).IncrementRotation to rotate the object. However I do not know how to tell it to check the rotation angle & if its at min/ max then accordingly do positive/negative numbers for the rotation. I have attached the rotation angle I need. Is there a way to do this?
 

Attachments

  • rotate.xlsx
    9.3 KB · Views: 10
Hi !

You could also use Rotation property …

Thanks but unsure how I would only make it move within a specific angle. basically I'm trying to create a simulation of a stickman walking left and right so I would use arrow keys to make him move by using the onkey argument and at the same time I want him to be able to move like a person so arms going to and fro
 

The only way to know the angle value is within Rotation property !

The axis of rotation is the middle of the shape as you can check yourself
by just manually amending the rotation value via the right click …
 
@Chihiro your link is good but was confusing. I liked the rotate from top version but couldn't understand it too well. I've drawn up a sample using my own logic but obviously its rotating from center so its kinda useless. Anyway to change to top rotate?
 

Attachments

  • Sample.xlsm
    19.3 KB · Views: 7


The only way to anchor a rotate around top is like Chihiro's link,
easy as pure mathematical logic …

 
Since trigonometry function uses Radians instead of degrees. You need to convert it to radians to fine tune your angle operation.

What the link is doing is using Arctangent (Atn) to convert degree of spin/rotation.
t = a*Atn(1)/45

Where "a" signifies degrees.

Since there is no direct method to rotate at top of shape. You use trig function to adjust it.
.Top = original_Top location - .Height * (1- Cos(t))/2
.Left = original_Left location - .Height*Sin(t)/2

Depending on your operation, you may want to store original_Top & original_Left location as indicated on the link.

Only difference between top or bottom rotation is trig operation of either subtracting .Heigh*(1-Cos(t))/2 or .Height*Sin(t)/2 from original Top/Left location.
 
Looks like if I wanna use the top rotation. I'll have to relearn trigonometry. Oh well. No other choice. Thanks
 
@Chihiro I modified the code from that link but noticed something. If I run it long enough. It keeps moving up and left. doesn't go back to original position.
 

Attachments

  • SAMPLE2.xlsm
    18.1 KB · Views: 6


As explained in your MrExcel' link, after rotation
just put back source Left and Top coordinates …

 
Yep. You are storing OrigTop and OrigLeft as variable at start of the code.

If you want to revert after operation to Original position. Use those variable to set it back. The actual code will depend on when you want to set it back to original position.
 
Looks like if I wanna use the top rotation. I'll have to relearn trigonometry. Oh well. No other choice.
No ! 'Cause the Trigo is already done in the link sample procedure !
Just past code and as written : « Choose your shape number » …

Once you succeed with this sample procedure,
you can create a function from it …

And then, Sky is the limit !

RotateDemo.gif
 
Back
Top