التحقق من وجود نقطة في قطاع الدائرة أم لا.

التحقق من وجود نقطة في قطاع الدائرة أم لا.

لدينا دائرة مركزها نقطة الأصل (0 0). كمدخل، حصلنا على زاوية البداية لقطاع الدائرة وحجم قطاع الدائرة بالنسبة المئوية. 

أمثلة: 

Input : Radius = 8 StartAngle = 0 Percentage = 12 x = 3 y = 4 Output : Point (3 4) exists in the circle sector Input : Radius = 12 Startangle = 45 Percentage = 25 x = 3 y = 4 Output : Point (3 4) does not exist in the circle sector 


 



المصدر:Wikibook.org المصدر:Wikibook.org


في هذه الصورة زاوية البداية هي 0 درجة نصف قطر r ولنفترض أن النسبة المئوية للمساحة الملونة هي 12٪ ثم نحسب زاوية النهاية كـ 360/نسبة مئوية + زاوية البداية .

لمعرفة هل توجد نقطة (x y) في قطاع دائرة (مركزها نقطة الأصل) أم لا نجد الإحداثيات القطبية لتلك النقطة ثم نمر بالخطوات التالية:

  1. تحويل x y إلى الإحداثيات القطبية باستخدام هذا 
    الزاوية = الغياب (ص/س)؛ نصف القطر = sqrt(x * y y y y y);
  2. ثم يجب أن تكون الزاوية بين StartingAngle وEndingAngle ونصف القطر بين 0 ونصف القطر.
C++
   // C++ program to check if a point lies inside a circle   // sector.   #include       using     namespace     std  ;   void     checkPoint  (  int     radius       int     x       int     y       float     percent        float     startAngle  )   {      // calculate endAngle      float     endAngle     =     360  /  percent     +     startAngle  ;      // Calculate polar co-ordinates      float     polarradius     =     sqrt  (  x  *  x  +  y  *  y  );      float     Angle     =     atan  (  y  /  x  );      // Check whether polarradius is less then radius of circle      // or not and Angle is between startAngle and endAngle      // or not      if     (  Angle  >=  startAngle     &&     Angle   <=  endAngle     &&     polarradius   <  radius  )      printf  (  'Point (%d %d) exist in the circle sector  n  '       x       y  );      else      printf  (  'Point (%d %d) does not exist in the circle sector  n  '        x       y  );   }   // Driver code   int     main  ()   {      int     radius     =     8       x     =     3       y     =     4  ;      float     percent     =     12       startAngle     =     0  ;      checkPoint  (  radius       x       y       percent       startAngle  );      return     0  ;   }   
Java
   // Java program to check if   // a point lies inside a circle   // sector.   class   GFG   {   static     void     checkPoint  (  int     radius       int     x       int     y       float     percent        float     startAngle  )   {      // calculate endAngle      float     endAngle     =     360  /  percent     +     startAngle  ;          // Calculate polar co-ordinates      double     polarradius     =     Math  .  sqrt  (  x  *  x  +  y  *  y  );      double     Angle     =     Math  .  atan  (  y  /  x  );          // Check whether polarradius is      // less then radius of circle      // or not and Angle is between      // startAngle and endAngle      // or not      if     (  Angle  >=  startAngle     &&     Angle   <=  endAngle     &&     polarradius   <  radius  )      System  .  out  .  print  (  'Point'  +  '('  +  x  +  ''  +  y  +  ')'  +      ' exist in the circle sectorn'  );      else      System  .  out  .  print  (  'Point'  +  '('  +  x  +  ''  +  y  +  ')'  +      ' exist in the circle sectorn'  );   }   // Driver Program to test above function   public     static     void     main  (  String     arg  []  )   {      int     radius     =     8       x     =     3       y     =     4  ;      float     percent     =     12       startAngle     =     0  ;      checkPoint  (  radius       x       y       percent       startAngle  );   }   }   // This code is contributed   // by Anant Agarwal.   
Python3
   # Python3 program to check if a point    # lies inside a circle sector.   import   math   def   checkPoint  (  radius     x     y     percent     startAngle  ):   # calculate endAngle   endAngle   =   360   /   percent   +   startAngle   # Calculate polar co-ordinates   polarradius   =   math  .  sqrt  (  x   *   x   +   y   *   y  )   Angle   =   math  .  atan  (  y   /   x  )   # Check whether polarradius is less   # then radius of circle or not and    # Angle is between startAngle and    # endAngle or not   if   (  Angle   >=   startAngle   and   Angle    <=   endAngle   and   polarradius    <   radius  ):   print  (  'Point ('     x     ''     y     ') '   'exist in the circle sector'  )   else  :   print  (  'Point ('     x     ''     y     ') '   'does not exist in the circle sector'  )   # Driver code   radius     x     y   =   8     3     4   percent     startAngle   =   12     0   checkPoint  (  radius     x     y     percent     startAngle  )   # This code is contributed by   # Smitha Dinesh Semwal   
C#
   // C# program to check if a point lies   // inside a circle sector.   using     System.IO  ;   using     System  ;   class     GFG     {          static     void     checkPoint  (  int     radius       int     x       int     y        float     percent       float     startAngle  )      {          // calculate endAngle      float     endAngle     =     360     /     percent     +     startAngle  ;          // Calculate polar co-ordinates      float     polarradius     =         (  float  )  Math  .  Sqrt  (  x     *     x     +     y     *     y  );          float     Angle     =     (  float  )  Math  .  Atan  (  y     /     x  );          // Check whether polarradius is less then       // radius of circle or not and Angle is       // between startAngle and endAngle or not      if     (  Angle     >=     startAngle     &&     Angle      <=     endAngle      &&     polarradius      <     radius  )      Console  .  Write  (  'Point ({0} {1}) exist in '      +     'the circle sector'       x       y  );      else      Console  .  Write  (  'Point ({0} {1}) does not '      +     'exist in the circle sector'       x       y  );      }          // Driver code      public     static     void     Main  ()      {      int     radius     =     8       x     =     3       y     =     4  ;      float     percent     =     12       startAngle     =     0  ;      checkPoint  (  radius       x       y       percent       startAngle  );      }   }   // This code is contributed by Smitha Dinesh Semwal   
JavaScript
    <  script  >   // Javascript program to check if   // a point lies inside a circle   // sector.   function     checkPoint  (  radius       x       y       percent       startAngle  )   {          // Calculate endAngle      let     endAngle     =     360     /     percent     +     startAngle  ;          // Calculate polar co-ordinates      let     polarradius     =     Math  .  sqrt  (  x     *     x     +     y     *     y  );      let     Angle     =     Math  .  atan  (  y     /     x  );          // Check whether polarradius is      // less then radius of circle      // or not and Angle is between      // startAngle and endAngle      // or not      if     (  Angle     >=     startAngle     &&         Angle      <=     endAngle     &&         polarradius      <     radius  )      document  .  write  (  'Point'     +     '('     +     x     +         ''     +     y     +     ')'     +      ' exist in the circle sectorn'  );      else      document  .  write  (  'Point'     +     '('     +     x     +         ''     +     y     +     ')'     +      ' exist in the circle sectorn'  );   }       // Driver code    let     radius     =     8       x     =     3       y     =     4  ;   let     percent     =     12       startAngle     =     0  ;   checkPoint  (  radius       x       y       percent       startAngle  );   // This code is contributed by splevel62        <  /script>   

الإخراج : 

Point(3 4) exists in the circle sector 

تعقيد الوقت:  يا(1)
المساحة المساعدة: يا(1)


 

إنشاء اختبار

مقالات العلوي

فئة

مقالات مثيرة للاهتمام