Created
July 13, 2022 07:06
-
-
Save lightjiao/82b27115d3006d4854354fd5cff158e9 to your computer and use it in GitHub Desktop.
椭圆网格映射
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// 椭圆网格映射 | |
/// </summary> | |
/// <remarks> | |
/// 将二维矢量作为移动的输入时,输入的矢量范围是一个正方形,显然正方形的斜角比边要长 | |
/// 如果直接将这个二维矢量作为移动的输入的话,会导致斜角的移动速度更快 | |
/// 采用这个函数将矢量的值域从正方形限制为圆形 | |
/// 而圆的半径是固定的,斜方向的移动速度不会更快 | |
/// 论文地址: https://arxiv.org/ftp/arxiv/papers/1509/1509.06344.pdf 第5页 elliptical grid mapping | |
/// </remarks> | |
private static Vector2 SquareToCircle(Vector2 input) | |
{ | |
var output = Vector2.zero; | |
output.x = input.x * Mathf.Sqrt(1 - (input.y * input.y) / 2.0f); | |
output.y = input.y * Mathf.Sqrt(1 - (input.x * input.x) / 2.0f); | |
return output; | |
} | |
private static Vector3 SquareToCircle(Vector3 input) | |
{ | |
var output = SquareToCircle(new Vector2(input.x, input.z)); | |
return new Vector3(output.x, input.y, output.y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment