Capsule constructor
Capsule({})
Implementation
factory Capsule({
double radiusTop = 1,
double radiusBottom = 1,
double height = 1,
int numSegments = 8,
int numHeightSegments = 4
}){
List<Vector2> ptsTop = [
Vector2(0, height*0.5+radiusTop),
];
List<Vector2> ptsBottom = [];
for(int i = 0; i < numHeightSegments-1; i++){
final theta = ((math.pi/2) / numHeightSegments) * (i + 1)+(2*math.pi+math.pi/2);
double xt = -math.cos(theta)*radiusTop;
double yt = height*0.5 + math.sin(theta)*radiusTop;
ptsTop.add(Vector2(xt, yt));
double xb = -math.cos(theta)*radiusBottom;
double yb = -height*0.5 - math.sin(theta)*radiusBottom;
ptsBottom.insert(0,Vector2(xb, yb));
}
ptsTop.add(Vector2(radiusTop, (height*0.5)));
ptsBottom.add(Vector2(0, -height*0.5-radiusBottom));
ptsBottom.insert(0,Vector2(radiusBottom, -height*0.5));
ptsTop.addAll(ptsBottom);
return Capsule.fromPoints(
radiusBottom: radiusBottom,
radiusTop: radiusTop,
height: height,
numSegments: numSegments,
points: ptsTop
);
}