如何将正方形的坐标转换为圆形的坐标? [英] How can I convert coordinates on a square to coordinates on a circle?

查看:304
本文介绍了如何将正方形的坐标转换为圆形的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款独立的视频游戏,并且一直在假设以下条件下进行操作:由于控制器上的指尖具有圆形的运动范围,因此它会返回圆形"坐标;也就是说,笛卡尔坐标限制在一个圆形区域(半径为1).实际上,坐标是正方形".例如,右上方的指尖位置注册为x = 1,y = 1.当我将笛卡尔坐标从极坐标转换为极坐标时,幅度可以超过1-这使玩家在对角线上的移动速度比在垂直或水平方向上的移动速度快.

I'm developing an indie video game, and have been operating under the assumption that because the thumbstick on my controller has a circular range of motion, it returns "circular" coordinates; that is, Cartesian coordinates constrained to a circular area (of radius 1). In fact, the coordinates are "square"; e.g., the top-right thumbstick position registers as x=1,y=1. When I convert the coordinates from Cartesian to polar, the magnitude can exceed 1 - which has the effect that the player can move faster diagonally than they can vertically or horizontally.

因此,为了清楚起见,我想记录一个模拟指尖的位置,其方向和大小在0到1之间.该指尖返回正方形平面上的坐标,因此只需将坐标转换为笛卡尔到极地是不够的.我想我需要转换坐标空间,但这正逼迫着我的猴子大脑的极限.

So, to clarify, I want to record the position of an analog thumbstick in terms of a direction and magnitude, where the magnitude is between 0 and 1. The thumbstick returns coordinates on a square plane, so simply converting the coordinates from Cartesian to polar is not sufficient. I think I need to convert the coordinate space, but that is pressing the limits of my monkey brain.

推荐答案

请参见

See Mapping a Square to a Circle. There's also a nice visualization for the mapping. You get:

xCircle = xSquare * sqrt(1 - 0.5*ySquare^2)
yCircle = ySquare * sqrt(1 - 0.5*xSquare^2)

这篇关于如何将正方形的坐标转换为圆形的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆