Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

23
LINES

< > BotCompany Repo | #1035307 // Angle - represents a 2D angle

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (172L/1K).

1  
// We store the angle in clockwise radians for more efficient
2  
// calculations.
3  
// So 0=right, pi=down etc.
4  
5  
persistable sclass Angle {
6  
  double radians;
7  
  
8  
  *(double *radians) {}
9  
  
10  
  // Create angle from x/y ratio
11  
  *(double x, double y) { radians = atan2(x, y); }
12  
  
13  
  static Angle fromRadians(double radians) { ret new Angle(radians); }
14  
  static Angle fromDegrees(double degrees) { ret new Angle(degreesToRadians(degrees); }
15  
16  
  double radians() { ret radians; }
17  
  double degrees() { ret radiansToDegrees(radians); }
18  
  
19  
  double x() { ret cos(radians); }
20  
  double y() { ret sin(radians); }
21  
  
22  
  toString { ret formatDouble(degrees(), 1) + "°"; }
23  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035307
Snippet name: Angle - represents a 2D angle
Eternal ID of this version: #1035307/3
Text MD5: 76595c959bb81c71ac61f02e45db33b9
Transpilation MD5: 4e000f3d06aa7e70f393c7f11029e713
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-30 14:53:34
Source code size: 673 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 184 / 278
Version history: 2 change(s)
Referenced in: [show references]