diff --git a/JansenLegViewer.sln b/JansenLegViewer.sln new file mode 100644 index 0000000..f36a48e --- /dev/null +++ b/JansenLegViewer.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31727.386 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JansenLegSimulator", "JansenLegViewer\JansenLegSimulator.csproj", "{85D59382-1D81-41E1-8213-CAAF5D8F6B2C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85D59382-1D81-41E1-8213-CAAF5D8F6B2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85D59382-1D81-41E1-8213-CAAF5D8F6B2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85D59382-1D81-41E1-8213-CAAF5D8F6B2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85D59382-1D81-41E1-8213-CAAF5D8F6B2C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B0ECD860-46CD-477E-ADA8-2F17A594387D} + EndGlobalSection +EndGlobal diff --git a/JansenLegViewer/App.xaml b/JansenLegViewer/App.xaml new file mode 100644 index 0000000..18588f8 --- /dev/null +++ b/JansenLegViewer/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/JansenLegViewer/App.xaml.cs b/JansenLegViewer/App.xaml.cs new file mode 100644 index 0000000..b97d03c --- /dev/null +++ b/JansenLegViewer/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace JansenLegViewer +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/JansenLegViewer/AssemblyInfo.cs b/JansenLegViewer/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/JansenLegViewer/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/JansenLegViewer/CosasQueNoSeExplicanEnMatesDePrimero.cs b/JansenLegViewer/CosasQueNoSeExplicanEnMatesDePrimero.cs new file mode 100644 index 0000000..d80ce46 --- /dev/null +++ b/JansenLegViewer/CosasQueNoSeExplicanEnMatesDePrimero.cs @@ -0,0 +1,75 @@ +using System; +using System.Linq; +using System.Text; +using System.Drawing; +using System.Threading.Tasks; +using System.Collections.Generic; +using static System.Math; +using System.Numerics; + +/* + Función que permite obtener las posiciones de las + posibles intersecciones entre dos circulos. + + PD: le debeo un café a alguien random de internet + */ + +namespace JansenLegSimulator +{ + public class CosasQueNoSeExplicanEnMatesDePrimero + { + /// + /// Gets the intersections of two circles + /// + /// The first circle's center + /// The second circle's center + /// The first circle's radius + /// The second circle's radius. If omitted, assumed to equal the first circle's radius + /// An array of intersection points. May have zero, one, or two values + /// Adapted from http://csharphelper.com/blog/2014/09/determine-where-two-circles-intersect-in-c/ + public static Vector2[] CalculateCircleIntersections(Vector2 center1, Vector2 center2, double radius1, double? radius2 = null) + { + // Definir radios. Si sólo se ha dado R1, + // asignar valor de R1 a los dos radios + var (r1, r2) = (radius1, radius2 ?? radius1); + + // Definir centros de los circulos. + (double x1, double y1, double x2, double y2) = (center1.X, center1.Y, center2.X, center2.Y); + + // Determinar la distancia entre los dos centros. + // Es el módulo del vector que une los dos centros. + double d = Sqrt(Pow(x1 - x2, 2) + Pow(y1 - y2, 2)); + + // Si la suma de radios es menor a la distancia que + // une los centros, devolver un array vacío. + // No existe intersección. + if (!(Abs(r1 - r2) <= d && d <= r1 + r2)) { return new Vector2[0]; } + + // En este momento, se dan las condiciones para que + // por lo menos exista una intersección + var dsq = d * d; // Caucular el cuadrado de la distancia (d^2) + var (r1sq, r2sq) = (r1 * r1, r2 * r2); // Calcular los cuadrados de los radios (r^2) + var r1sq_r2sq = r1sq - r2sq; // Calcular la diferencia de los r^2 (incR^2) + var a = r1sq_r2sq / (2 * dsq); // Calcular la división (incR^2)/(2*d^2) + + var c = Sqrt(2 * (r1sq + r2sq) / dsq - (r1sq_r2sq * r1sq_r2sq) / (dsq * dsq) - 1); + + // Calcular las componentes de los resultados + var fx = (x1 + x2) / 2 + a * (x2 - x1); + var gx = c * (y2 - y1) / 2; + + var fy = (y1 + y2) / 2 + a * (y2 - y1); + var gy = c * (x1 - x2) / 2; + + // Generar los vectores de las intersecciones resultado + var i1 = new Vector2((float)(fx + gx), (float)(fy + gy)); + var i2 = new Vector2((float)(fx - gx), (float)(fy - gy)); + + // Si son la misma solucción deveolver sólo i1. + // Si son ditintas, devolver ambas soluciones. + return i1 == i2 ? + new Vector2[] { i1 } : + new Vector2[] { i1, i2 }; + } + } +} diff --git a/JansenLegViewer/Cálculos.cs b/JansenLegViewer/Cálculos.cs new file mode 100644 index 0000000..23cba18 --- /dev/null +++ b/JansenLegViewer/Cálculos.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; +using System.Threading.Tasks; +using static JansenLegSimulator.Rod; + +namespace JansenLegSimulator +{ + public partial class Cálculos + { + private void DefineSystem() + { + // Definir las barra motriz + M = new Rod(new Vector2(a, l)) { Length = m, RodName = "M" }; + + // Definir las barras semi-independientes + // Aquellas que tienen un extremo fijado a una coordenada + B = new Rod(new Vector2(0, 0)) { Length = b, RodName = "B" }; + C = new Rod(new Vector2(0, 0)) { Length = c, RodName = "C" }; + D = new Rod(new Vector2(0, 0)) { Length = d, RodName = "D" }; + + // Definir y conectar los inicios de las barras flotantes + // Aquellas cuyos dos extremos están conectados a otra barra + J = new Rod() { Length = j, RodName = "J" }; J.ConnectBegin(ref M); + K = new Rod() { Length = k, RodName = "K" }; K.ConnectBegin(ref M); + E = new Rod() { Length = e, RodName = "E" }; E.ConnectBegin(ref B); + + G = new Rod() { Length = g, RodName = "G" }; G.ConnectBegin(ref C); + F = new Rod() { Length = f, RodName = "F" }; F.ConnectBegin(ref D); + + H = new Rod() { Length = h, RodName = "H" }; H.ConnectBegin(ref G); + I = new Rod() { Length = i, RodName = "I" }; I.ConnectBegin(ref C); + + // Añadir las barras definidas a la lista + // de elementos móviles. + Elements.Add(M); + Elements.Add(J); + Elements.Add(B); + + Elements.Add(C); + Elements.Add(K); + + Elements.Add(E); + Elements.Add(D); + + Elements.Add(G); + Elements.Add(F); + + Elements.Add(H); + Elements.Add(I); + } + + [STAThread] + public void CalculateSystem() + { + // Para cada par de barras calcular y asignar los + // ángulos de rotación necesarios para unirlas + + // Articulación JB + (J.Alpha, B.Alpha) = GetIntersectionAlphas(J, B); + // Articulación CK + (C.Alpha, K.Alpha) = GetIntersectionAlphas(C, K); + // Articulación ED + (E.Alpha, D.Alpha) = GetIntersectionAlphas(E, D); + // Articulación FG + (F.Alpha, G.Alpha) = GetIntersectionAlphas(F, G); + // Articulación HI + (H.Alpha, I.Alpha) = GetIntersectionAlphas(H, I); + } + } +} diff --git a/JansenLegViewer/JansenLegSimulator.csproj b/JansenLegViewer/JansenLegSimulator.csproj new file mode 100644 index 0000000..407932c --- /dev/null +++ b/JansenLegViewer/JansenLegSimulator.csproj @@ -0,0 +1,9 @@ + + + + WinExe + net5.0-windows + true + + + diff --git a/JansenLegViewer/JansenLegSimulator.zip b/JansenLegViewer/JansenLegSimulator.zip new file mode 100644 index 0000000..2ebee8c Binary files /dev/null and b/JansenLegViewer/JansenLegSimulator.zip differ diff --git a/JansenLegViewer/MainWindow.xaml b/JansenLegViewer/MainWindow.xaml new file mode 100644 index 0000000..8100b97 --- /dev/null +++ b/JansenLegViewer/MainWindow.xaml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + +