本文整理汇总了C#中Polygons.Offset方法的典型用法代码示例。如果您正苦于以下问题:C# Polygons.Offset方法的具体用法?C# Polygons.Offset怎么用?C# Polygons.Offset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygons
的用法示例。
在下文中一共展示了Polygons.Offset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateLinePaths
public static void GenerateLinePaths(Polygons polygonToInfill, ref Polygons infillLinesToPrint, int lineSpacing, int infillExtendIntoPerimeter_um, double rotation, long rotationOffset = 0)
{
if (polygonToInfill.Count > 0)
{
Polygons outlines = polygonToInfill.Offset(infillExtendIntoPerimeter_um);
if (outlines.Count > 0)
{
PointMatrix matrix = new PointMatrix(-(rotation + 90)); // we are rotating the part so we rotate by the negative so the lines go the way we expect
outlines.ApplyMatrix(matrix);
Aabb boundary = new Aabb(outlines);
boundary.min.X = ((boundary.min.X / lineSpacing) - 1) * lineSpacing - rotationOffset;
int xLineCount = (int)((boundary.max.X - boundary.min.X + (lineSpacing - 1)) / lineSpacing);
Polygons unclipedPatern = new Polygons();
long firstX = boundary.min.X / lineSpacing * lineSpacing;
for (int lineIndex = 0; lineIndex < xLineCount; lineIndex++)
{
Polygon line = new Polygon();
line.Add(new IntPoint(firstX + lineIndex * lineSpacing, boundary.min.Y));
line.Add(new IntPoint(firstX + lineIndex * lineSpacing, boundary.max.Y));
unclipedPatern.Add(line);
}
PolyTree ret = new PolyTree();
Clipper clipper = new Clipper();
clipper.AddPaths(unclipedPatern, PolyType.ptSubject, false);
clipper.AddPaths(outlines, PolyType.ptClip, true);
clipper.Execute(ClipType.ctIntersection, ret, PolyFillType.pftPositive, PolyFillType.pftEvenOdd);
Polygons newSegments = Clipper.OpenPathsFromPolyTree(ret);
PointMatrix inversematrix = new PointMatrix((rotation + 90));
newSegments.ApplyMatrix(inversematrix);
infillLinesToPrint.AddRange(newSegments);
}
}
}
示例2: GenerateConcentricInfill
public static void GenerateConcentricInfill(ConfigSettings config, Polygons partOutline, ref Polygons fillPolygons, long extrusionWidthOverride_um = 0)
{
if (extrusionWidthOverride_um == 0)
{
extrusionWidthOverride_um = config.extrusionWidth_um;
}
Polygons outlineCopy = new Polygons(partOutline);
foreach (Polygon outline in outlineCopy)
{
if (outline.Count > 0)
{
outline.Add(outline[0]);
}
}
int linespacing_um = (int)(extrusionWidthOverride_um / (config.infillPercent / 100));
while (outlineCopy.Count > 0)
{
for (int outlineIndex = 0; outlineIndex < outlineCopy.Count; outlineIndex++)
{
Polygon r = outlineCopy[outlineIndex];
fillPolygons.Add(r);
}
outlineCopy = outlineCopy.Offset(-linespacing_um);
foreach (Polygon outline in outlineCopy)
{
if (outline.Count > 0)
{
outline.Add(outline[0]);
}
}
}
}
示例3: GenerateSkirt
public void GenerateSkirt(int distance, int extrusionWidth_um, int numberOfLoops, int minLength, int initialLayerHeight, ConfigSettings config)
{
LayerDataStorage storage = this;
bool externalOnly = (distance > 0);
for (int skirtLoop = 0; skirtLoop < numberOfLoops; skirtLoop++)
{
int offsetDistance = distance + extrusionWidth_um * skirtLoop + extrusionWidth_um / 2;
Polygons skirtPolygons = new Polygons(storage.wipeTower.Offset(offsetDistance));
for (int extrudeIndex = 0; extrudeIndex < storage.Extruders.Count; extrudeIndex++)
{
if (config.continuousSpiralOuterPerimeter && extrudeIndex > 0)
{
continue;
}
if (storage.Extruders[extrudeIndex].Layers.Count < 1)
{
continue;
}
SliceLayer layer = storage.Extruders[extrudeIndex].Layers[0];
for (int partIndex = 0; partIndex < layer.Islands.Count; partIndex++)
{
if (config.continuousSpiralOuterPerimeter && partIndex > 0)
{
continue;
}
if (externalOnly)
{
Polygons p = new Polygons();
p.Add(layer.Islands[partIndex].IslandOutline[0]);
//p.Add(IntPointHelper.CreateConvexHull(layer.parts[partIndex].outline[0]));
skirtPolygons = skirtPolygons.CreateUnion(p.Offset(offsetDistance));
}
else
{
skirtPolygons = skirtPolygons.CreateUnion(layer.Islands[partIndex].IslandOutline.Offset(offsetDistance));
}
}
}
if (storage.support != null)
{
skirtPolygons = skirtPolygons.CreateUnion(storage.support.GetBedOutlines().Offset(offsetDistance));
}
//Remove small inner skirt holes. Holes have a negative area, remove anything smaller then 100x extrusion "area"
for (int n = 0; n < skirtPolygons.Count; n++)
{
double area = skirtPolygons[n].Area();
if (area < 0 && area > -extrusionWidth_um * extrusionWidth_um * 100)
{
skirtPolygons.RemoveAt(n--);
}
}
storage.skirt.AddAll(skirtPolygons);
int lenght = (int)storage.skirt.PolygonLength();
if (skirtLoop + 1 >= numberOfLoops && lenght > 0 && lenght < minLength)
{
// add more loops for as long as we have not extruded enough length
numberOfLoops++;
}
}
}
示例4: GenerateHexLinePaths
public static void GenerateHexLinePaths(Polygons in_outline, ref Polygons result, int lineSpacing, int infillExtendIntoPerimeter_um, double rotationDegrees, int layerIndex)
{
int extraRotationAngle = 0;
if (in_outline.Count > 0)
{
Polygons outlines = in_outline.Offset(infillExtendIntoPerimeter_um);
if (outlines.Count > 0)
{
int perIncrementOffset = (int)(lineSpacing * Math.Sqrt(3) / 2 + .5);
PointMatrix matrix = new PointMatrix(-(rotationDegrees + extraRotationAngle)); // we are rotating the part so we rotate by the negative so the lines go the way we expect
outlines.ApplyMatrix(matrix);
Aabb boundary = new Aabb(outlines);
boundary.min.X = ((boundary.min.X / lineSpacing) - 1) * lineSpacing;
boundary.min.Y = ((boundary.min.Y / perIncrementOffset) - 2) * perIncrementOffset;
boundary.max.X += lineSpacing;
boundary.max.Y += perIncrementOffset;
Polygons unclipedPatern = new Polygons();
foreach (IntPoint startPoint in StartPositionIterator(boundary, lineSpacing, layerIndex))
{
Polygon attachedLine = new Polygon();
foreach (IntPoint center in IncrementPositionIterator(startPoint, boundary, lineSpacing, layerIndex))
{
// what we are adding are the little plusses that define the points
// | top
// |
// /\ center
// left/ \ right
//
IntPoint left = center + new IntPoint(-lineSpacing / 2, -perIncrementOffset / 3);
IntPoint right = center + new IntPoint(lineSpacing / 2, -perIncrementOffset / 3);
IntPoint top = center + new IntPoint(0, perIncrementOffset * 2 / 3);
switch (layerIndex % 3)
{
case 0: // left to right
attachedLine.Add(left); attachedLine.Add(center);
attachedLine.Add(center); attachedLine.Add(right);
unclipedPatern.Add(new Polygon() { top, center });
break;
case 1: // left to top
attachedLine.Add(left); attachedLine.Add(center);
attachedLine.Add(center); attachedLine.Add(top);
unclipedPatern.Add(new Polygon() { center, right });
break;
case 2: // top to right
attachedLine.Add(top); attachedLine.Add(center);
attachedLine.Add(center); attachedLine.Add(right);
unclipedPatern.Add(new Polygon() { left, center });
break;
}
}
if (attachedLine.Count > 0)
{
unclipedPatern.Add(attachedLine);
}
}
PolyTree ret = new PolyTree();
Clipper clipper = new Clipper();
clipper.AddPaths(unclipedPatern, PolyType.ptSubject, false);
clipper.AddPaths(outlines, PolyType.ptClip, true);
clipper.Execute(ClipType.ctIntersection, ret, PolyFillType.pftPositive, PolyFillType.pftEvenOdd);
Polygons newSegments = Clipper.OpenPathsFromPolyTree(ret);
PointMatrix inversematrix = new PointMatrix((rotationDegrees + extraRotationAngle));
newSegments.ApplyMatrix(inversematrix);
result.AddRange(newSegments);
}
}
}
示例5: OverlapMultipleExtrudersSlightly
//Expand each layer a bit and then keep the extra overlapping parts that overlap with other extruders.
//This generates some overlap in dual extrusion, for better bonding in touching parts.
public static void OverlapMultipleExtrudersSlightly(List<ExtruderLayers> extruders, int overlapUm)
{
if (extruders.Count < 2 || overlapUm <= 0)
{
return;
}
for (int layerIndex = 0; layerIndex < extruders[0].Layers.Count; layerIndex++)
{
Polygons fullLayer = new Polygons();
for (int extruderIndex = 0; extruderIndex < extruders.Count; extruderIndex++)
{
SliceLayer layer1 = extruders[extruderIndex].Layers[layerIndex];
fullLayer = fullLayer.CreateUnion(layer1.AllOutlines.Offset(20));
}
fullLayer = fullLayer.Offset(-20);
for (int extruderIndex = 0; extruderIndex < extruders.Count; extruderIndex++)
{
SliceLayer layer1 = extruders[extruderIndex].Layers[layerIndex];
layer1.AllOutlines = fullLayer.CreateIntersection(layer1.AllOutlines.Offset(overlapUm / 2));
}
}
}