当前位置:网站首页>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;
}
}
}
边栏推荐
- After UE4 is packaged, mesh has no material problem
- Please supervise the 2022 plan
- nodejs package. JSON version number ^ and~
- Three. JS introductory learning notes 04: external model import - no material obj model
- Three. JS introductory learning notes 11:three JS group composite object
- 强化实时数据管理,英方软件助力医保平台安全建设
- Jacobo code coverage
- [quick start of Digital IC Verification] 25. AHB sramc of SystemVerilog project practice (5) (AHB key review, key points refining)
- The "go to definition" in VS2010 does not respond or prompts the solution of "symbol not found"
- Do not use memset to clear floating-point numbers
猜你喜欢

Three. JS introductory learning notes 07: external model import -c4d to JSON file for web pages -fbx import
![[quick start of Digital IC Verification] 25. AHB sramc of SystemVerilog project practice (5) (AHB key review, key points refining)](/img/78/29eb8581e9a8fb4c6c7e1e35ad7adc.png)
[quick start of Digital IC Verification] 25. AHB sramc of SystemVerilog project practice (5) (AHB key review, key points refining)

强化实时数据管理,英方软件助力医保平台安全建设

Actually changed from 408 to self proposition! 211 North China Electric Power University (Beijing)

JS array foreach source code parsing

Mesh merging under ue4/ue5 runtime

LeetCode1_ Sum of two numbers

HPDC smart base Talent Development Summit essay

Use of SVN

Gd32 F3 pin mapping problem SW interface cannot be burned
随机推荐
A JS script can be directly put into the browser to perform operations
How to create Apple Developer personal account P8 certificate
Asynchronous application of generator function
山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
Cut ffmpeg as needed, and use emscripten to compile and run
Getting started with webgl (3)
Cocos makes Scrollview to realize the effect of zooming in the middle and zooming out on both sides
./ Functions of configure, make and make install
Vertex shader to slice shader procedure, varying variable
Numpy -- epidemic data analysis case
Numpy --- basic learning notes
webgl_ Enter the three-dimensional world (2)
Three. JS introductory learning notes 13: animation learning
How to build your own super signature system (yunxiaoduo)?
招标公告:2022年云南联通gbase数据库维保公开比选项目(第二次)比选公告
Three. JS introductory learning notes 04: external model import - no material obj model
Wireless sensor networks -- ZigBee and 6LoWPAN
Super simple and fully automated generation super signature system (cloud Xiaoduo minclouds.com cloud service instance), free application in-house test app distribution and hosting platform, maintenan
What is Base64?
Numpy -- data cleaning