View unanswered posts | View active topics It is currently Fri Dec 27, 2024 10:42 pm



Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
 DrawLine() 
Author Message
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Tue Sep 22, 2009 12:52 am
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: DrawLine()
I know just how to express my opinion on this;

:?:


Tue Sep 22, 2009 12:58 am
Profile WWW
Banned
User avatar

Joined: Tue Feb 27, 2007 4:05 pm
Posts: 2527
Reply with quote
Post Re: DrawLine()
Its how to draw a line with Lua.


Tue Sep 22, 2009 1:40 am
Profile YIM
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: DrawLine()
More specifically it's Bresenham's line algorithm, in Lua.
http://en.wikipedia.org/wiki/Bresenham_line_algorithm


Tue Sep 22, 2009 1:43 am
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post 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 187 times
Tue Sep 22, 2009 4:09 am
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Tue Sep 22, 2009 4:54 am
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Re: DrawLine()
Now if only Lua had support for derivatives and integrals, then I'd be happy:P.


Tue Sep 22, 2009 7:18 pm
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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.


Wed Sep 23, 2009 7:06 am
Profile WWW
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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.


Thu Sep 24, 2009 1:43 am
Profile
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post 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:


Thu Sep 24, 2009 3:35 am
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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.


Thu Sep 24, 2009 4:19 am
Profile
Banned
User avatar

Joined: Tue Feb 27, 2007 4:05 pm
Posts: 2527
Reply with quote
Post Re: DrawLine()
I think his point was "Stop being a Wikipedia scholar."


Thu Sep 24, 2009 4:46 am
Profile YIM
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post 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


Thu Sep 24, 2009 5:21 am
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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.


Thu Sep 24, 2009 6:04 am
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post 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


Thu Sep 24, 2009 8:53 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 32 posts ]  Go to page 1, 2, 3  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.067s | 15 Queries | GZIP : Off ]