android 学习笔记之图形算法
莫名奇妙地用了叉积分。求完面积之后,再进行平均(除以y):
奇怪的是
??? pt2.fX = poly[0].fY - poly[3].fY;
??? pt2.fY = poly[3].fX - poly[0].fX;
这两行,竟然与逻辑推理出来的不一致。刚好取了个相反数。?
bool SkMatrix::setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count) { if ((unsigned)count > 4) { SkDebugf("--- SkMatrix::setPolyToPoly count out of range %d\n", count); return false; } if (0 == count) { this->reset(); return true; } if (1 == count) { this->setTranslate(dst[0].fX - src[0].fX, dst[0].fY - src[0].fY); return true; } SkPoint scale; if (!poly_to_point(&scale, src, count) || SkScalarNearlyZero(scale.fX) || SkScalarNearlyZero(scale.fY)) { return false; } static const PolyMapProc gPolyMapProcs[] = { SkMatrix::Poly2Proc, SkMatrix::Poly3Proc, SkMatrix::Poly4Proc }; PolyMapProc proc = gPolyMapProcs[count - 2]; SkMatrix tempMap, result; tempMap.setTypeMask(kUnknown_Mask); if (!proc(src, &tempMap, scale)) { return false; } if (!tempMap.invert(&result)) { return false; } if (!proc(dst, &tempMap, scale)) { return false; } if (!result.setConcat(tempMap, result)) { return false; } *this = result; return true;}
?