JS-坐标对应到1080p下的转换
作者:互联网
把非1080p的坐标对应转换为1080p系坐标
例如在宽高为width * height(192*108)区域中的坐标,需要对应到1080p下:
1、当前宽高对应到1080p:
let arr1 = [[{x:1,y:2},{x:3,y:4}],[{x:5,y:6},{x:7,y:8}]]
let newArr1 = []
arr1.map((item)=>{
let arr = []
item.map((items)=>{
let a = parseInt( items.x * 1920/192)
let b = parseInt( items.y * 1080/108)
arr.push({x:a,y:b})
})
newArr1.push(arr)
})
console.log('108 --> 1080p坐标',newArr1)
两段代码的运行结果:
2、 1080p对应到当前宽高
let arr2 = [[{x:10,y:20},{x:30,y:40}],[{x:50,y:60},{x:70,y:80}]]
arr2.map((item)=>{
item.map((items)=>{
items.x= parseInt(items.x *192 / 1920)
items.y= parseInt(items.y *108 / 1080);
return items
})
return item
})
console.log('1080p --> 108坐标',arr2)
标签:items,JS,item,108,let,坐标,1080p 来源: https://blog.csdn.net/qq_42301358/article/details/116068070