Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (622) 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 1052 times) 0 Members and 1 Guest are viewing this topic.
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);
Roquen
 « Reply #1 - Posted 2013-11-24 11:26:41 »

Trig is slow.
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!
Roquen
 « Reply #3 - Posted 2013-11-24 12:03:46 »

Trig is slower.
Riven
« League of Dukes »

« JGO Overlord »

Medals: 954
Projects: 4
Exp: 16 years

 « 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!
Icecore

Senior Devvie

Medals: 6

 « 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 `

You live in so cool and insane world, what you f**king doing here?
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 BurntPizza (27 views) 2015-04-23 03:42:11 theagentd (31 views) 2015-04-22 16:23:07 Riven (45 views) 2015-04-16 10:48:47 Duke0200 (52 views) 2015-04-16 01:59:01 Fairy Tailz (38 views) 2015-04-14 20:13:12 Riven (41 views) 2015-04-12 21:36:37 bus hotdog (58 views) 2015-04-10 02:39:32 CopyableCougar4 (61 views) 2015-04-10 00:51:04 BurntPizza (62 views) 2015-04-06 22:06:58 ags1 (62 views) 2015-04-02 10:58:48
 theagentd 23x BurntPizza 16x wessles 15x alwex 11x 65K 11x kingroka123 11x Rayvolution 8x kevglass 8x phu004 8x Roquen 7x chrislo27 7x Hanksha 7x Riven 7x Olo 7x ra4king 7x Ecumene 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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