开发者

How to draw a bitmap that moves in specific path(Arc) in android?

开发者 https://www.devze.com 2023-04-06 08:13 出处:网络
I am trying to create a custom component.I have a bitmap image as marker and it has to travel in an arc direction.The position of the marker is located using the user\'s touch.

I am trying to create a custom component.I have a bitmap image as marker and it has to travel in an arc direction.The position of the marker is located using the user's touch. Even if the user try to drag the marker outside the arc,it should not be possible.

Now using Canvas in onDraw i have drawn an arc and marker Bitmap imag开发者_如何转开发e.But don't know how to make the bitmap to follow only that arc.


You need to write a function that finds a point on your arc that has the least distance to the point where user touched. That point on your arc is the place where you want to draw your image.

Now, that calculation very much depends on how you represent your arc as a mathematical function. And that is a subject of "Analytic Geometry"

But a less accurate and simpler way would be(if the sliding doesn't need to be smooth), if you choose some sample points on your arc and use only those points to calculate this distance, and finally you choose the one with the least distance. The more points you choose the smoother it will "slide".

0

精彩评论

暂无评论...
验证码 换一张
取 消