Programming」カテゴリーアーカイブ

プログラミング全般に関するカテゴリーです。

幾何学関係アルゴリズムで参考になりそうなリポジトリー

2Dの幾何学関係のアルゴリズムで参考になりそうなリポジトリー

2つの円の共有点

Algorithms/CircleCircleIntersectionPoints.js at master · williamfiset/Algorithms · GitHub
https://github.com/williamfiset/Algorithms/blob/master/com/williamfiset/algorithms/geometry/CircleCircleIntersectionPoints.js

円と直線の共有点

Algorithms/LineCircleIntersection.js at master · williamfiset/Algorithms · GitHub
https://github.com/williamfiset/Algorithms/blob/master/com/williamfiset/algorithms/geometry/LineCircleIntersection.js

2つの直線の共有点

Algorithms/Line.java at master · williamfiset/Algorithms · GitHub
https://github.com/williamfiset/Algorithms/blob/master/com/williamfiset/algorithms/geometry/Line.java

他にも線形代数やグラフ理論など数学系のコードがあるようです。

リンク

GitHub – williamfiset/Algorithms: A collection of algorithms
https://github.com/williamfiset/Algorithms

Enumerable.Range

以前、LinqのSelectを使ってPythonのmapのような操作をする方法を書きました。

そこでは、

int[] a = new int[]{ 0, 1, 2, 3, 4 };

としていましたが、new int[]の代わりにEnumerable.Rangeを使うという方法もあるそうです。

using System;
using System.Linq;
using System.Collections.Generic;

public class Example
{
  static public void Main ()
  {
    IEnumerable<int> a = Enumerable.Range(0, 5).Select(x => x * 2 + 1);
    foreach(int v in a) {
      Console.WriteLine(v);
    }
  }
}

実行結果

1
3
5
7
9

リンク

Enumerable.Range Method (Int32, Int32) (System.Linq)
https://msdn.microsoft.com/en-us/library/system.linq.enumerable.range(v=vs.110).aspx

UnityのLineRendererでInvalid AABBエラー

UnityのLineRendererを使っていて

  • Invalid worldAABB
  • Invalid localAABB
  • Invalid AABB

のようなエラーが発生する場合は、設定しているPositionsの値にNaNが含まれていることが原因の場合があるそうです。

NaNかどうかはfloat.IsNaNでチェックできるので確認してみてください。

リンク

【Unity】Assertion failed: Invalid worldAABB. Object is too large or too far away from the origin. – コガネブログ
http://baba-s.hatenablog.com/entry/2018/01/31/102700

【C#】float 型の値が正常ではない場合はデフォルト値を返す拡張メソッド – コガネブログ
http://baba-s.hatenablog.com/entry/2015/03/01/104741

Unity – Scripting API: LineRenderer
https://docs.unity3d.com/ScriptReference/LineRenderer.html