pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <i id='T9Bzf'><tr id='T9Bzf'><dt id='T9Bzf'><q id='T9Bzf'><span id='T9Bzf'><b id='T9Bzf'><form id='T9Bzf'><ins id='T9Bzf'></ins><ul id='T9Bzf'></ul><sub id='T9Bzf'></sub></form><legend id='T9Bzf'></legend><bdo id='T9Bzf'><pre id='T9Bzf'><center id='T9Bzf'></center></pre></bdo></b><th id='T9Bzf'></th></span></q></dt></tr></i><div class="j9z7r77" id='T9Bzf'><tfoot id='T9Bzf'></tfoot><dl id='T9Bzf'><fieldset id='T9Bzf'></fieldset></dl></div>
    <tfoot id='T9Bzf'></tfoot>
    <legend id='T9Bzf'><style id='T9Bzf'><dir id='T9Bzf'><q id='T9Bzf'></q></dir></style></legend>

    <small id='T9Bzf'></small><noframes id='T9Bzf'>

          <bdo id='T9Bzf'></bdo><ul id='T9Bzf'></ul>

        html5 - 以相對坐標獲取設備方向旋轉

        html5 - Get device orientation rotation in relative coordinate(html5 - 以相對坐標獲取設備方向旋轉)
        <legend id='yTSQd'><style id='yTSQd'><dir id='yTSQd'><q id='yTSQd'></q></dir></style></legend>
            <tbody id='yTSQd'></tbody>
          <i id='yTSQd'><tr id='yTSQd'><dt id='yTSQd'><q id='yTSQd'><span id='yTSQd'><b id='yTSQd'><form id='yTSQd'><ins id='yTSQd'></ins><ul id='yTSQd'></ul><sub id='yTSQd'></sub></form><legend id='yTSQd'></legend><bdo id='yTSQd'><pre id='yTSQd'><center id='yTSQd'></center></pre></bdo></b><th id='yTSQd'></th></span></q></dt></tr></i><div class="tljtbzt" id='yTSQd'><tfoot id='yTSQd'></tfoot><dl id='yTSQd'><fieldset id='yTSQd'></fieldset></dl></div>

          1. <tfoot id='yTSQd'></tfoot>
              <bdo id='yTSQd'></bdo><ul id='yTSQd'></ul>

              <small id='yTSQd'></small><noframes id='yTSQd'>

                • 本文介紹了html5 - 以相對坐標獲取設備方向旋轉的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我試圖在兩個 deviceorientation 事件之間沿左右軸和上下軸改變方向,這些軸通常定義為電話 xy 軸(https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Orientation_and_motion_data_explained)

                  I'm trying to get the change in orientation between two deviceorientation events along the left-right axis, and top-bottom axis, those axis being usually defined as the phone x and y axis (https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Orientation_and_motion_data_explained)

                  即在瞬間 t1t2 之間,這些音素軸從 (x1, y1) 移動到 (x2, y2),想得到(angle(x2-x1), angle(y1-y2)).

                  ie between instants t1 and t2 where those phone axis move from (x1, y1) to (x2, y2), It'd like to get (angle(x2-x1), angle(y1-y2)).

                  當設備處于縱向模式(與橫向模式相反)時,這些軸似乎對應于 betagamma.但是當手機垂直(底面朝地)時,gamma值變得極不穩定,從90度跳到-90度(同時alpha跳180度)你可以在您的手機上輕松查看此處

                  When the device is in portrait mode (in opposition to landscape mode), those axis seems to correspond to the beta and gamma. However when the phone is vertical (bottom facing the ground), the gamma value becomes extremely instable, and jumps from 90 to -90 degrees (at the same occasion, the alpha jumps by 180 degrees) You can easily see that here on your phone

                  我想避免這種情況,并獲得 360 范圍內的值.這是我目前所擁有的:

                  I'd like to avoid that, and also get values in the 360 range. Here is what I have so far:

                  // assuming portrait mode
                  var beta0, gamma0;
                  window.addEventListener('deviceorientation', function(orientation) {
                    if (typeof beta0 === 'undefined') {
                      beta0 = beta;
                      gamma0 = gamma;
                    } 
                  
                    console.log('user has moved to the left by', gamma - gamma0, ' and to the top by', beta - beta0);
                  });
                  

                  當設備大部分是水平的時候可以正常工作,而當它是垂直的時候就不行了

                  That works ok when the device is mostly horizontal, and not at all when it is vertical

                  推薦答案

                  好的.先簡單解釋一下設備方向輸入:

                  All right. First, a simple explanation of the device orientation input:

                  絕對坐標系,(X, Y, Z) 使得X 為東,Y 為北,Z 已啟動.設備相對坐標系,(x, y, z) 使得x 是對的,y 是頂部,z 已啟動.然后方向角,(alpha, beta, gamma) 是描述三個簡單旋轉連續的角度,這些旋轉將 (X, Y, Z) 更改為 (x, y, z) 如下:

                  The absolute coordinate system, (X, Y, Z) is such that X is East, Y is North and Z is up. The device relative coordinate system, (x, y, z) is such that x is right, y is top and z is up. Then the orientation angles, (alpha, beta, gamma) are the angles that describe the succession of three simple rotations that change (X, Y, Z) to (x, y, z) as so:

                  • 圍繞 Z 旋轉 alpha 度,將 (X, Y, Z) 轉換為 (X', Y', Z')Z' = Z
                  • 圍繞 X' 旋轉 beta 度,將 (X', Y', Z') 轉換為 (X'', Y'', Z'')X'' = X'
                  • 圍繞 Y'' 旋轉 gamma 度,將 (X'', Y'', Z'') 轉換為 <代碼>(x, y, z) with y = Y''
                  • rotate around Z by alpha degrees, which transforms (X, Y, Z) to (X', Y', Z') with Z' = Z
                  • rotate around X' by beta degrees, which transforms (X', Y', Z') to (X'', Y'', Z'') with X'' = X'
                  • rotate around Y'' by gamma degrees, which transforms (X'', Y'', Z'') to (x, y, z) with y = Y''

                  (它們被稱為 Z-X'-Y'' 類型的固有 Tait-Bryan 角)

                  (they are called intrinsic Tait-Bryan angles of type Z-X'-Y'')

                  現在我們可以通過組合簡單的旋轉矩陣得到對應的旋轉矩陣,每個旋轉矩陣對應三個旋轉之一.

                  Now we can get the corresponding rotation matrix by composing simple rotation matrix that each correspond to one of the three rotations.

                                                   [   cC   0    sC  ] [  1    0    0   ] [  cA   -sA  0  ]
                  R(A, B, C) = Ry(C)*Rx(B)*Rz(A) = |   0    1    0   |*|  0    cB  -sB  |*[  sA   cA   0  ]
                                                   [  -sC   0    cC  ] [  0    sB   cB  ] [  0    0    1  ]
                  

                  其中 A, B, Calpha, beta, gamma 的縮寫,s, csin, cos.

                  where A, B, C are short for alpha, beta, gamma and s, c for sin, cos.

                  現在,我們感興趣的是左右(y 軸)和自上而下(x 軸)旋轉的角度在兩個位置之間的增量(x, y, z)(x', y', z') 對應于方向 (A, B, C) 和 <代碼>(A', B', C')

                  Now, we are interested in the angles of the right-left (y axis) and top-down (x axis) rotations deltas between two positions (x, y, z) and (x', y', z') that correspond to the orientations (A, B, C) and (A', B', C')

                  (x', y', z')(x, y, z) 方面的坐標由 R(A', B', C') * R(A, B, C)^-1 = R(A', B', C') * R(A, B, C)^T 因為逆是正交(旋轉)矩陣的轉置.最后,如果 z' = p*x + q*y + r*z,這些旋轉的角度是 p 圍繞左右軸和 q 圍繞自上而下的一個(這對于小角度是正確的,假設經常更新方向,否則 asin(p)asin(r) 更接近說實話)

                  The coordinates of (x', y', z') in term of (x, y, z) are given by R(A', B', C') * R(A, B, C)^-1 = R(A', B', C') * R(A, B, C)^T since the inverse is the transpose for orthogonal (rotation) matrix. Finally, if z' = p*x + q*y + r*z, the angle of those rotations are p around the right-left axis and q around the top-down one (this is true for small angles, which assume frequent orientation update, else asin(p) and asin(r) are closer from the truth)

                  所以這里有一些 javascript 來獲取旋轉矩陣:

                  So here is some javascript to get the rotation matrix:

                  /*
                   * gl-matrix is a nice library that handles rotation stuff efficiently
                   * The 3x3 matrix is a 9 element array
                   * such that indexes 0-2 correspond to the first column, 3-5 to the second column and 6-8 to the third
                   */
                  import {mat3} from 'gl-matrix';
                  
                  let _x, _y, _z;
                  let cX, cY, cZ, sX, sY, sZ;
                  /*
                   * return the rotation matrix corresponding to the orientation angles
                   */
                  const fromOrientation = function(out, alpha, beta, gamma) {
                    _z = alpha;
                    _x = beta;
                    _y = gamma;
                  
                    cX = Math.cos( _x );
                    cY = Math.cos( _y );
                    cZ = Math.cos( _z );
                    sX = Math.sin( _x );
                    sY = Math.sin( _y );
                    sZ = Math.sin( _z );
                  
                    out[0] = cZ * cY + sZ * sX * sY,    // row 1, col 1
                    out[1] = cX * sZ,                   // row 2, col 1
                    out[2] = - cZ * sY + sZ * sX * cY , // row 3, col 1
                  
                    out[3] = - cY * sZ + cZ * sX * sY,  // row 1, col 2
                    out[4] = cZ * cX,                   // row 2, col 2
                    out[5] = sZ * sY + cZ * cY * sX,    // row 3, col 2
                  
                    out[6] = cX * sY,                   // row 1, col 3
                    out[7] = - sX,                      // row 2, col 3
                    out[8] = cX * cY                    // row 3, col 3
                  };
                  

                  現在我們得到了角度增量:

                  and now we get the angular deltas:

                  const deg2rad = Math.PI / 180; // Degree-to-Radian conversion
                  let currentRotMat, previousRotMat, inverseMat, relativeRotationDelta,
                    totalRightAngularMovement=0, totalTopAngularMovement=0;
                  
                  window.addEventListener('deviceorientation', ({alpha, beta, gamma}) => {
                    // init values if necessary
                    if (!previousRotMat) {
                      previousRotMat = mat3.create();
                      currentRotMat = mat3.create();
                      relativeRotationDelta = mat3.create();
                  
                      fromOrientation(currentRotMat, alpha * deg2rad, beta * deg2rad, gamma * deg2rad);
                    }
                  
                    // save last orientation
                    mat3.copy(previousRotMat, currentRotMat);
                  
                    // get rotation in the previous orientation coordinate
                    fromOrientation(currentRotMat, alpha * deg2rad, beta * deg2rad, gamma * deg2rad);
                    mat3.transpose(inverseMat, previousRotMat); // for rotation matrix, inverse is transpose
                    mat3.multiply(relativeRotationDelta, currentRotMat, inverseMat);
                  
                    // add the angular deltas to the cummulative rotation
                    totalRightAngularMovement += Math.asin(relativeRotationDelta[6]) / deg2rad;
                    totalTopAngularMovement += Math.asin(relativeRotationDelta[7]) / deg2rad;
                  }
                  

                  最后,考慮到屏幕方向,我們必須替換

                  Finally, to account for screen orientation, we have to replace

                    _z = alpha;
                    _x = beta;
                    _y = gamma;
                  

                  通過

                  const screen = window.screen;
                  const getScreenOrientation = () => {
                    const oriented = screen && (screen.orientation || screen.mozOrientation);
                    if (oriented) switch (oriented.type || oriented) {
                      case 'landscape-primary':
                        return 90;
                      case 'landscape-secondary':
                        return -90;
                      case 'portrait-secondary':
                        return 180;
                      case 'portrait-primary':
                        return 0;
                    }
                    return window.orientation|0; // defaults to zero if orientation is unsupported
                  };
                  
                  const screenOrientation = getScreenOrientation();
                  
                  _z = alpha;
                  if (screenOrientation === 90) {
                    _x = - gamma;
                    _y = beta;
                  }
                  else if (screenOrientation === -90) {
                    _x = gamma;
                    _y = - beta;
                  }
                  else if (screenOrientation === 180) {
                    _x = - beta;
                    _y = - gamma;
                  }
                  else if (screenOrientation === 0) {
                    _x = beta;
                    _y = gamma;
                  }
                  

                  請注意,累積的左右和上下角度取決于用戶選擇的路徑,不能直接從設備方向推斷,而是必須通過移動進行跟蹤.您可以通過不同的動作到達相同的位置:

                  Note that the cumulative right-left and top-bottom angles will depend of the path chosen by the user, and cannot be infer directly from the device orientation but have to be tracked through the movement. You can arrive to the same position with different movements:

                  • 方法一:

                  • method 1:

                  • 保持手機水平并順時針旋轉 90 度.(這既不是左右旋轉也不是上下旋轉)
                  • 讓您的手機保持橫向模式,然后朝您的方向旋轉 90 度.(這既不是 90 度左右旋轉)
                  • 讓您的手機面向您并旋轉 90 度以使其向上.(這既不是 90 度左右旋轉)

                  方法二:

                  • 將手機旋轉 90 度,使其面向您并且垂直(這是 90 度上下旋轉)

                  這篇關于html5 - 以相對坐標獲取設備方向旋轉的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  document.write() overwriting the document?(document.write() 覆蓋文檔?)
                  AngularJS Error: Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https(AngularJS 錯誤:跨源請求僅支持協議方案:http、data、chrome-extension、https) - IT屋-程序員軟件開發技術分
                  IE10 and Cross-origin resource sharing (CORS) issues with Image / Canvas(IE10 和 Image/Canvas 的跨域資源共享 (CORS) 問題)
                  Importing script with type=module from local folder causes a CORS issue(從本地文件夾導入 type=module 的腳本會導致 CORS 問題)
                  HTML crossorigin attribute for img tag(img 標簽的 HTML 跨域屬性)

                  <small id='vTP8V'></small><noframes id='vTP8V'>

                  <i id='vTP8V'><tr id='vTP8V'><dt id='vTP8V'><q id='vTP8V'><span id='vTP8V'><b id='vTP8V'><form id='vTP8V'><ins id='vTP8V'></ins><ul id='vTP8V'></ul><sub id='vTP8V'></sub></form><legend id='vTP8V'></legend><bdo id='vTP8V'><pre id='vTP8V'><center id='vTP8V'></center></pre></bdo></b><th id='vTP8V'></th></span></q></dt></tr></i><div class="pf5ddzx" id='vTP8V'><tfoot id='vTP8V'></tfoot><dl id='vTP8V'><fieldset id='vTP8V'></fieldset></dl></div>
                      <tbody id='vTP8V'></tbody>

                    1. <tfoot id='vTP8V'></tfoot>
                      <legend id='vTP8V'><style id='vTP8V'><dir id='vTP8V'><q id='vTP8V'></q></dir></style></legend>
                        <bdo id='vTP8V'></bdo><ul id='vTP8V'></ul>
                            主站蜘蛛池模板: 嘉兴恒升声级计-湖南衡仪声级计-杭州爱华多功能声级计-上海邦沃仪器设备有限公司 | 东莞市超赞电子科技有限公司 全系列直插/贴片铝电解电容,电解电容,电容器 | 真空搅拌机-行星搅拌机-双行星动力混合机-广州市番禺区源创化工设备厂 | 齿轮减速马达一体式_蜗轮蜗杆减速机配电机-德国BOSERL齿轮减速电动机生产厂家 | ★店家乐|服装销售管理软件|服装店收银系统|内衣店鞋店进销存软件|连锁店管理软件|收银软件手机版|会员管理系统-手机版,云版,App | 协议书_协议合同格式模板范本大全 | 亮化工程,亮化设计,城市亮化工程,亮化资质合作,长沙亮化照明,杰奥思【官网】 | 南京种植牙医院【官方挂号】_南京治疗种植牙医院那个好_南京看种植牙哪里好_南京茀莱堡口腔医院 尼龙PA610树脂,尼龙PA612树脂,尼龙PA1010树脂,透明尼龙-谷骐科技【官网】 | 橡胶粉碎机_橡胶磨粉机_轮胎粉碎机_轮胎磨粉机-河南鼎聚重工机械制造有限公司 | 压缩空气检测_气体_水质找上海京工-服务专业、价格合理 | 南京交通事故律师-专打交通事故的南京律师 | 搪瓷搅拌器,搪玻璃搅拌器,搪玻璃冷凝器_厂家-淄博越宏化工设备 | 金蝶帐无忧|云代账软件|智能财税软件|会计代账公司专用软件 | 制冷采购电子商务平台——制冷大市场 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 宽带办理,电信宽带,移动宽带,联通宽带,电信宽带办理,移动宽带办理,联通宽带办理 | 12cr1mov无缝钢管切割-15crmog无缝钢管切割-40cr无缝钢管切割-42crmo无缝钢管切割-Q345B无缝钢管切割-45#无缝钢管切割 - 聊城宽达钢管有限公司 | 深圳法律咨询【24小时在线】深圳律师咨询免费 | 步进电机_agv电机_伺服马达-伺服轮毂电机-和利时电机 | 517瓜水果特产网|一个专注特产好物的网站| 河北码上网络科技|邯郸小程序开发|邯郸微信开发|邯郸网站建设 | 卷筒电缆-拖链电缆-特种柔性扁平电缆定制厂家「上海缆胜」 | 国产频谱分析仪-国产网络分析仪-上海坚融实业有限公司 | 智能终端_RTU_dcm_北斗星空自动化科技 | 直流电能表-充电桩电能表-导轨式电能表-智能电能表-浙江科为电气有限公司 | 空气净化器租赁,空气净化器出租,全国直租_奥司汀净化器租赁 | 电解抛光加工_不锈钢电解抛光_常州安谱金属制品有限公司 | 实体店商新零售|微赢|波后|波后合作|微赢集团 | 防爆型气象站_农业气象站_校园气象站_农业四情监测系统「山东万象环境科技有限公司」 | 企小优-企业数字化转型服务商_网络推广_网络推广公司 | 全自动端子机|刺破式端子压接机|全自动双头沾锡机|全自动插胶壳端子机-东莞市傅氏兄弟机械设备有限公司 | 临海涌泉蜜桔官网|涌泉蜜桔微商批发代理|涌泉蜜桔供应链|涌泉蜜桔一件代发 | CPSE安博会 | 无线讲解器-导游讲解器-自助讲解器-分区讲解系统 品牌生产厂家[鹰米讲解-合肥市徽马信息科技有限公司] | 岛津二手液相色谱仪,岛津10A液相,安捷伦二手液相,安捷伦1100液相-杭州森尼欧科学仪器有限公司 | 石牌坊价格石牌坊雕刻制作_石雕牌坊牌楼石栏杆厂家_山东嘉祥石雕有限公司 | 玻璃瓶厂家_酱菜瓶厂家_饮料瓶厂家_酒瓶厂家_玻璃杯厂家_徐州东明玻璃制品有限公司 | 新疆散热器,新疆暖气片,新疆电锅炉,光耀暖通公司 | 长沙网站建设制作「网站优化推广」-网页设计公司-速马科技官网 | 聚丙烯酰胺PAM-聚合氯化铝PAC-絮凝剂-河南博旭环保科技有限公司 巨野电机维修-水泵维修-巨野县飞宇机电维修有限公司 | 凝胶成像系统(wb成像系统)百科-上海嘉鹏 |