当前位置:网站首页>Remap function of C different interval mapping
Remap function of C different interval mapping
2022-06-12 06:05:00 【VR technology Xiaoguang】
This function is used to realize the mapping between two segmented intervals , Suppose there is A,B Definition of two segmented intervals , Given one in A Internal value , Can be found in B The percentage of the relative starting point in the .
The number of segments of the two intervals should be consistent , The first element of the array is fixed to 0, The last element is the maximum value of the last interval .
public static float remap(float[] srcmap, float[] tomap, float refval)
{
if(srcmap.Length!=tomap.Length)
{
//Debug.log(" The number of mapping intervals does not match !{0},{1}", srcmap.Length, tomap.Length);
return -1;
}
if (refval < srcmap[0]) return 0;
if (refval > srcmap[srcmap.Length - 1]) return 1;
float tomax = tomap[tomap.Length - 1];
int rank = 0;
float srcSubPercent = 0;
for(int i=0; i<srcmap.Length-1; i++)
{
if(refval>srcmap[i] && refval < srcmap[i + 1])
{
rank = i;
srcSubPercent = (refval - srcmap[i]) / (srcmap[i + 1] - srcmap[i]);
break;
}
}
float basePercent = tomap[rank] / tomax;
float subPercent = (tomap[rank + 1] - tomap[rank]) / tomax * srcSubPercent;
return basePercent + subPercent;
}
边栏推荐
- What is the lszrz protocol used at ordinary times? Talk about xmodem/ymodem/zmodem
- Lock and reentrankload
- dlib 人脸检测
- Redis persistence
- Introduction to thread pool: ThreadPoolExecutor
- MySQL notes
- Performance optimization metrics and tools
- Leetcode 第 80 场双周赛题解
- [Yu Yue education] basic reference materials of accounting of Nanjing Normal University
- cv2.fillPoly coco annotator segment坐标转化为mask图像
猜你喜欢

Project and build Publishing

Why is the union index the leftmost matching principle?

sqlite交叉编译动态库

肝了一个月的 DDD,一文带你掌握

Who is more fierce in network acceleration? New king reappeared in CDN field

Poisson disk sampling for procedural placement

Houdini terrain creation

Directx11 advanced tutorial cluster based deffered shading

Why doesn't the database use binary tree, red black tree, B tree and hash table? Instead, a b+ tree is used

Houdini script vex learning
随机推荐
C WMI query remote Win32_ Operatingsystem class
Why don't databases use hash tables?
Introduction to thread pool: ThreadPoolExecutor
基于LFFD模型目标检测自动标注生成xml文件
相机图像质量概述
为什么数据库不使用二叉树、红黑树、B树、Hash表? 而是使用了B+树
(UE4 4.27) customize globalshader
Houdini script vex learning
Project technical structure
MySQL 主从,6 分钟带你掌握
Divide a folder image into training set and test set
Project progress on February 28, 2022
The application could not be installed: INSTALL_FAILED_TEST_ONLY
User login [next]
[untitled]
Data integration framework seatunnel learning notes
数据库实验二:数据更新
Leetcode-1552. Magnetic force between two balls
Leetcode-2048. Next larger numerical balance
IO to IO multiplexing from traditional network