{"id":1427,"date":"2013-04-13T11:35:16","date_gmt":"2013-04-13T06:05:16","guid":{"rendered":"http:\/\/judepereira.com\/blog\/?p=1427"},"modified":"2013-04-13T11:35:16","modified_gmt":"2013-04-13T06:05:16","slug":"calculate-the-real-scale-factor-and-the-angle-of-rotation-from-an-android-matrix","status":"publish","type":"post","link":"https:\/\/judepereira.com\/blog\/calculate-the-real-scale-factor-and-the-angle-of-rotation-from-an-android-matrix\/","title":{"rendered":"Calculate the REAL scale factor and the angle of rotation from an Android Matrix"},"content":{"rendered":"<p>After performing transformations such as rotation of a bitmap about an arbitrary point, the scale is lost. Of course, this makes sense because the bitmap is rotated inside the same bounds.<\/p>\n<p>To get the real scale now, along with the most reliable degree of rotation, I had to follow this method. Hope it saves the rest of you a night or two.<\/p>\n<p>[code lang=&#8221;java&#8221;]<br \/>\nfloat[] v = new float[9];<br \/>\nmatrix.getValues(v);<br \/>\n\/\/ translation is simple<br \/>\nfloat tx = v[Matrix.MTRANS_X];<br \/>\nfloat ty = v[Matrix.MTRANS_Y];<\/p>\n<p>\/\/ calculate real scale<br \/>\nfloat scalex = values[Matrix.MSCALE_X];<br \/>\nfloat skewy = values[Matrix.MSKEW_Y];<br \/>\nfloat rScale = (float) Math.sqrt(scalex * scalex + skewy * skewy);<\/p>\n<p>\/\/ calculate the degree of rotation<br \/>\nfloat rAngle = Math.round(Math.atan2(v[Matrix.MSKEW_X], v[Matrix.MSCALE_X]) * (180 \/ Math.PI));<br \/>\n[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After performing transformations such as rotation of a bitmap about an arbitrary point, the scale is lost. Of course, this makes sense because the bitmap is rotated inside the same bounds. To get the real scale now, along with the most reliable degree of rotation, I had to follow this method. Hope it saves the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[401,52],"tags":[556,454,448,455,451,444,450,440,449,438,452,453],"class_list":["post-1427","post","type-post","status-publish","format-standard","hentry","category-android","category-code","tag-android","tag-angle-of-rotation","tag-degree","tag-degree-of-rotation","tag-factor","tag-matrix","tag-real","tag-rotate","tag-rotation","tag-scale","tag-skew","tag-transformation"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pqtyx-n1","jetpack-related-posts":[{"id":1713,"url":"https:\/\/judepereira.com\/blog\/a-letter-to-tim-cook-regarding-ios-10-with-love-for-apple\/","url_meta":{"origin":1427,"position":0},"title":"A letter to Tim Cook regarding iOS 10, with love for Apple","author":"Jude Pereira","date":"June 17, 2016","format":false,"excerpt":"Tim, iOS has always been known for it's user interface, until recently. Your new take on notifications have not only made them very loud, and unsettling, but do not flow with the entire look and feel of Apple: No Mr. Tim, no. My notifications aren't waiting for me. They're crying\u2026","rel":"","context":"In &quot;life!&quot;","block_context":{"text":"life!","link":"https:\/\/judepereira.com\/blog\/category\/living-a-wonder\/"},"img":{"alt_text":"No Mr. Tim, no. My notifications will not be waiting for me. They're crying out for my attention.","src":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screen-Shot-2016-06-17-at-08.49.59-614x1024.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screen-Shot-2016-06-17-at-08.49.59-614x1024.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/Screen-Shot-2016-06-17-at-08.49.59-614x1024.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1778,"url":"https:\/\/judepereira.com\/blog\/letstuneup-a-music-chart-with-arjit-singh-in-the-lead\/","url_meta":{"origin":1427,"position":1},"title":"LetsTuneup: A music chart with Arjit Singh in the lead","author":"Jude Pereira","date":"April 28, 2017","format":false,"excerpt":"LetsTuneup has grown tremendously, and with it, we've introduced new features too. We identified that a few of our users couldn't use the app to it's full extent because they didn't have music on their devices. We've solved that. Users can now pick their favourite artists, powered by a location\u2026","rel":"","context":"In &quot;android&quot;","block_context":{"text":"android","link":"https:\/\/judepereira.com\/blog\/category\/code\/android\/"},"img":{"alt_text":"Arjit Singh in the lead, with Eminem, Linking Park, Coldplay and Pink Floyd following close","src":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/artists.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1734,"url":"https:\/\/judepereira.com\/blog\/why-matchbox-and-how-it-connects-people-through-music\/","url_meta":{"origin":1427,"position":2},"title":"Why Matchbox, and how it connects people through music","author":"Jude Pereira","date":"January 21, 2017","format":false,"excerpt":"There's no doubt that music defines us. It influences our moods, for example, making us happy by releasing a chemical named dopamine. It can affect what we wear, what we eat, and perhaps even who we enjoy being together with. It affects\u00a0our thought process too (it's well known that ambient\u2026","rel":"","context":"In &quot;android&quot;","block_context":{"text":"android","link":"https:\/\/judepereira.com\/blog\/category\/code\/android\/"},"img":{"alt_text":"Matchbox showing the top 10 artists","src":"https:\/\/i0.wp.com\/judepereira.com\/blog\/wp-content\/uploads\/IMG_7195-300x210.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/1427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/comments?post=1427"}],"version-history":[{"count":5,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/1427\/revisions"}],"predecessor-version":[{"id":1432,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/posts\/1427\/revisions\/1432"}],"wp:attachment":[{"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/media?parent=1427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/categories?post=1427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/judepereira.com\/blog\/wp-json\/wp\/v2\/tags?post=1427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}