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).

// We store the angle in clockwise radians for more efficient
// calculations.
// So 0=right, pi=down etc.

persistable sclass Angle {
  double radians;
  
  *(double *radians) {}
  
  // Create angle from x/y ratio
  *(double x, double y) { radians = atan2(x, y); }
  
  static Angle fromRadians(double radians) { ret new Angle(radians); }
  static Angle fromDegrees(double degrees) { ret new Angle(degreesToRadians(degrees); }

  double radians() { ret radians; }
  double degrees() { ret radiansToDegrees(radians); }
  
  double x() { ret cos(radians); }
  double y() { ret sin(radians); }
  
  toString { ret formatDouble(degrees(), 1) + "°"; }
}

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: 182 / 274
Version history: 2 change(s)
Referenced in: [show references]