Author Topic: how to get Arc Length using Chord and Radius with c#  (Read 3806 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
how to get Arc Length using Chord and Radius with c#
« on: September 05, 2015, 07:12:20 PM »
Okay...so I've tried to format it a few different ways but can't seem to get the formula right in c#

Anyone willing to share a method if you have one?

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: how to get Arc Length using Chord and Radius with c#
« Reply #1 on: September 05, 2015, 08:31:29 PM »
Nevermind... took the long route.

Got the vectors to the start and end and then subtracted to get my angle.

Code - C#: [Select]
  1. Vector2d anglestart = pipe.Curve2d.Center.GetVectorTo(new Point2d(pipe.StartPoint.X, pipe.StartPoint.Y));
  2. Vector2d angleend = pipe.Curve2d.Center.GetVectorTo(new Point2d(myinvloc.X, myinvloc.Y));
  3. double theta = anglestart.GetAngleTo(angleend);
  4. dist = pipe.Radius * theta;//arclength
  5.  
« Last Edit: September 05, 2015, 08:35:39 PM by Alien »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: how to get Arc Length using Chord and Radius with c#
« Reply #2 on: September 05, 2015, 10:00:22 PM »
Just in case you want the result as a math solution :

Code - C#: [Select]
  1. using System;
  2.  
  3.  
  4. namespace ConsoleApplication2 {
  5.     class Program {
  6.         static void Main(string[] args) {
  7.             double radius = 200;
  8.             double chordLength = 200;
  9.  
  10.             double circumference = Math.PI * 2.0 * radius;
  11.             double enclosedAngleRadians = AngleFromChord(radius, chordLength);
  12.             double arcLength = ArcLengthFromChord(radius, chordLength);
  13.  
  14.  
  15.             Console.WriteLine("Circumference: " + circumference);
  16.             Console.WriteLine("Enclosed Angle Radians: " + enclosedAngleRadians);
  17.             Console.WriteLine("Enclosed Angle Degrees: " + enclosedAngleRadians * (180.0 / Math.PI));
  18.             Console.WriteLine("Arc Length: " + arcLength);
  19.  
  20.             Console.ReadKey();
  21.         }
  22.  
  23.         /// <summary>
  24.         /// Get the arc length from the radius and enclosed angle
  25.         /// </summary>
  26.         public static double ArcLengthFromAngle(double radius, double radians) {
  27.             return radius * radians;
  28.         }
  29.         /// <summary>
  30.         ///  Get the angle from the chordLength (only works for angles <= 180)
  31.         /// </summary>
  32.         public static double AngleFromChord(double radius, double chordLength) {
  33.             return radius != 0.0 ? 2.0 * Math.Asin(chordLength / (radius * 2.0)) : 0.0;
  34.         }
  35.         /// <summary>
  36.         ///Get the arc length from the radius and chordLength
  37.         /// </summary>
  38.         public static double ArcLengthFromChord(double radius, double chordLength) {
  39.             if(radius == 0.0)
  40.                 return chordLength;
  41.  
  42.             return ArcLengthFromAngle(radius, AngleFromChord(radius, chordLength));
  43.         }
  44.     }
  45. }
  46.  
  47.  

« Last Edit: September 05, 2015, 10:06:29 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: how to get Arc Length using Chord and Radius with c#
« Reply #3 on: September 06, 2015, 08:39:27 PM »
Thank you Kerry!  I've needed this for a few items. Much appreciated :)


Just in case you want the result as a math solution :

Code - C#: [Select]
  1. using System;
  2.  
  3.  
  4. namespace ConsoleApplication2 {
  5.     class Program {
  6.         static void Main(string[] args) {
  7.             double radius = 200;
  8.             double chordLength = 200;
  9.  
  10.             double circumference = Math.PI * 2.0 * radius;
  11.             double enclosedAngleRadians = AngleFromChord(radius, chordLength);
  12.             double arcLength = ArcLengthFromChord(radius, chordLength);
  13.  
  14.  
  15.             Console.WriteLine("Circumference: " + circumference);
  16.             Console.WriteLine("Enclosed Angle Radians: " + enclosedAngleRadians);
  17.             Console.WriteLine("Enclosed Angle Degrees: " + enclosedAngleRadians * (180.0 / Math.PI));
  18.             Console.WriteLine("Arc Length: " + arcLength);
  19.  
  20.             Console.ReadKey();
  21.         }
  22.  
  23.         /// <summary>
  24.         /// Get the arc length from the radius and enclosed angle
  25.         /// </summary>
  26.         public static double ArcLengthFromAngle(double radius, double radians) {
  27.             return radius * radians;
  28.         }
  29.         /// <summary>
  30.         ///  Get the angle from the chordLength (only works for angles <= 180)
  31.         /// </summary>
  32.         public static double AngleFromChord(double radius, double chordLength) {
  33.             return radius != 0.0 ? 2.0 * Math.Asin(chordLength / (radius * 2.0)) : 0.0;
  34.         }
  35.         /// <summary>
  36.         ///Get the arc length from the radius and chordLength
  37.         /// </summary>
  38.         public static double ArcLengthFromChord(double radius, double chordLength) {
  39.             if(radius == 0.0)
  40.                 return chordLength;
  41.  
  42.             return ArcLengthFromAngle(radius, AngleFromChord(radius, chordLength));
  43.         }
  44.     }
  45. }
  46.  
  47.  

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: how to get Arc Length using Chord and Radius with c#
« Reply #4 on: September 07, 2015, 08:33:55 PM »
You're welcome.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bryco

  • Water Moccasin
  • Posts: 1882
Re: how to get Arc Length using Chord and Radius with c#
« Reply #5 on: September 10, 2015, 05:41:14 PM »
Also     arc.GetFirstDerivative(arc.StartPoint) is the vector of the tangent at that point
arc.GetSecondDerivative(arc.StartPoint) is the vector of the radius