2

I am trying to rotate a circular image in circle on touch with respect to its center.

I understand that this can be done using the OnTouchListener and onTouch() method .... by using MotionEvent.ACTION_DOWN,MotionEvent.ACTION_MOVE and MotionEvent.ACTION_UP events. But I could not find out the angle of rotation .... on touch of different point from the initial postion (i.e by taking the initial postion as 0 degree and finding each angle after rotation ...like 0,90.180,270 degrees ...etc ).

Basically My idea is to determine the actually position of the image after rotating the image for certain angle .

Please see the image below : enter image description here

Please share your idea on this problem .

Any kind of help will be highly appreciated.

Thanks

Dinesh Sharma
  • 11,533
  • 7
  • 42
  • 60
  • Personally I would start with dot product. You can calculate unit vector for touch point easily and other one is constant unit vector by definition. Then you can get the angle by using arcos cosinus. – harism Oct 26 '12 at 10:37
  • @harish thanks for the comment ..but can you explore it a bit ...and can give some reference URLs where I can get some idea on this ..as I could not get you ... !!! – Dinesh Sharma Oct 26 '12 at 10:41

3 Answers3

1

You need like this:

enter image description here

Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.sheetalkumar105:ZoomImageView-android:1.01'
}

Step 3. Add ZoomImageView in your layout

<com.impulsive.zoomimageview.ZoomImageView
  android:layout_width="match_parent"
  android:layout_height="300dp"
  android:src="@drawable/sample"
  android:scaleType="matrix"
  app:rotation="true" 
  app:scaledown="true"
  />


app:rotation="true" // Allow to rotate image in view. Default value is true.


app:scaledown="true" // Allow to ZoomOut less than container size. Default value is false. 

Full Code:

https://github.com/sheetalkumar105/ZoomImageView-android/blob/master/zoomimageview/src/main/java/com/impulsive/zoomimageview/ZoomImageView.java

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

For rotating image please see this: Android: Rotate image in imageview by an angle

The angle of touch point relatively to your base may be calculated so: arctan((x1 - x0)/(y1 - y0)) where (x0, y0) - the centre of the circle, (x1, y1) - point of touch. Be aware of situation where y1 == y0.

Community
  • 1
  • 1
Dmytro Sirenko
  • 5,003
  • 21
  • 26
  • I tired to find angle using : **Math.toDegrees(Math.atan2(x1 - x0 ,y1- y0));** but it did nt worked .. I mean give me peculiar results(angle) ... this is not exactly want I want .... angles should be like 10,30,90,180,270,360... but here I get uncertain angles ...not in a fixed pattern... Did you try this – Dinesh Sharma Oct 26 '12 at 10:38
  • @DineshSharma just truncate the specific values to the values you want, if I understand you correctly. – Dmytro Sirenko Oct 26 '12 at 10:41
  • Sorry I could not get you ... I don't want just that specific angle ..It can be any angle where users touches on circle .....!!! – Dinesh Sharma Oct 26 '12 at 10:43
  • @DineshSharma : I stuck with same issue ..Did you find anything? I want the angle which should be in range (6, 30, 36, 90...) but getting angle in 0.9065, 1.97654 etc... – Sheetal Shinde Feb 25 '22 at 05:54
-1

To find the angle of any circle the formula is right i.e. Math.toDegrees(Math.atan2(x1-x0, y0-y1))

In circle we use little bit trigonometry to calculate angle so we have to take one base which corrds (x0, y0) and other point corrds(x1, y1). Now according to our formula we need to give two parameters i.e. Base and Parpendicular. So base is x1-x0 and parpendicular is y0-y1. Please try it I think it will help you!!

Newts
  • 1,354
  • 14
  • 23