Skip to content

Commit

Permalink
lceanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding committed Jan 4, 2025
1 parent 242887d commit 9b0fb72
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/features/rap/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Temperature from "./cells/Temperature";
import WindDirection from "./cells/WindDirection";
import WindSpeed from "./cells/WindSpeed";
import { css } from "@emotion/react";
import { vectorDifferenceMagnitude } from "../../helpers/vector";

const DELTA_WINDSPEED_VECTOR_THRESHOLD_KPH = 10;

const TableRow = styled.tr<{ opaque: boolean }>`
${({ opaque }) =>
Expand Down Expand Up @@ -40,7 +43,7 @@ export default function Row({
datum.windDirectionInDeg,
displayedRapData[index - 1]?.windSpeedInKph,
displayedRapData[index - 1]?.windDirectionInDeg,
) > 10;
) > DELTA_WINDSPEED_VECTOR_THRESHOLD_KPH;

return (
<TableRow key={index} opaque={negativeAltitude(datum)}>
Expand Down Expand Up @@ -84,27 +87,3 @@ export default function Row({
</TableRow>
);
}

function vectorDifferenceMagnitude(
speed1: number,
direction1: number,
speed2: number,
direction2: number,
): number {
// Convert directions from degrees to radians
const radian1 = (Math.PI / 180) * direction1;
const radian2 = (Math.PI / 180) * direction2;

// Convert polar coordinates to Cartesian coordinates
const x1 = speed1 * Math.cos(radian1);
const y1 = speed1 * Math.sin(radian1);
const x2 = speed2 * Math.cos(radian2);
const y2 = speed2 * Math.sin(radian2);

// Calculate the difference in Cartesian coordinates
const dx = x2 - x1;
const dy = y2 - y1;

// Calculate the magnitude of the difference vector
return Math.sqrt(dx * dx + dy * dy);
}
23 changes: 23 additions & 0 deletions src/helpers/vector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export function vectorDifferenceMagnitude(
speed1: number,
direction1: number,
speed2: number,
direction2: number,
): number {
// Convert directions from degrees to radians
const radian1 = (Math.PI / 180) * direction1;
const radian2 = (Math.PI / 180) * direction2;

// Convert polar coordinates to Cartesian coordinates
const x1 = speed1 * Math.cos(radian1);
const y1 = speed1 * Math.sin(radian1);
const x2 = speed2 * Math.cos(radian2);
const y2 = speed2 * Math.sin(radian2);

// Calculate the difference in Cartesian coordinates
const dx = x2 - x1;
const dy = y2 - y1;

// Calculate the magnitude of the difference vector
return Math.sqrt(dx * dx + dy * dy);
}

0 comments on commit 9b0fb72

Please sign in to comment.