コード例 #1
0
ファイル: opennurbs_polyline.cpp プロジェクト: ckvk/opennurbs
bool ON_Polyline::CreateStarPolygon(
    const ON_Circle& circle,
    double other_radius,
    int side_count
)
{
    bool rc = ( circle.IsValid() && side_count >= 3 && other_radius >= 0.0 )
              ? true
              : false;
    if ( rc )
    {
        SetCapacity(2*side_count+1);
        SetCount(2*side_count+1);
        double half_a = ON_PI/side_count;
        int i;
        ON_Circle other_circle = circle;
        other_circle.radius = other_radius;
        for ( i = 0; i < side_count; i++ )
        {
            m_a[i*2]   = circle.PointAt(half_a*2*i);
            m_a[i*2+1] = other_circle.PointAt(half_a*(1+2*i));
        }
        m_a[side_count*2] = m_a[0];
    }
    else
        Destroy();
    return rc;
}
コード例 #2
0
ファイル: opennurbs_polyline.cpp プロジェクト: ckvk/opennurbs
bool ON_Polyline::CreateInscribedPolygon(
    const ON_Circle& circle,
    int side_count
)
{
    bool rc = ( circle.IsValid() && side_count >= 3 ) ? true : false;
    if ( rc )
    {
        SetCapacity(side_count+1);
        SetCount(side_count+1);
        double a = 2.0*ON_PI/side_count;
        int i;
        for ( i = 0; i < side_count; i++ )
        {
            m_a[i] = circle.PointAt(a*i);
        }
        m_a[side_count] = m_a[0];
    }
    else
        Destroy();
    return rc;
}
コード例 #3
0
ファイル: opennurbs_polyline.cpp プロジェクト: ckvk/opennurbs
bool ON_Polyline::CreateCircumscribedPolygon(
    const ON_Circle& circle,
    int side_count
)
{
    bool rc = ( circle.IsValid() && side_count >= 3 ) ? true : false;
    if ( rc )
    {
        SetCapacity(side_count+1);
        SetCount(side_count+1);
        double half_a = ON_PI/side_count;
        int i;
        ON_Circle c = circle;
        c.radius = circle.radius/cos(half_a);
        for ( i = 0; i < side_count; i++ )
        {
            m_a[i] = c.PointAt(half_a*(1+2*i));
        }
        m_a[side_count] = m_a[0];
    }
    else
        Destroy();
    return rc;
}
コード例 #4
0
ファイル: opennurbs_intersect.cpp プロジェクト: jl2/ONView
int ON_Intersect(
      const ON_Line& line, 
      const ON_Arc& arc,
      double* line_t0,
      ON_3dPoint& arc_point0,
      double* line_t1,
      ON_3dPoint& arc_point1
      )
{
  ON_Circle c = arc;
  ON_3dPoint p[2];
  double t[2], a[2], s;
  ON_BOOL32 b[2] = {false,false};
  int i, xcnt = ON_Intersect( line, c, &t[0], p[0], &t[1], p[1] );
  if ( xcnt > 0 )
  {
    // make sure points are on the arc;
    ON_Interval arc_domain = arc.DomainRadians();
    for ( i = 0; i < xcnt; i++ )
    {
      b[i] = c.ClosestPointTo(p[i], &a[i]);
      if ( b[i] )
      {
        s = arc_domain.NormalizedParameterAt(a[i]);
        if ( s < 0.0 )
        {
          if ( s >= -ON_SQRT_EPSILON )
          {
            a[i] = arc_domain[0];
            p[i] = c.PointAt(a[i]);
            b[i] = line.ClosestPointTo( p[i], &t[i] );
          }
          else
            b[i] = false;
        }
        else if ( s > 1.0 )
        {
          if ( s <= 1.0+ON_SQRT_EPSILON )
          {
            a[i] = arc_domain[1];
            p[i] = c.PointAt(a[i]);
            b[i] = line.ClosestPointTo( p[i], &t[i] );
          }
          else
            b[i] = false;
        }
      }
    }
    if ( !b[0] && !b[1] )
      xcnt = 0;

    if ( xcnt == 2 )
    {
      if ( !b[1] )
        xcnt = 1;
      if ( !b[0] )
      {
        xcnt = 1;
        b[0] = b[1];
        t[0] = t[1];
        a[0] = a[1];
        p[0] = p[1];
        b[1] = 0;
      }
      if ( xcnt == 2 && t[0] == t[1] )
      {
        xcnt = 1;
        b[1] = 0;
        ON_3dPoint q = line.PointAt(t[0]);
        if ( p[0].DistanceTo(q) > p[1].DistanceTo(q) )
        {
          a[0] = a[1];
          t[0] = t[1];
          p[0] = p[1];
        }
      }
    }
    if  ( xcnt == 1 && !b[0] )
      xcnt = 0;
    if ( xcnt >= 1 )
    {
      if ( line_t0 )
        *line_t0 = t[0];
      arc_point0 = p[0];
    }
    if ( xcnt == 2 )
    {
      if ( line_t1 )
        *line_t1 = t[1];
      arc_point1 = p[1];
    }
  }
  return xcnt;
}