QgsGeometry QgsTransectAlgorithm::calcTransect( const QgsPoint &point, const double angleAtVertex, const double length, const QgsTransectAlgorithm::Side orientation, const double angle )
{
  QgsPoint pLeft; // left point of the line
  QgsPoint pRight; // right point of the line

  QgsPolyline line;

  if ( ( orientation == QgsTransectAlgorithm::Right ) || ( orientation == QgsTransectAlgorithm::Both ) )
  {
    pLeft = point.project( length, angle + 180.0 / M_PI * angleAtVertex );
    if ( orientation != QgsTransectAlgorithm::Both )
      pRight = point;
  }

  if ( ( orientation == QgsTransectAlgorithm::Left ) || ( orientation == QgsTransectAlgorithm::Both ) )
  {
    pRight = point.project( -length, angle + 180.0 / M_PI * angleAtVertex );
    if ( orientation != QgsTransectAlgorithm::Both )
      pLeft = point;
  }

  line.append( pLeft );
  line.append( pRight );

  return QgsGeometry::fromPolyline( line );
}
Exemple #2
0
void QgsRegularPolygon::setCenter( const QgsPoint &center )
{
  double azimuth = mCenter.azimuth( mFirstVertex );
  // TODO: double inclination = mCenter.inclination(mFirstVertex);
  mCenter = center;
  mFirstVertex = center.project( mRadius, azimuth );
}
Exemple #3
0
QgsRegularPolygon::QgsRegularPolygon( const QgsPoint &pt1, const QgsPoint &pt2, const int numSides )
  : mCenter( QgsPoint() )
  , mFirstVertex( QgsPoint() )
  , mNumberSides( 0 )
  , mRadius( 0.0 )
{
  if ( numSides >= 3 )
  {
    mNumberSides = numSides;

    double azimuth = pt1.azimuth( pt2 );
    QgsPoint pm = QgsGeometryUtils::midpoint( pt1, pt2 );
    double length = pt1.distance( pm );

    double angle = ( 180 - ( 360 / numSides ) ) / 2.0;
    double hypothenuse = length / cos( angle * M_PI / 180 );
    // TODO: inclination

    mCenter = pt1.project( hypothenuse, azimuth + angle );
    mFirstVertex = pt1;
    mRadius = qAbs( hypothenuse );
  }
}