How to rotate an image x degrees then move in that direction?

一曲冷凌霜 提交于 2019-12-06 14:37:47

问题


I'm a newbie to KineticJS and have been going through the tutorials. I want to take an image that has a 'front' and rotate it a random number of degrees and then have it move forward a number of pixels/inches in that new direction.

I was able to use this rotation tutorial to rotate my image.

I see how to use transitionTo to send an image to an x/y coordinate.

I'm having trouble tying the two together. I feel like I need randomly generate e a new x/y coordinate and then determine the degree difference between where my image is pointing and a line drawn from the center of the image to the new x/y point.

Does anyone have any tips for doing something like this? How would one draw two lines from one point and determine the angle between them?

Thanks in advance.


回答1:


You have to calculate the new coordinates thanks to the law of cosines. http://en.wikipedia.org/wiki/Law_of_cosines Once you have calculated the angle, you have to be careful because you will get an absolute angle.

Don't hesitate if you need more help. I also have to do this calculation using KineticJS.

Good luck !

The JS Math Object will be useful I guess : http://www.w3schools.com/jsref/jsref_obj_math.asp



来源:https://stackoverflow.com/questions/16365552/how-to-rotate-an-image-x-degrees-then-move-in-that-direction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!