Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Which method of drawing a line is faster?  (Read 3015 times)
0 Members and 1 Guest are viewing this topic.
Offline lcass
« Posted 2013-11-24 11:24:05 »

So I generally know there are two ways to render a line one with bresehnams line algorithm and one with trigonometry.

double grad = Math.atan2((lineendx - linestartx),(lineendy - linestarty));
double xincrement = Math.sin(grad);
double yincrement = Math.cos(grad);
Offline Roquen

JGO Kernel


Medals: 518



« Reply #1 - Posted 2013-11-24 11:26:41 »

Trig is slow.
Offline lcass
« Reply #2 - Posted 2013-11-24 11:32:37 »

Well ive been about to do over 100,000 trig operations with no defect to performance.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen

JGO Kernel


Medals: 518



« Reply #3 - Posted 2013-11-24 12:03:46 »

Trig is slower.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1356
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2013-11-24 12:17:51 »

Whenever you see atan2 + cos&sin, the obvious choice is to normalize the vector instead.

1  
2  
3  
double angle = Math.atan2(dy, dx);
double x= Math.sin(angle);
double y= Math.cos(angle);
==
1  
2  
3  
double invLen = 1.0 / Math.sqrt(dx*dx + dy*dy);
double x = dx * invLen;
double y = dy * invLen;


However... pick Bresenham.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline Icecore
« Reply #5 - Posted 2013-11-24 14:27:46 »

f**k Y i finaly find out this XD
offtop sorry
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
      double rad = Math.toRadians(33);
      double Cos = Math.cos(rad);
      double Sin = Math.sin(rad);
      double len = 4;
      double x = len * Sin;
      double y = len * Cos;
      //////////////////////////////////////////
      //Direction normalize
      double len_Sq = Math.sqrt(x * x + y * y);
      double invlen = 1d / len_Sq;
      double Cos2 = y * invlen;
      double Sin2 = x * invlen;
      ////////////////////////
      double x2 = len * Sin2;
      double y2 = len * Cos2;
      double len2 = (x2 / Sin2 + y2 / Cos2) / 2;
      //   x == x2, Sin == Sin2
      //   y == y2, Cos == Cos2
      //   len2 == 4

Last known State: Reassembled in Cyberspace
End Transmission....
..
.
Journey began Now)
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1574 views)
2018-06-10 19:43:48

EgonOlsen (1658 views)
2018-06-10 19:43:44

EgonOlsen (1145 views)
2018-06-10 19:43:20

DesertCoockie (1573 views)
2018-05-13 18:23:11

nelsongames (1174 views)
2018-04-24 18:15:36

nelsongames (1664 views)
2018-04-24 18:14:32

ivj94 (2421 views)
2018-03-24 14:47:39

ivj94 (1631 views)
2018-03-24 14:46:31

ivj94 (2719 views)
2018-03-24 14:43:53

Solater (884 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!