Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Example for Polar coordinates #126

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docs/components/guide-examples/examples/PolarCoordinates.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as React from "react";
import {
Mafs,
vec,
Theme,
Line,
Coordinates,
useMovablePoint,
Plot
} from "mafs";

export default function PolarCoordinate() {
const point1 = useMovablePoint([-2, -1]);
const r = vec.mag(point1.point);
let angle = Math.atan2(point1.point[1], point1.point[0]);

// Adjust angle to always be positive, between 0 to 2π
if (angle < 0) {
angle += 2 * Math.PI;
}

return (
<div
style={{ display: "flex", justifyContent: "space-between", gap: "10px" }}
>
<Mafs viewBox={{ x: [-2, 2], y: [-4, 4] }} pan={false}>
<Coordinates.Cartesian />
<Line.Segment
point1={[0, 0]}
point2={[point1.point[0], 0]}
color={Theme.blue}
/>
<Line.Segment
point1={[point1.point[0], 0]}
point2={point1.point}
color={Theme.blue}
/>

{point1.element}
</Mafs>

<Mafs viewBox={{ x: [-2, 2], y: [-4, 4] }} pan={false}>
<Coordinates.Polar subdivisions={3} lines={1} />
<Line.Segment point1={[0, 0]} point2={[r, 0]} color={Theme.blue} />
<Plot.Parametric
t={[0, angle]}
xy={(t) => [r * Math.cos(t), r * Math.sin(t)]}
color={Theme.blue}
/>
{point1.element}
</Mafs>
</div>
);
}