Skip to content

Commit

Permalink
NOname-awa/graphics2d: Use atan2 to get coord to coord angle (#1460)
Browse files Browse the repository at this point in the history
  • Loading branch information
DNin01 authored May 19, 2024
1 parent 02e255b commit 168e724
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions extensions/NOname-awa/graphics2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@
id: "ray_direction",
default: "direction of ([x1],[y1]) to ([x2],[y2])",
}),
hideFromPalette: true,
arguments: {
x1: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "0",
},
y1: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "0",
},
x2: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "100",
},
y2: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "0",
},
},
},
{
opcode: "ray_direction2",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate({
id: "ray_direction",
default: "direction of ([x1],[y1]) to ([x2],[y2])",
}),
arguments: {
x1: {
type: Scratch.ArgumentType.NUMBER,
Expand Down Expand Up @@ -295,6 +322,13 @@
return (180 / Math.PI) * Math.atan(dx / dy);
}
}
ray_direction2(args) {
const dx =
Scratch.Cast.toNumber(args.x2) - Scratch.Cast.toNumber(args.x1);
const dy =
Scratch.Cast.toNumber(args.y2) - Scratch.Cast.toNumber(args.y1);
return (Math.atan2(dx, dy) * 180) / Math.PI;
}
vertical(args) {
if (isNaN(args.a) || isNaN(args.b)) {
return false;
Expand Down

0 comments on commit 168e724

Please sign in to comment.