本文整理汇总了C#中Point2D.Set方法的典型用法代码示例。如果您正苦于以下问题:C# Point2D.Set方法的具体用法?C# Point2D.Set怎么用?C# Point2D.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point2D
的用法示例。
在下文中一共展示了Point2D.Set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClipPolygonToEdge2D
////////////////////////////////////////////////////////////////////////////////
// ClipPolygonToEdge2D
//
// This function clips a polygon against an edge. The portion of the polygon
// which is to the left of the edge (while going from edgeBegin to edgeEnd)
// is returned in "outPoly". Note that the clipped polygon may have more vertices
// than the input polygon. Make sure that outPolyArraySize is sufficiently large.
// Otherwise, you may get incorrect results and may be an assert (hopefully, no crash).
// Pass in the actual size of the array in "outPolyArraySize".
//
// Read Sutherland-Hidgman algorithm description in Foley & van Dam book for
// details about this.
//
///////////////////////////////////////////////////////////////////////////
public static void ClipPolygonToEdge2D( Point2D edgeBegin,
Point2D edgeEnd,
IList<Point2D> poly,
out List<Point2D> outPoly)
{
outPoly = null;
if (edgeBegin == null ||
edgeEnd == null ||
poly == null ||
poly.Count < 3)
{
return;
}
outPoly = new List<Point2D>();
int lastVertex = poly.Count - 1;
Point2D edgeRayVector = new Point2D(edgeEnd.X - edgeBegin.X, edgeEnd.Y - edgeBegin.Y);
// Note: >= 0 as opposed to <= 0 is intentional. We are
// dealing with x and z here. And in our case, z axis goes
// downward while the x axis goes rightward.
//bool bLastVertexIsToRight = TriangulationUtil.PointRelativeToLine2D(poly[lastVertex], edgeBegin, edgeEnd) >= 0;
bool bLastVertexIsToRight = TriangulationUtil.Orient2d(edgeBegin, edgeEnd, poly[lastVertex]) == Orientation.CW ? true : false;
Point2D tempRay = new Point2D(0.0, 0.0);
for (int curVertex = 0; curVertex < poly.Count; curVertex++)
{
//bool bCurVertexIsToRight = TriangulationUtil.PointRelativeToLine2D(poly[curVertex], edgeBegin, edgeEnd) >= 0;
bool bCurVertexIsToRight = TriangulationUtil.Orient2d(edgeBegin, edgeEnd, poly[curVertex]) == Orientation.CW ? true : false;
if (bCurVertexIsToRight)
{
if (bLastVertexIsToRight)
{
outPoly.Add(poly[curVertex]);
}
else
{
tempRay.Set(poly[curVertex].X - poly[lastVertex].X, poly[curVertex].Y - poly[lastVertex].Y);
Point2D ptIntersection = new Point2D(0.0, 0.0);
bool bIntersect = TriangulationUtil.RaysIntersect2D(poly[lastVertex], tempRay, edgeBegin, edgeRayVector, ref ptIntersection);
if (bIntersect)
{
outPoly.Add(ptIntersection);
outPoly.Add(poly[curVertex]);
}
}
}
else if (bLastVertexIsToRight)
{
tempRay.Set(poly[curVertex].X - poly[lastVertex].X, poly[curVertex].Y - poly[lastVertex].Y);
Point2D ptIntersection = new Point2D(0.0, 0.0);
bool bIntersect = TriangulationUtil.RaysIntersect2D(poly[lastVertex], tempRay, edgeBegin, edgeRayVector, ref ptIntersection);
if (bIntersect)
{
outPoly.Add(ptIntersection);
}
}
lastVertex = curVertex;
bLastVertexIsToRight = bCurVertexIsToRight;
}
}
示例2: PolygonsAreSame2D
/// <summary>
/// Check if the polys are similar to within a tolerance (Doesn't include reflections,
/// but allows for the points to be numbered differently, but not reversed).
/// </summary>
/// <param name="poly1"></param>
/// <param name="poly2"></param>
/// <returns></returns>
public static bool PolygonsAreSame2D(IList<Point2D> poly1, IList<Point2D> poly2)
{
int numVerts1 = poly1.Count;
int numVerts2 = poly2.Count;
if (numVerts1 != numVerts2)
{
return false;
}
const double kEpsilon = 0.01;
const double kEpsilonSq = kEpsilon * kEpsilon;
// Bounds the same to within tolerance, are there polys the same?
Point2D vdelta = new Point2D(0.0, 0.0);
for (int k = 0; k < numVerts2; ++k)
{
// Look for a match in verts2 to the first vertex in verts1
vdelta.Set(poly1[0]);
vdelta.Subtract(poly2[k]);
if (vdelta.MagnitudeSquared() < kEpsilonSq)
{
// Found match to the first point, now check the other points continuing round
// if the points don't match in the first direction we check, then it's possible
// that the polygons have a different winding order, so we check going round
// the opposite way as well
int matchedVertIndex = k;
bool bReverseSearch = false;
while (true)
{
bool bMatchFound = true;
for (int i = 1; i < numVerts1; ++i)
{
if (!bReverseSearch)
{
++k;
}
else
{
--k;
if (k < 0)
{
k = numVerts2 - 1;
}
}
vdelta.Set(poly1[i]);
vdelta.Subtract(poly2[k % numVerts2]);
if (vdelta.MagnitudeSquared() >= kEpsilonSq)
{
if (bReverseSearch)
{
// didn't find a match going in either direction, so the polygons are not the same
return false;
}
else
{
// mismatch in the first direction checked, so check the other direction.
k = matchedVertIndex;
bReverseSearch = true;
bMatchFound = false;
break;
}
}
}
if (bMatchFound)
{
return true;
}
}
}
}
return false;
}