Libraryless. Click here for Pure Java version (8126L/45K).
1 | // line that goes through x, y at specified angle |
2 | // angle is in radians |
3 | srecord LineThroughPoint(double x, double y, double angle) is G2Drawable { |
4 | *(IDoublePt p, double *angle) { |
5 | x = p.x_double(); |
6 | y = p.y_double(); |
7 | } |
8 | |
9 | DoublePt pointOnLine(double distance) { |
10 | ret doublePt( |
11 | x+sin(angle)*distance, |
12 | y+cos(angle)*distance); |
13 | } |
14 | |
15 | // uses color selected in g |
16 | public void drawOn(Graphics2D g) { |
17 | int distance = 200; |
18 | DoublePt p1 = pointOnLine(-distance); |
19 | DoublePt p2 = pointOnLine(distance); |
20 | g.drawLine( |
21 | iround(p1.x_double()), iround(p1.y_double()), |
22 | iround(p2.x_double()), iround(p2.y_double())); |
23 | } |
24 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035464 |
Snippet name: | LineThroughPoint |
Eternal ID of this version: | #1035464/4 |
Text MD5: | fbcb7889339e98f5b52b823e691a4161 |
Transpilation MD5: | caa4ca8000c40c625120a03e63cb43af |
Author: | stefan |
Category: | javax / math |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-05-21 18:41:52 |
Source code size: | 682 bytes / 24 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 135 / 210 |
Version history: | 3 change(s) |
Referenced in: | [show references] |