Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9309

C# 8 で ベジェ線の計算

$
0
0

2つ以上の点からベジェ線を計算するコード。

publicstaticclassBezier{publicstaticVector3Get(floatt,paramsVector3[]points)=>Get(t,points.AsSpan());publicstaticVector3Get(floatt,ReadOnlySpan<Vector3>points)=>(points.Length,t)switch{_whent<0||t>1=>thrownewException(""),var(i,_)wheni<2=>thrownewException("Points must be >= 2"),var(i,_)wheni==2=>points[0]+t*(points[1]-points[0]),var(i,_)=>Get(t,points.Slice(0,i-1))+t*(Get(t,points.Slice(1,i-1))-Get(t,points.Slice(0,i-1))),};}

だいぶ関数型っぽいコードになってきた気がする。


Viewing all articles
Browse latest Browse all 9309