duanhuan5409 2015-06-23 19:08
浏览 48

将X,Y对转换为唯一可反转的数字

Assume you have coordinate pairs Xn,Yn how would you convert the pair into a unique reverse-able number such that for any such series Yn * Xn != Xn * Yn?

Right now I use the multiplication method to get one number; however, this causes problems because for any series like 1600,2000 2000,1600 results in the same non unique number.

Thanks.

  • 写回答

1条回答 默认 最新

  • douji6735 2015-06-24 06:40
    关注

    If you want to store the address of a pixel on a computer screen in a single number, the most efficient way would be to multiply Y by the number of horizontal pixels. With a horizontal resolution of 1280, the top row will have numbers 0 through 1279, the second row 1280 through 2559, and so on. In fact, this is how the computers themselves do it. (*)

    But if you want to use the same formula for different computer monitors, it's best to not rely on the horizontal resolution, but to use a large constant value for the multiplication factor, so that the calculations become more efficient.
    For 32 bits integers, 216 is a nice number; this allows for resolutions of up to 65536 × 65536. (Of course if you're trying to print posters, you may have to grow to a bigger scale.)

     number = (Y<<16)+X;
    

    and to reverse

     X = number&65535; Y = number>>16;
    

    (*) That's an oversimplification, but you get the idea.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用