Skip to content

Instantly share code, notes, and snippets.

@jhorikawa
Created February 28, 2023 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhorikawa/3e4065860d21838f4732b05928275059 to your computer and use it in GitHub Desktop.
Save jhorikawa/3e4065860d21838f4732b05928275059 to your computer and use it in GitHub Desktop.
C# code for Grasshopper to divide surface with angle parameter.
private void RunScript(double ang, ref object A)
{
double dang = ang * Math.PI / 180.0;
int div1 = (int) Math.Round(Math.PI / dang);
List<Point3d> points = new List<Point3d>();
for(int i = 0; i < div1; i++){
var a = i * Math.PI / (div1 - 1.0);
var cz = Math.Cos(a);
var cx = Math.Sin(a);
var dia = cx * 2.0 * Math.PI;
int div2 = (int) Math.Max(Math.Round(dia / dang), 1);
for(int n = 0; n < div2; n++){
var tx = cx * Math.Cos(n * (Math.PI * 2.0 / div2));
var ty = cx * Math.Sin(n * (Math.PI * 2.0 / div2));
var point = new Point3d(tx, ty, cz);
points.Add(point);
}
}
A = points;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment