Data Realms Fan Forums
http://45.55.195.193/

DrawLine()
http://45.55.195.193/viewtopic.php?f=73&t=16617
Page 1 of 3

Author:  Grif [ Tue Sep 22, 2009 12:52 am ]
Post subject:  DrawLine()

haha just kidding

but really:

Code:
   function plot(a,b)
      local pixel = CreateMOPixel("Line Particle");
      pixel.Pos = Vector(a,b);
      MovableMan:AddParticle(pixel);
   end
   
   function line(x0, x1, y0, y1)
      if math.abs(y1-y0) > math.abs(x1-x0) then
         steep = true;
      end
      if steep == true then
         x0,y0,x1,y1 = y0,x0,y1,x1;
      end
      if x0 > x1 then
         x0,x1,y0,y1 = x1,x0,y1,y0;
      end
      deltax = x1 - x0;
      deltay = math.abs(y1 - y0);
      xerror = deltax / 2
      y = y0;
      if y0 < y1 then
         ystep = 1;
      else
         ystep = -1;
      end
      for x=x0,x1 do
         if steep == true then
            plot(y,x);
         else
            plot(x,y);
         end
         xerror = xerror - deltay;
         if xerror < 0 then
            y = y + ystep;
            xerror = xerror + deltax;
         end
      end
   end

Author:  CrazyMLC [ Tue Sep 22, 2009 12:58 am ]
Post subject:  Re: DrawLine()

I know just how to express my opinion on this;

:?:

Author:  ProjektTHOR [ Tue Sep 22, 2009 1:40 am ]
Post subject:  Re: DrawLine()

Its how to draw a line with Lua.

Author:  Grif [ Tue Sep 22, 2009 1:43 am ]
Post subject:  Re: DrawLine()

More specifically it's Bresenham's line algorithm, in Lua.
http://en.wikipedia.org/wiki/Bresenham_line_algorithm

Author:  zalo [ Tue Sep 22, 2009 4:09 am ]
Post subject:  Re: DrawLine()

It works fairly kinda well.

Image
As you can see here, a Bersenham-Grappling gun splice shows fairly well (Edited for
MOSParticle Main thruster blast ball at Lifetime 10).


Image Image
But here and here you can see that it oddly doesn't connect when I move out of an invisible area.

Anyway, do the formula for plotting trajectory, and we have a deal.

So you don't have to go through the effort of combining them together yourself to test.

Attachments:
File comment: Kyred and Roon3, Hope you don't mind.
Grapple.rte.rar [31.62 KiB]
Downloaded 188 times

Author:  Grif [ Tue Sep 22, 2009 4:54 am ]
Post subject:  Re: DrawLine()

Yeah, I think one of the line slopes isn't quite right, since it's designed for a four-quadrant system.

Need to fix it.

Author:  Kyred [ Tue Sep 22, 2009 7:18 pm ]
Post subject:  Re: DrawLine()

Now if only Lua had support for derivatives and integrals, then I'd be happy:P.

Author:  Geti [ Wed Sep 23, 2009 7:06 am ]
Post subject:  Re: DrawLine()

they are. you just have to write a function to do them yourself ;)
i do love my calculus though.

this could be made more efficient by using the velocity of a mopixel to make it have a longer trail.

Author:  Kyred [ Thu Sep 24, 2009 1:43 am ]
Post subject:  Re: DrawLine()

Geti wrote:
they are. you just have to write a function to do them yourself ;)
i do love my calculus though.

this could be made more efficient by using the velocity of a mopixel to make it have a longer trail.
Ugh...I really do not want to write a Riemann Sum script for Lua. Wouldn't be so bad if it were in C/C++, but not Lua. Same goes for Newton's Method for derivitives.

Author:  Daman [ Thu Sep 24, 2009 3:35 am ]
Post subject:  Re: DrawLine()

Kyred wrote:
Geti wrote:
they are. you just have to write a function to do them yourself ;)
i do love my calculus though.

this could be made more efficient by using the velocity of a mopixel to make it have a longer trail.
Ugh...I really do not want to write a Riemann Sum script for Lua. Wouldn't be so bad if it were in C/C++, but not Lua. Same goes for Newton's Method for derivitives.


riemann sums have absolutely nothing to do with this

look guys i can spew off buzzwords derp derp derivative factors of polynomial ellipsis using sigma additivity :cool: :cool: :cool: :cool: :cool: :cool: :cool: :cool: :cool:

Author:  Kyred [ Thu Sep 24, 2009 4:19 am ]
Post subject:  Re: DrawLine()

Daman wrote:
Kyred wrote:
Geti wrote:
they are. you just have to write a function to do them yourself ;)
i do love my calculus though.

this could be made more efficient by using the velocity of a mopixel to make it have a longer trail.
Ugh...I really do not want to write a Riemann Sum script for Lua. Wouldn't be so bad if it were in C/C++, but not Lua. Same goes for Newton's Method for derivitives.


riemann sums have absolutely nothing to do with this

look guys i can spew off buzzwords derp derp derivative factors of polynomial ellipsis using sigma additivity :cool:
A Riemann Sum is used to approximate an integral. Newton's method is used to approximate a derivative. Using either of these in Lua, you could adapt the DrawLine() method to efficiently drawing something such as a parabola, something that would be useful for showing the path a projectile will fly before you fire it.

So actually, Riemann Sums do have something to do with this.

Author:  ProjektTHOR [ Thu Sep 24, 2009 4:46 am ]
Post subject:  Re: DrawLine()

I think his point was "Stop being a Wikipedia scholar."

Author:  Daman [ Thu Sep 24, 2009 5:21 am ]
Post subject:  Re: DrawLine()

Kyred wrote:
A Riemann Sum is used to approximate an integral. Newton's method is used to approximate a derivative. Using either of these in Lua, you could adapt the DrawLine() method to efficiently drawing something such as a parabola, something that would be useful for showing the path a projectile will fly before you fire it.

So actually, Riemann Sums do have something to do with this.


uh nope it doesn't because you'd be a fuc­king idiot to use riemann sums to draw a trajectory

you don't find the area under a curve to draw a trajectory sorry you're completely wrong

Author:  Kyred [ Thu Sep 24, 2009 6:04 am ]
Post subject:  Re: DrawLine()

Daman wrote:
Kyred wrote:
A Riemann Sum is used to approximate an integral. Newton's method is used to approximate a derivative. Using either of these in Lua, you could adapt the DrawLine() method to efficiently drawing something such as a parabola, something that would be useful for showing the path a projectile will fly before you fire it.

So actually, Riemann Sums do have something to do with this.

uh nope it doesn't because you'd be a fuc­king idiot to use riemann sums to draw a trajectory
you don't find the area under a curve to draw a trajectory sorry you're completely wrong
You can integrate velocity with respect to time to get a position function.

The physics equation y = y0 + y0*t + 1/2*a*t^2 is created this way (integrate v = v0 + at with respect to 't'), which is an equation for trajectory when 'a' is negative. Plug in a projectile's velocity function into the integrand, and you will get a basic parabola to model the trajectory. Then you can use the line algorithm to draw the trajectory.

ProjektTHOR wrote:
I think his point was "Stop being a Wikipedia scholar."

For the record, I am currently in my 4th (and last :D) semester of calculus, and will be taking differential equations after that. I typed out all this from memory, since I am forced to use some of this stuff on almost a daily basis.

Author:  piipu [ Thu Sep 24, 2009 8:53 am ]
Post subject:  Re: DrawLine()

For the record, for loops can be used to calculate trajectories by using the s = s0 + v0 * t + 1/2 * a * t² formula thingy:
Image

Page 1 of 3 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/