## Any help with geometry?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Gerrit
Prole
Posts: 46
Joined: Wed Mar 25, 2009 7:40 pm

### Any help with geometry?

Hi there!

I'm playing around with Löve now for a couple of days and there are some obstacles I can't solve myself (at this moment) or I have no idea where to look for answers. So, my first problem was that I had a point, an angle and the speed of an object. To get the new coordinates I tried to use 2 triangles to find out the height difference between the new and the old point. This is how I tried it:

Downsides:
- Needs a big IF loop to determine how big our angle is because we need to change the parameters a bit. Means one if we're going straight Up (just y - speed) or between 1 and 89 degrees and so on.
- Doesn't really work with small speeds like 2 pixels

Now I use physics to move stuff around but I'm still not happy about that fact as I won't use physics for everything. Then I ran into my next problem which I can't solve with the built in physics afaik. My objects have to change their course on occasion so they can move in a circle or similar. Which brings me to the point:

How can I find out the coordinates on a given path to move my objects/sprites along it?

I could just use a line for everything that moves into one direction or a circle to move stuff in a circle. Or (if you help me with the first two first) follow a polygon line. The only game making experience was with Game Maker on windows more then 4 years ago and I didn't need to do stuff like this because I could define a path objects followed.

So, hit me with the math or some links. I'm not new to programming, but I do mostly desktop applications so I'm not that good with geometry stuff (yet). And for the first post here I have to say: Keep up the good work with Löve, it's really easy to use and Lua is quick to learn. It really feels like programming in Game Maker again, except without the helpers on your side there (which help you with basic stuff like creating graphics/objects, move them, making levels). And Löves big plus is that it's platform independent and free

PS: Sorry for any mistakes, you can keep them if you like English is only my second language.

osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

### Re: Any help with geometry?

Trigonometry and linear algebra are important for the 2d geometry.

I might have misunderstood you, but I'm not sure you're familiar with sin (sinus) or cos (cosinus). That should offer a simpler solution to your problem.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.

Kaze
Party member
Posts: 189
Joined: Sat Jul 19, 2008 4:39 pm
Location: Dublin, Ireland

### Re: Any help with geometry?

osuf oboys wrote:Trigonometry and linear algebra are important for the 2d geometry.

I might have misunderstood you, but I'm not sure you're familiar with sin (sinus) or cos (cosinus). That should offer a simpler solution to your problem.
This.
First, get the direction: (ang is in radians)

Code: Select all

local dir_x = math.cos( ang )
local dir_y = math.sin( ang )
Then multiply the direction by the distance you want to move it, and add it to your original position. Also added deltatime.

Code: Select all

local new_x = old_x + (dir_x * speed * dt)
local new_y = old_y + (dir_y * speed * dt)

Gerrit
Prole
Posts: 46
Joined: Wed Mar 25, 2009 7:40 pm

### Re: Any help with geometry?

Well, thank you Sir!
This is what I was looking for. It's easier than I thought and really fast. At least in 640x480. I guess to animate a lot of objects/bullets in 1280x720 I need to use love.physics. But that's far away. I'm still working on a prototype. Next thing would be to find the exact numbers between movement & rotation to rotate objects (in a circle) while this circle expands. Did it with a slowly rotating circle but if I go faster (without the loop) they will come back. Looks actually pretty nice, like a screensaver..

But thanks again for this and for the fast response

@osuf oboys
Ya, sinus and cosinus. It's been a while since I used geometry. I guess I'll have to read about that again to get my project running. This won't be the last problem of that kind. I can feel it. Maybe I can get my hands on some sort of book for 2d game development. Might be a real timesaver as the most information about pure math isn't really easy to read.

### Who is online

Users browsing this forum: No registered users and 31 guests