Skip to content

Instantly share code, notes, and snippets.

@f1729
Created July 1, 2018 20:24
Show Gist options
  • Save f1729/45b667bd2e6f7a80bdc02b7142e86f6e to your computer and use it in GitHub Desktop.
Save f1729/45b667bd2e6f7a80bdc02b7142e86f6e to your computer and use it in GitHub Desktop.
// A x B
const matrix = [["25027M67","25023M67","25021M67","27015M67","29012M66","32012M67"],
["26035M68","26033M67","26031M67","27031M68","28027M67","29027M66"],
["26052M67","25058M67","26056M67","27060M67","28056M66","29048M66"],
["26083M68","26079M67","26068M65","27060M63","29068M62","29071M62"],
["27068M66","26066M65","26056M64","27048M62","29054M62","28064M61"]]
const topMax = ["0600W", "0550W", "0500W", "0450W", "0400W", "0350W"]
const leftMax = ["050S", "100S", "150S", "200S", "250S"]
let values = [];
matrix.forEach((rows, i) => {
rows.forEach((element, j) => {
if (i !== 0 && j !== 0 && i !== matrix.length - 1 && j !== rows.length - 1) {
values.push([transformData(getCross(element, i, j)), i, j]);
}
})
});
/*
En el eje x:
(ui,vj) = 26033M67
(ui−1,vj)= 26035M68
(ui+1 , vj )=26031M67
En el eje y:
(ui, vj+1) = 25058M67 (ui, vj−1) = 25023M67
*/
function getCross(element, i, j) {
// return a matrix with X, Y axes
return [[matrix[i][j-1], matrix[i][j+1]], [matrix[i+1][j], matrix[i-1][j]]]
}
//Donde cada valor para 25058M67 significa 250 grados (direcci ́on del viento), 58 kt nudos de intensidad , M representa el signo menos y 67 representa la temperatura como se muestra en la siguiente data.
function transformData(matrix, i, j) {
var x = matrix[0]; // ["25027M67", "25027M67"]
var y = matrix[1]; // the same
return [
[
2 * Number(x[0].substring(3, 5)) * Math.cos(Number(x[0].substring(0, 3)) * Math.PI / 180),
2 * Number(x[0].substring(3, 5)) * Math.sin(Number(x[0].substring(0, 3)) * Math.PI / 180)
],
[
2 * Number(x[1].substring(3, 5)) * Math.cos(Number(x[1].substring(1, 3)) * Math.PI / 181),
2 * Number(x[1].substring(3, 5)) * Math.sin(Number(x[1].substring(0, 3)) * Math.PI / 180)]
];
}
function getVorticityPerPoint(matrix) {
// We use just a X axes, then:
var x = matrix[0];
var i = matrix[1];
var j = matrix[2];
var difTop = Math.abs(Number(topMax[i+1].substring(0,3)) - Number(topMax[i-1].substring(0,3))) * 10;
var difLef = Math.abs(Number(leftMax[j+1].substring(0,2)) - Number(leftMax[j-1].substring(0,2))) * 10;
console.log(difTop, difLef);
}
console.log(values[0])
getVorticityPerPoint(values[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment