From 42da5eddcf903303224c4c31b4cbbf3904a95b97 Mon Sep 17 00:00:00 2001
From: Thomas Lambert <t.lambert@uliege.be>
Date: Mon, 11 Jul 2022 17:21:11 +0200
Subject: [PATCH] add(polar): polypolar method

---
 +af_tools/@Polar/Polar.m     |  6 ++++
 +af_tools/@Polar/loadpolar.m |  2 +-
 +af_tools/@Polar/polypolar.m | 54 ++++++++++++++++++++++++++++++++++++
 CHANGELOG.md                 |  2 ++
 4 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 +af_tools/@Polar/polypolar.m

diff --git a/+af_tools/@Polar/Polar.m b/+af_tools/@Polar/Polar.m
index d9461b5..dd99a43 100644
--- a/+af_tools/@Polar/Polar.m
+++ b/+af_tools/@Polar/Polar.m
@@ -153,4 +153,10 @@ classdef Polar
     methods (Static)
         self = loadpolar(polarFile) % Load polar from file
     end
+
+    % ----------------------------------------------------------------------------------------------
+
+    methods (Static)
+        self = polypolar(polyCl, polyCd) % Create polar using polynomial coefficients
+    end
 end
diff --git a/+af_tools/@Polar/loadpolar.m b/+af_tools/@Polar/loadpolar.m
index ea69528..f5b7779 100644
--- a/+af_tools/@Polar/loadpolar.m
+++ b/+af_tools/@Polar/loadpolar.m
@@ -1,7 +1,7 @@
 function obj = loadpolar(polarFile)
     % LOADPOLAR  Load a polar object from a file
     %   This static method can be used in place of a normal constructor.
-    %   When this function is used, the Polar object saved in the MAT-File will be imported. By
+    %   When this method is used, the Polar object saved in the MAT-File will be imported. By
     %   assigning the output to something, it effectively duplicates the polar from the MAT-file.
     % -----
     %
diff --git a/+af_tools/@Polar/polypolar.m b/+af_tools/@Polar/polypolar.m
new file mode 100644
index 0000000..cd0b9cf
--- /dev/null
+++ b/+af_tools/@Polar/polypolar.m
@@ -0,0 +1,54 @@
+function Obj = polypolar(polyCl, polyCd)
+    % POLYPOLAR  Create a polar object using polynomial coefficients for cl and cd
+    %   This static method can be used in place of a normal constructor.
+    %   This will create a Polar object based on the polynomial coefficients given as input.
+    %   The polar created will cover the full range of angles of attack ([-pi, pi] rad), with a step
+    %   of 0.5 deg between two points.
+    % -----
+    %
+    % Usage:
+    %   Polar.polypolar(polyCl,polyCd) returns a polar object with values equal to the coefficients.
+    %
+    % Inputs:
+    %   polyCl : polynomial coefficients for cl (see polyval function for formatting), [1/deg]
+    %   polyCd : polynomial coefficients for cd (see polyval function for formatting), [1/deg]
+    %
+    % Output:
+    %   Obj: Polar object polynomial values for aoa, cl and cd an default values otherwise.
+    %
+    % Example:
+    %   NewPolar = af_tools.Polar.polypolar([0.001, 2*pi, 0], [0.1, 0, 0.002]);
+    %
+    % See also: af_tools.Polar.
+    %
+    % -----
+    % (c) Copyright 2022 University of Liege
+    % Author: Thomas Lambert <t.lambert@uliege.be>
+    % ULiege - Aeroelasticity and Experimental Aerodynamics
+    % Apache 2.0 License
+    % https://gitlab.uliege.be/am-dept/matlab_airfoil_toolbox
+
+    % ----------------------------------------------------------------------------------------------
+
+    % Defaults and constants
+    DEF.AOA_STEP = 0.5;
+    DEF.AIRFOIL = {'Polynomial'};
+    DEF.REYNOLDS = 1e6;
+    DEF.MACH = 0;
+
+    % ---------------------------------------
+    % Construct empty object first
+    Obj = af_tools.Polar();
+
+    % Get lift and drag values
+    aoa_deg = (-180:DEF.AOA_STEP:180)';
+    Obj.aoa = deg2rad(aoa_deg);
+    Obj.cl = polyval(polyCl, aoa_deg);
+    Obj.cd = polyval(polyCd, aoa_deg);
+
+    % Set other properties to default values
+    Obj.airfoil = DEF.AIRFOIL;
+    Obj.reynolds = DEF.REYNOLDS;
+    Obj.mach = DEF.MACH;
+
+end
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5b27383..4998329 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Added
 
+- **Polar**: add polypolar method
+
 ### Changed
 
 ### Deprecated
-- 
GitLab