Unity环境下的常用数值静态引用

news/2024/7/8 2:16:02

1、三角函数

using UnityEngine;

public class TriFun
{
	static float[] _Sin32s;
	public static float[] Sin32s
	{
		get
		{
			if (_Sin32s == null || _Sin32s.Length == 0)
			{
				_Sin32s = new float[32];
				float angleDeta = Mathf.PI / 16;
				_Sin32s[0] = 0;
				_Sin32s[8] = 1;
				_Sin32s[16] = 0;
				_Sin32s[24] = -1;
				for (int i = 1; i < 8; i++)
				{
					_Sin32s[i] = Mathf.Sin(angleDeta * i);
				}
				for (int i = 9; i < 16; i++)
				{
					_Sin32s[i] = _Sin32s[16 - i];
				}
				for (int i = 18; i < 24; i++)
				{
					_Sin32s[i] = -_Sin32s[i - 16];
				}
				for (int i = 25; i < 32; i++)
				{
					_Sin32s[i] = -_Sin32s[i - 16];
				}
			}
			return _Sin32s;
		}
	}

	static float[] _Cos32s;
	public static float[] Cos32s
	{
		get
		{
			if (_Cos32s == null || _Cos32s.Length == 0)
			{
				_Cos32s = new float[32];
				for (int i = 0; i < 32; i++)
				{
					int iSin = i + 8;
					iSin %= 32;
					_Cos32s[i] = Sin32s[iSin];
				}
			}
			return _Cos32s;
		}
	}

	static float[] _Sin16s;
	public static float[] Sin16s
	{
		get
		{
			if (_Sin16s == null || _Sin16s.Length == 0)
			{
				_Sin16s = new float[16];
				for (int i = 0; i < 16; i++)
				{
					_Sin16s[i] = Sin32s[i * 2];
				}
			}
			return _Sin16s;
		}
	}

	static float[] _Cos16s;
	public static float[] Cos16s
	{
		get
		{
			if (_Cos16s == null || _Cos16s.Length == 0)
			{
				_Cos16s = new float[16];
				for (int i = 0; i < 16; i++)
				{
					_Cos16s[i] = Cos32s[i * 2];
				}
			}
			return _Cos16s;
		}
	}

	static float[] _Sin8s;
	public static float[] Sin8s
	{
		get
		{
			if (_Sin8s == null || _Sin8s.Length == 0)
			{
				_Sin8s = new float[8];
				for (int i = 0; i < 8; i++)
				{
					_Sin8s[i] = Sin32s[i * 4];
				}
			}
			return _Sin8s;
		}
	}

	static float[] _Cos8s;
	public static float[] Cos8s
	{
		get
		{
			if (_Cos8s == null || _Cos8s.Length == 0)
			{
				_Cos8s = new float[8];
				for (int i = 0; i < 8; i++)
				{
					_Cos8s[i] = _Cos32s[i * 4];
				}
			}
			return _Cos8s;
		}
	}
}


http://lihuaxi.xjx100.cn/news/1007401.html

相关文章

NeRF代码学习

学习nerf_pytorch项目代码&#xff0c;以及pytorch_lighting形式代码&#xff0c; 首先需要读取数据&#xff0c;将数据输入神经网络进行训练&#xff08;包括生成编码、生成光线、计算密度颜色、体渲染步骤&#xff09;&#xff0c;将数据输出 1、数据集读取 代码中给出的样…

【MySQL数据库原理】MySQL Community安装与配置

目录 1、介绍、安装与配置数据库2、操作MySQL数据库3、MySQL数据库原理1、介绍、安装与配置数据库 下载安装包:https://download.csdn.net/download/weixin_41194129/87672588 MySQL Installer - Community 是一个用于安装、配置和管理 MySQL 服务器的官方工具。以下是使用 …

VSCode+PyQt之Python界面编写

环境配置 1、python3.9 2、安装库 pip install PyQt5 pip install PyQt5-tools3、选择python解释器 4、在VSCode里下载并安装PYQT Integration 5、配置pyqt integration 5.1 将下面改为&#xff1a;D:\ProgramFiles\Python39\Scripts\pyuic5.exe 5.2 将下面的改为&#xff…

IEEE754单精度浮点数与十进制相互转化

什么是IEEE754单精度浮点数 IEEE 754单精度浮点数格式使用32位二进制表示&#xff0c;其中1位用于符号位&#xff0c;8位用于指数&#xff0c;23位用于尾数。 以下是IEEE 754单精度浮点数的详细格式&#xff1a; SExpFrac18 bits23 bits 其中&#xff0c;S表示符号位&#x…

食堂总是拥挤不堪?解决用餐拥挤,教你一招

随着近几年科技的快速发展&#xff0c;行业里出现了很多新的名词&#xff0c;比如智慧社区、智慧旅游、智慧建筑&#xff0c;那么智慧食堂是什么呢&#xff1f;它又是如何实现全自助、全智能消费&#xff1f; 在先进的智能技术以及市场需求带动下&#xff0c;智慧食堂经历了由传…

【案例教程】大气颗粒物PMF源解析实践技术

颗粒物污染不仅对气候和环境有重要影响&#xff0c;而且对人体健康有严重损害&#xff0c;尤其在一些重污染天气&#xff0c;如灰霾和沙尘暴等。为了高效、精准地治理区域大气颗粒物污染&#xff0c;首先需要了解颗粒物的来源。因此&#xff0c;颗粒物源解析成为目前解决大气颗…

关于工商详细信息 API,你想了解的都在这里了

概述 工商详细信息 API 是一种基于云计算和数据挖掘技术的 API&#xff0c;旨在帮助用户快速获取公司的详细信息。通过使用这个 API&#xff0c;用户可以输入公司的名称或注册号&#xff0c;获取公司的详细信息&#xff0c;例如公司名称、法定代表人、注册资本、注册地址、经营…

CK-GW208-EC与汇川中型PLC配置走EtherCAT通讯手册

晨控CK-GW208-EC与汇川中型PLC配置走EtherCAT通讯手册 CK-GW208-EC这款产品是晨控智能一款工业级 IO-LINK 主站网关&#xff0c;支持 EtherCat 工业协议。可通过以太网接口&#xff0c;对 IO-LINK 从站设备进行控制。 CK-GW208-EC 是一款支持标准工业 Ethercat协议的 IO-LINK…