QList<RVector> RArc::getPointsWithDistanceToEnd(double distance, RS::From from) const { QList<RVector> ret; if (radius<RS::PointTolerance) { return ret; } double a1; double a2; RVector p; double aDist = distance / radius; if (isReversed()) { a1 = getStartAngle() - aDist; a2 = getEndAngle() + aDist; } else { a1 = getStartAngle() + aDist; a2 = getEndAngle() - aDist; } if (from==RS::FromStart || from==RS::FromAny) { p.setPolar(radius, a1); p += center; ret.append(p); } if (from==RS::FromEnd || from==RS::FromAny) { p.setPolar(radius, a2); p += center; ret.append(p); } return ret; }
bool MgArc::_setHandlePoint(int index, const Point2d& pt, float) { if (index == 1) { return setStartMidEnd(pt, getMidPoint(), getEndPoint()); } if (index == 2) { return setStartMidEnd(getStartPoint(), getMidPoint(), pt); } if (index == 3) { return setStartMidEnd(getStartPoint(), pt, getEndPoint()); } if (index == 4) { float a = (pt - getCenter()).angle2(); return setCenterRadius(getCenter(), getRadius(), a, getEndAngle() - a); } if (index == 5) { float a = (pt - getCenter()).angle2(); return setCenterRadius(getCenter(), getRadius(), getStartAngle(), a - getStartAngle()); } if (index == 6) { return setTanStartEnd(pt - getStartPoint(), getStartPoint(), getEndPoint()); } if (index == 7) { return (setTanStartEnd(getEndPoint() - pt, getEndPoint(), getStartPoint()) && _reverse()); } return setCenterStartEnd(pt, getStartPoint(), getEndPoint()); }
void Arc::draw(MyWindow* win) const { for(int r = getRadius(); r > endRadius; r--) { for(float theta = getStartAngle(); theta <= getEndAngle(); theta += 0.001) { win->putPixel(getCenter().getX() + r*cos(theta), getCenter().getY() + r*(-sin(theta)), getColor().r, getColor().g, getColor().b); //setPixel(discContainer, (center.getX() + r*cos(theta)), (center.getY() + r*(-sin(theta))), color); } } }
void RArcEntity::print(QDebug dbg) const { dbg.nospace() << "RArcEntity("; REntity::print(dbg); dbg.nospace() << ", center: " << getCenter(); dbg.nospace() << ", radius: " << getRadius(); dbg.nospace() << ", startAngle: " << RMath::rad2deg(getStartAngle()); dbg.nospace() << ", endAngle: " << RMath::rad2deg(getEndAngle()); dbg.nospace() << ", reversed: " << isReversed() << ")"; }
float MgArc::getSweepAngle() const { if (!mgIsZero(_sweepAngle)) { return _sweepAngle; } const float midAngle = (getMidPoint() - getCenter()).angle2(); const float startAngle = getStartAngle(); const float endAngle = getEndAngle(); if (mgEquals(midAngle, startAngle) && mgEquals(startAngle, endAngle)) { return endAngle - startAngle; } Tol tol(getRadius() * 1e-3f, 1e-4f); if (getStartPoint().isEqualTo(getEndPoint(), tol) && (getMidPoint() + (getStartPoint() + getEndPoint()) / 2).isEqualTo(2 * getCenter(), tol)) { return _M_2PI; } float startAngle2 = startAngle; float midAngle2 = midAngle; float endAngle2 = endAngle; // 先尝试看是否为逆时针方向:endAngle2 > midAngle2 > startAngle2 >= 0 if (startAngle2 < 0) startAngle2 += _M_2PI; while (midAngle2 < startAngle2) midAngle2 += _M_2PI; while (endAngle2 < midAngle2) endAngle2 += _M_2PI; if (fabsf(startAngle2 + endAngle2 - 2 * midAngle2) < _M_PI_6 && endAngle2 - startAngle2 < _M_2PI) { return endAngle2 - startAngle2; } // 再尝试看是否为顺时针方向:endAngle2 < midAngle2 < startAngle2 <= 0 startAngle2 = startAngle; midAngle2 = midAngle; endAngle2 = endAngle; if (startAngle2 > 0) startAngle2 -= _M_2PI; while (midAngle2 > startAngle2) midAngle2 -= _M_2PI; while (endAngle2 > midAngle2) endAngle2 -= _M_2PI; if (fabsf(startAngle2 + endAngle2 - 2 * midAngle2) < _M_PI_6) { if (endAngle2 - startAngle2 > -_M_2PI) return endAngle2 - startAngle2; return mgbase::toRange(endAngle2 - startAngle2, -_M_2PI, 0); } return endAngle - startAngle; // error }
void REllipseEntity::print(QDebug dbg) const { dbg.nospace() << "REllipseEntity("; REntity::print(dbg); dbg.nospace() << ", center: " << getCenter(); dbg.nospace() << ", majorPoint: " << getMajorPoint(); dbg.nospace() << ", ratio: " << getRatio(); dbg.nospace() << ", startAngle: " << getStartAngle(); dbg.nospace() << ", endAngle: " << getEndAngle(); dbg.nospace() << ", reversed: " << isReversed() << ")"; }
void RArc::print(QDebug dbg) const { dbg.nospace() << "RArc("; RShape::print(dbg); dbg.nospace() << ", center: " << getCenter() << ", radius: " << getRadius() << ", startAngle: " << getStartAngle() << ", endAngle: " << getEndAngle() << ", startPoint: " << getStartPoint() << ", endPoint: " << getEndPoint() << ", reversed: " << isReversed() << ")"; }
bool GuideRibbonEllipse::idealize(::pb::GuideRibbon* pOut) const { ::pb::GuideRibbon::Ellipse* idea = pOut->mutable_ellipse(); { idea->mutable_center()->set_x( getCenterX() ); idea->mutable_center()->set_y( getCenterY() ); idea->mutable_radius()->set_x( getRadiusX() ); idea->mutable_radius()->set_y( getRadiusY() ); idea->set_angle0( getBeginAngle() ); idea->set_angle1( getEndAngle() ); idea->set_direction( getDirection() ); } return true; }
float MgArc::getSweepAngle() const { const float midAngle = (getMidPoint() - getCenter()).angle2(); const float startAngle = getStartAngle(); const float endAngle = getEndAngle(); if (mgEquals(midAngle, startAngle) && mgEquals(startAngle, endAngle)) { return endAngle - startAngle; } float startAngle2 = startAngle; float midAngle2 = midAngle; float endAngle2 = endAngle; // 先尝试看是否为逆时针方向:endAngle2 > midAngle2 > startAngle2 >= 0 if (startAngle2 < 0) startAngle2 += _M_2PI; while (midAngle2 < startAngle2) midAngle2 += _M_2PI; while (endAngle2 < midAngle2) endAngle2 += _M_2PI; if (fabsf(startAngle2 + endAngle2 - 2 * midAngle2) < _M_PI_6 && endAngle2 - startAngle2 < _M_2PI) { return endAngle2 - startAngle2; } // 再尝试看是否为顺时针方向:endAngle2 < midAngle2 < startAngle2 <= 0 startAngle2 = startAngle; midAngle2 = midAngle; endAngle2 = endAngle; if (startAngle2 > 0) startAngle2 -= _M_2PI; while (midAngle2 > startAngle2) midAngle2 -= _M_2PI; while (endAngle2 > midAngle2) endAngle2 -= _M_2PI; if (fabsf(startAngle2 + endAngle2 - 2 * midAngle2) < _M_PI_6) { if (endAngle2 - startAngle2 > -_M_2PI) return endAngle2 - startAngle2; return mgToRange(endAngle2 - startAngle2, -_M_2PI, 0); } return endAngle - startAngle; // error }
RPolyline RArc::approximateWithLines(double segmentLength) { RPolyline polyline; // avoid a segment length of 0: if (segmentLength<1.0e-6) { segmentLength = 1.0e-6; } double a1 = getStartAngle(); double a2 = getEndAngle(); double aStep = segmentLength / radius; double a, cix, ciy; polyline.appendVertex(getStartPoint()); if (!reversed) { // Arc Counterclockwise: if (a1>a2-1.0e-10) { a2+=2*M_PI; } for (a=a1+aStep; a<=a2; a+=aStep) { cix = center.x + cos(a) * radius; ciy = center.y + sin(a) * radius; polyline.appendVertex(RVector(cix, ciy)); } } else { // Arc Clockwise: if (a1<a2+1.0e-10) { a2-=2*M_PI; } for (a=a1-aStep; a>=a2; a-=aStep) { cix = center.x + cos(a) * radius; ciy = center.y + sin(a) * radius; polyline.appendVertex(RVector(cix, ciy)); } } polyline.appendVertex(getEndPoint()); return polyline; }