android - How to calculate X-axis reduction when view is rotated along Y-axis -


how find out x axis reduction when view rotated along y-axis?

im trying create folding animation using combination of rotation , translation.

i have 2 textviews sitting side-by-side each other shown xml below:

<linearlayout     android:id="@+id/colorbox"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:orientation="horizontal"     android:layout_marginbottom="10dp">      <textview         android:id="@+id/left"         android:layout_width="150dp"         android:layout_height="150dp"         android:background="@android:color/holo_blue_dark"         android:text="a"         android:textsize="100sp"/>      <textview         android:id="@+id/right"         android:layout_width="150dp"         android:layout_height="150dp"         android:background="@android:color/holo_green_dark"         android:text="b"         android:textsize="100sp" /> </linearlayout> 

the way planning achieve folding animation rotating left , right textview simultaneously while translating right textview left. achieve using code below:

left.setpivotx(0f); left.setpivoty(left.getheight()/2); right.setpivotx(right.getwidth()); right.setpivoty(right.getheight()/2);  objectanimator rotateleft; rotateleft = objectanimator.offloat(left, "rotationy", left.getrotationy(), 45.0f); objectanimator rotateright; rotateright = objectanimator.offloat(right, "rotationy", right.getrotationy(), -45.0f); objectanimator translaterightx; translaterightx = objectanimator.offloat(right, "x", right.getx()-amountofxtotranslate);  animateset = new animatorset(); animateset.play(rotateright).with(rotateleft).with(translaterightx); animateset.setduration(3000); animateset.setinterpolator(new decelerateinterpolator()); animateset.start(); 

my question here how calculate value of amountofxtotranslate?

i have tried various mathematical calculation.

method 1: based on reasoning when view rotated 90 degrees, width 0 , disappears , when view not rotated @ (0 degree rotation) width @ max. made assumption when rotated 45 degrees, width along x-axis should half of maximum width. in case, going logic, given have 2 textviews 150dp wide each, when both of them @ angle of 45 degrees, amount of space between 2 views (150/2)*2. amountofxtotranslate 150.

upon testing this, assumption proved wrong. reason, formula works sizes , fails miserably others. (eg: when both textview of width 100dp , 100dp translation, animation looks fine , there no gap between 2 views. when 150dp wide each, there gap. formula appears work widths less 150dp)

method 2: failure of method 1, decided use real mathematical approach , consider in 3 dimensional plane. using basic maths taught in high school, trigonometric functions: http://www.suitcaseofdreams.net/images/background/sincos.gif figured can calculate value of amountofxtotranslate using formula of ac = ab cos 45 (ac , ab based on image attached link). final formula calculate amount of x translate (widthoftextview * cos 45) * 2. unfortunately, after trying formula, still isnt correct , amount of x translation falls short, leaving gap between 2 views.

below images of problem , attemps: http://i41.tinypic.com/20z8d4o.png, http://i41.tinypic.com/2hmkbj4.png, http://i40.tinypic.com/k12xbq.png

so how find value of amountofxtotranslate?

the question partially related how calculate height of bottom edge when rotating plane on x-axis in 3d space? oddly reverse equation not work (method 2).

editted well, decided manual investigative work , results mind boggling. following test results have been carried out constant view height of 150dp , rotation along y-axis of 45 degrees.
result 1: when width of each view 150px, translation needed close gap between 2 views after rotation 120px
result 2: when width of each view 300px, translation needed close gap between 2 views after rotation 290px
result 3: when width of each view 450px, translation needed close gap between 2 views after rotation 490px
result 4: when width of each view 600px, translation needed close gap between 2 views after rotation 712px

i find weird when width of each view less 300, amount of translation needed less width of single view. but, when width of each view more 300, amount of translation needed bigger width of single view.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -