当前位置:网站首页>U3D_ Infinite Bessel curve
U3D_ Infinite Bessel curve
2022-07-07 15:52:00 【Le_ Sam】
Lua edition
local Bezier = {}
--【 Infinite Bessel curve 】
[email protected] t The corresponding percentage position of the whole line {0-1}
[email protected] node The starting point , The control points 1, The control points 2, The control points 3......, The end point
[email protected] ret Return to the corresponding point / value
function Bezier.BezierCurve(t, node)
local vecs = node
local count = #vecs
local rank = count - 1
local ret = Vector3.zero
local pts = Bezier.GetPascalTriangle(count)
local fs = {}
for i = 1,count do
local f = Bezier.GetFormula(vecs[i],rank,i,pts[i],t)
table.insert(fs,f)
end
for i = 1,#fs do
ret = ret + fs[i].Caclu()
end
return ret
end
-------------------------Private---------------------------------
function Bezier.Exponentiation(num,power)
local n = 1
if power == 0 then return n end
for i = 1,power do
n = n * num
end
return n
end
function Bezier.GetFormula(point,rank,index,ptValue,t)
local ret = {}
ret.point = point
ret.rank = rank
ret.index = index - 1
ret.ptValue = ptValue
ret.t = t
ret.Caclu = function()
local t1 = Bezier.Exponentiation((1 - ret.t),(ret.rank - ret.index))
local t2 = Bezier.Exponentiation(ret.t,ret.index)
return ret.point * t1 * t2 * ret.ptValue
end
return ret
end
function Bezier.GetPascalTriangle(n)
local ret = {}
local t = {}
for i = 1,n do
t[i] = {}
for j = 1,i do
if j == 1 or j == i then
t[i][j] = 1
else
t[i][j] = t[i - 1][j - 1] + t[i - 1][j]
end
end
end
for i = 1,n do
table.insert(ret,t[n][i])
end
t = nil
return ret
end
------------------------ Test functions ------------------------
function Bezier.TEST()
local go = GameObject()
go.name = " Test point "
go.transform.position = Vector3.zero
local go1 = GameObject()
go1.name = " Test point 1"
go1.transform.position = Vector3(-17.4,0,0)
go1.transform:SetParent(go.transform)
local go2 = GameObject()
go2.name = " Test point 2"
go2.transform.position = Vector3(-9.52,0,-3.84)
go2.transform:SetParent(go.transform)
local go3 = GameObject()
go3.name = " Test point 3"
go3.transform.position = Vector3(-2.88,0,5.94)
go3.transform:SetParent(go.transform)
local go4 = GameObject()
go4.name = " Test point 4"
go4.transform.position = Vector3(1.7,0,0)
go4.transform:SetParent(go.transform)
local go5 = GameObject()
go5.name = " Test point 5"
go5.transform.position = Vector3(9.95,0,-4.91)
go5.transform:SetParent(go.transform)
local go6 = GameObject()
go6.name = " Test point 6"
go6.transform.position = Vector3(15.38,0,5.46)
go6.transform:SetParent(go.transform)
local lineCount = 20
go:AddComponent(typeof(UnityEngine.LineRenderer))
local lr = go:GetComponent("LineRenderer")
lr.positionCount = lineCount + 1
for i = 0,lineCount do
lr:SetPosition(i,Bezier.BezierCurve(i / lineCount,go1.transform.position,
go2.transform.position,
go3.transform.position,
go4.transform.position,
go5.transform.position,
go6.transform.position))
end
end
return BezierC# edition
//N Jie Bessel
public class Bezier
{
public static Vector3 BezierCurve(float t, List<Vector3> vecs)
{
int count = vecs.Count;
int rank = count - 1;
Vector3 ret = Vector3.zero;
List<int> pts = CacluPascalTriangle(count);
List<Formula> fs = new List<Formula>();
for (int i = 0; i < count; i++)
{
Formula f = new Formula(vecs[i], rank, i, pts[i], t);
fs.Add(f);
}
for (int i = 0; i < fs.Count; i++)
{
ret += fs[i].Caclu();
}
return ret;
}
public static Vector3 BezierCurve(float t, params Vector3[] vecs)
{
int count = vecs.Length;
int rank = count - 1;
Vector3 ret = Vector3.zero;
List<int> pts = CacluPascalTriangle(count);
List<Formula> fs = new List<Formula>();
for (int i = 0; i < count; i++)
{
Formula f = new Formula(vecs[i], rank, i, pts[i], t);
fs.Add(f);
}
for (int i = 0; i < fs.Count; i++)
{
ret += fs[i].Caclu();
}
return ret;
}
public static List<int> CacluPascalTriangle(int n)
{
List<int> ret = new List<int>();
int[,] array = new int[n, n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= i; j++)
{
if (j == 0 || i == j)
{
array[i, j] = 1;
}
else
{
array[i, j] = array[i - 1, j - 1] + array[i - 1, j];
}
}
}
for (int i = 0; i < n; i++)
{
ret.Add(array[n - 1, i]);
}
return ret;
}
public class Formula
{
// spot
public Vector3 point;
// Stratum
public int rank;
// Indexes
public int index;
// Yang hui triangle
public int PTValue;
public float t;
public Formula(Vector3 point, int rank, int index, int pTValue, float t)
{
this.point = point;
this.rank = rank;
this.index = index;
this.PTValue = pTValue;
this.t = t;
}
public float Exponentiation(float num, int power)
{
float n = 1;
if (power == 0)
{
return n;
}
for (int i = 0; i < power; i++)
{
n *= num;
}
return n;
}
public Vector3 Caclu()
{
Vector3 P = Vector3.zero;
float t1 = Exponentiation((1 - t), (rank - index));
float t2 = Exponentiation(t, index);
P = PTValue * point * t1 * t2;
return P;
}
}
}
边栏推荐
- Three. JS introductory learning notes 19: how to import FBX static model
- HPDC smart base Talent Development Summit essay
- The bank needs to build the middle office capability of the intelligent customer service module to drive the upgrade of the whole scene intelligent customer service
- XMIND frame drawing tool
- Detailed explanation of Cocos creator 2.4.0 rendering process
- 神经网络c语言中的指针是怎么回事
- 【数字IC验证快速入门】18、SystemVerilog学习之基本语法5(并发线程...内含实践练习)
- Clang compile link ffmpeg FAQ
- Limit of total fields [1000] in index has been exceeded
- Getting started with webgl (2)
猜你喜欢
![[quick start of Digital IC Verification] 29. Ahb-sramc (9) (ahb-sramc svtb overview) of SystemVerilog project practice](/img/f7/03975d08912afd8daee936799e8951.png)
[quick start of Digital IC Verification] 29. Ahb-sramc (9) (ahb-sramc svtb overview) of SystemVerilog project practice

15. Using the text editing tool VIM

2022 all open source enterprise card issuing network repair short website and other bugs_ 2022 enterprise level multi merchant card issuing platform source code

星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”

LeetCode1_ Sum of two numbers

Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import

numpy---基础学习笔记

postman生成时间戳,未来时间戳

Numpy --- basic learning notes

2022第四届中国(济南)国际智慧养老产业展览会,山东老博会
随机推荐
Syntax of generator function (state machine)
How to build your own super signature system (yunxiaoduo)?
尤雨溪,来了!
Async and await
The "go to definition" in VS2010 does not respond or prompts the solution of "symbol not found"
The rebound problem of using Scrollview in cocos Creator
Use moviepy Editor clips videos and intercepts video clips in batches
How to deploy the super signature distribution platform system?
leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
[quick start of Digital IC Verification] 24. AHB sramc of SystemVerilog project practice (4) (AHB continues to deepen)
How to create Apple Developer personal account P8 certificate
[quick start of Digital IC Verification] 26. Ahb-sramc of SystemVerilog project practice (6) (basic points of APB protocol)
It's different for rich people to buy a house
Using eating in cocos Creator
[quick start of Digital IC Verification] 19. Basic grammar of SystemVerilog learning 6 (thread internal communication... Including practical exercises)
Numpy -- data cleaning
Spin animation of Cocos performance optimization
Mysql database backup script
20th anniversary of agile: a failed uprising
Mesh merging under ue4/ue5 runtime