ON_2dVector ON_Ellipse::GradientAt( 
                 const ON_2dPoint& p // coordinates in plane
                 ) const
{
  ON_2dVector g;
  if ( radius[0] != 0.0 && radius[1] != 0.0 ) {
    g.x = 2.0*p.x/(radius[0]*radius[0]);
    g.y = 2.0*p.y/(radius[1]*radius[1]);
  }
  else {
    g.Zero();
  }
  return g;
}
Beispiel #2
0
ON_2dVector ON_Circle::GradientAt( 
                 const ON_2dPoint& p // coordinates in plane
                 ) const
{
  ON_2dVector g;
  if ( radius != 0.0 ) {
    const double rr = 2.0/(radius*radius);
    g.x = rr*p.x;
    g.y = rr*p.y;
  }
  else {
    g.Zero();
  }
  return g;
}
Beispiel #3
0
unsigned
NurbsTools::getClosestPoint (const ON_2dPoint &p, const ON_2dVector &dir, const vector_vec2d &data,
			     unsigned &idxcp)
{
  if (data.empty ())
    throw std::runtime_error ("[NurbsTools::getClosestPoint(2d)] Data empty.\n");

  unsigned idx (0);
  idxcp = 0;
  double dist2 (0.0);
  double dist2cp (DBL_MAX);
  for (unsigned i = 0; i < data.size (); i++)
  {
    ON_2dVector v = (data[i] - p);
    double d2 = ON_DotProduct(v, v);

    if (d2 < dist2cp)
    {
      idxcp = i;
      dist2cp = d2;
    }

    if (NEAR_ZERO(d2, SMALL_FASTF))
      return i;

    v.Unitize();

    double d1 = ON_DotProduct(dir, v);
    if (d1 / d2 > dist2)
    {
      idx = i;
      dist2 = d1 / d2;
    }
  }
  return idx;
}
CRhinoCommand::result CCommandSampleIntepCrvOnSrf::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoGetObject go; 
  go.SetCommandPrompt( L"Select surface to draw curve on" );
  go.SetGeometryFilter( CRhinoObject::surface_object);
  go.GetObjects( 1, 1 );
  if( go.CommandResult() != CRhinoCommand::success )
    return go.CommandResult();
	 
  const CRhinoObject* obj = go.Object(0).Object();
  const ON_BrepFace* face = go.Object(0).Face();
  if( 0 == obj || 0 == face )
    return CRhinoCommand::failure;

	ON_SimpleArray<ON_2dPoint> points2d(25);

	CRhinoGetPoint gp;
  gp.Constrain( *face, obj->Attributes().m_wire_density );

  for(;;)
  {
    gp.ClearCommandOptions();

    if( points2d.Count() < 1 )
      gp.SetCommandPrompt( L"Start of curve" );
    else if( points2d.Count() == 1 )
      gp.SetCommandPrompt( L"Next point" );
    else 
      gp.SetCommandPrompt( L"Next point. Press Enter when done" );

    gp.AcceptUndo( points2d.Count() > 0 );

		gp.AcceptNothing();

    CRhinoGet::result res = gp.GetPoint();
		
    if( res == CRhinoGet::cancel)
			return CRhinoCommand::cancel;
		
    else if ( res == CRhinoGet::undo)
    {
      points2d.Remove(); // remove last point
      continue;
    }
    else if( res == CRhinoGet::point)
    {
			ON_2dPoint pt;
			if( gp.PointOnSurface(&pt.x, &pt.y) )
      {
        int count = points2d.Count();
        if( count > 0 )
        {
          ON_2dVector v = *points2d.At(count-1) - pt;
          if ( v.IsTiny())
            continue;
        }

			  points2d.Append( pt );
      }
      continue;
		}
		
  	break;
	}
	
  const int count = points2d.Count();
  if( count >  1)
  {
    // Check for closed curve
    int is_closed = 0;
    if( count > 3 )
    {
      ON_2dPoint pt = points2d[0];
      if( pt.DistanceTo(points2d[count-1]) < ON_SQRT_EPSILON )
        is_closed = 1;
    }

    double tol = context.m_doc.AbsoluteTolerance();
    ON_Curve* crv = RhinoInterpolatePointsOnSurface( *face, points2d, is_closed, tol, 1 ); 
    if( crv )
    {
      CRhinoCurveObject* crv_obj = new CRhinoCurveObject();
      crv_obj->SetCurve( crv );
      context.m_doc.AddObject( crv_obj );
      context.m_doc.Redraw();
    }

  	return CRhinoCommand::success;
  }

  return CRhinoCommand::success;
}