Skip to content

Instantly share code, notes, and snippets.

@Dreamersoul
Last active June 7, 2023 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dreamersoul/68f69903efaee5cdb12b7bd4676fba2a to your computer and use it in GitHub Desktop.
Save Dreamersoul/68f69903efaee5cdb12b7bd4676fba2a to your computer and use it in GitHub Desktop.
Azimuth
using System;
namespace WellborePathCalculation
{
public class DeviationSurveyPoint
{
public double Azimuth { get; set; } // Azimuth angle in degrees
public double Depth { get; set; } // Depth in meters
public double Inclination { get; set; } // Inclination angle in degrees
public double DoglegSeverity { get; set; } // Dogleg severity in degrees per 30 meters
public double ToolFaceAngle { get; set; } // Tool face angle in degrees
public double TurnRate { get; set; } // Turn rate in degrees per 30 meters
public double X { get; set; } // X-coordinate in meters
public double Y { get; set; } // Y-coordinate in meters
public double Z { get; set; } // Z-coordinate in meters
}
public class WellborePathCalculator {
using System;
public class Point3D
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}
public class SurveyPoint
{
public double Azimuth { get; set; }
public double Inclination { get; set; }
public double TVD { get; set; }
public double MD { get; set; }
public double TurnRate { get; set; }
public double ToolFaceAngle { get; set; }
}
public class WellboreSurveyCalculator
{
// Convert degrees to radians
private static double ToRadians(double degrees)
{
return degrees * Math.PI / 180.0;
}
// Calculate XYZ coordinates of a survey point
public static Point3D CalculateSurveyPoint(SurveyPoint point, Point3D previousPoint = null)
{
double inclinationRad = ToRadians(point.Inclination);
double azimuthRad = ToRadians(point.Azimuth);
double turnRateRad = ToRadians(point.TurnRate);
double toolFaceAngleRad = ToRadians(point.ToolFaceAngle);
Point3D currentPoint = new Point3D();
if (previousPoint != null)
{
// Calculate the change in MD
double deltaMD = point.MD - previousPoint.MD;
// Calculate the change in TVD
double deltaTVD = Math.Sin(inclinationRad) * deltaMD;
// Calculate the change in horizontal distance (XY plane)
double deltaHorizontal = Math.Cos(inclinationRad) * deltaMD;
// Calculate the change in X, Y, Z coordinates
currentPoint.X = previousPoint.X + deltaHorizontal * Math.Cos(azimuthRad);
currentPoint.Y = previousPoint.Y + deltaHorizontal * Math.Sin(azimuthRad);
currentPoint.Z = previousPoint.Z + deltaTVD;
}
else
{
// If it's the first point, use TVD as the Z coordinate
currentPoint.X = 0.0;
currentPoint.Y = 0.0;
currentPoint.Z = point.TVD;
}
// Apply the tool face rotation
double rotationX = Math.Cos(toolFaceAngleRad);
double rotationY = Math.Sin(toolFaceAngleRad);
double newX = currentPoint.X * rotationX - currentPoint.Y * rotationY;
double newY = currentPoint.X * rotationY + currentPoint.Y * rotationX;
currentPoint.X = newX;
currentPoint.Y = newY;
return currentPoint;
}
public static List<Point3D> CalculateSurveyPoints(List<SurveyPoint> points)
{
List<Point3D> surveyPoints = new List<Point3D>();
for (int i = 0; i < points.Count; i++)
{
Point3D currentPoint = CalculateSurveyPoint(points[i], i > 0 ? surveyPoints[i - 1] : null);
surveyPoints.Add(currentPoint);
}
return surveyPoints;
}
private static double DegreesToRadians(double degrees)
{
return degrees * Math.PI / 180;
}
}
public Point3DCollection WellborePoints
{
get { return _wellborePoints; }
set
{
_wellborePoints = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(WellborePoints)));
}
}
@Dreamersoul
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment