Skip to content

Instantly share code, notes, and snippets.

@jhorikawa
Created September 18, 2017 13:26
Show Gist options
  • Save jhorikawa/5df1ba30aaa4b0e3c15f25fbcf8b272c to your computer and use it in GitHub Desktop.
Save jhorikawa/5df1ba30aaa4b0e3c15f25fbcf8b272c to your computer and use it in GitHub Desktop.
Creating points on simple quadratic bezier curve for Grasshopper C# component.
private void RunScript(List<Point3d> pts, int res, ref object A)
{
List<Point3d> points = new List<Point3d>();
if(pts.Count >= 3){
for(int i = 0; i < pts.Count - 2; i++){
Point3d pt1, pt2, pt3 = new Point3d();
if(pts.Count == 3){
pt1 = pts[i];
pt2 = pts[i + 1];
pt3 = pts[i + 2];
}else{
if(i == 0){
pt1 = pts[i];
pt2 = pts[i + 1];
pt3 = pts[i + 1] + (pts[i + 2] - pts[i + 1]) * 0.5;
}else if(i == pts.Count - 3){
pt1 = pts[i] + (pts[i + 1] - pts[i]) * 0.5;
pt2 = pts[i + 1];
pt3 = pts[i + 2];
}else{
pt1 = pts[i] + (pts[i + 1] - pts[i]) * 0.5;
pt2 = pts[i + 1];
pt3 = pts[i + 1] + (pts[i + 2] - pts[i + 1]) * 0.5;
}
}
for(int n = 0; n < res; n++){
Point3d tpt1 = pt1 + (pt2 - pt1) * n / (res - 1);
Point3d tpt2 = pt2 + (pt3 - pt2) * n / (res - 1);
Point3d newPt = tpt1 + (tpt2 - tpt1) * n / (res - 1);
points.Add(newPt);
}
}
}
A = points;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment