Author Topic: Math Help  (Read 9165 times)

Offline Celledor

  • Moderator
  • Full Member
  • *****
  • Posts: 151
    • http://www.veus.se
Math Help
« on: February 03, 2010, 03:10:33 AM »
This is a topic where I will post math problems I need help with for diffrent functions, the first one is:

A way to find the center of multiple (2D and/or 3D) vectors.

Exampel: I have an array of positions (vectors), if they would form a circle I would get a point in the center.

Anyone know how to do this, (please don't post answer that you think is correct, onlu post if you know the answer) or have a good link?

Offline Moley

  • Jr. Member
  • **
  • Posts: 95
Math Help
« Reply #1 on: February 03, 2010, 06:11:34 AM »
first a question, do you have a way of getting the x,y,z out of the vectors?
what functions (operator+ ect.) can you perform...

and i'll get you one soulution
I HATE SPELLING!!!!!!
if i spell something or screw up grammer,
ignore it or tell me if you dont understand what i typed.

Offline Celledor

  • Moderator
  • Full Member
  • *****
  • Posts: 151
    • http://www.veus.se
Math Help
« Reply #2 on: February 03, 2010, 06:27:19 AM »
Quote
first a question, do you have a way of getting the x,y,z out of the vectors?
what functions (operator+ ect.) can you perform...
Yes I can get the x,y,z... y is used to represent height, x and z for ground position.

The  engine has a builtin math library with most common functions like add, subtract, cross product, scale etc.

In the end what I am trying to do is move the array(list) of vectors to a new position but keep their positsion realtive to eachother if you get what I mean. Getting the center of the vectors should be a part of the solution.

(Array of vectors + single vector = new array of vectors moved to the location of the single vector), it will be used to move a group of selected units.

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Math Help
« Reply #3 on: February 03, 2010, 07:58:26 AM »
It's the arithmetic mean of all the points' coordinates done for each plane and relative to the same origin. (Sorry, all I can offer right now is this)

Xm = (x1+x2+x3+...+xn)/n
Ym = (y1+y2+...+yn)/n
Zm = (z1+z2+...+zn)/n

Where Xm, Ym, Zm represent the coordinates of the center point and xk,yk,zk represent the coordinates of an individual point.
« Last Edit: February 03, 2010, 09:32:13 AM by Hidiot »
"Nothing from nowhere, I'm no one at all"

Offline Celledor

  • Moderator
  • Full Member
  • *****
  • Posts: 151
    • http://www.veus.se
Math Help
« Reply #4 on: February 03, 2010, 08:29:52 AM »
Okey, thanks will try this when I get home... arithmetic mean sounds like I should know this but what to say my brain practise some sort of selective memory.

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
Math Help
« Reply #5 on: February 03, 2010, 09:26:24 AM »
Hidiot forgot to say divided by n on those mean values
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Math Help
« Reply #6 on: February 03, 2010, 09:31:56 AM »
:CK9's:

I fixez.
"Nothing from nowhere, I'm no one at all"

Offline meatwad1666

  • Newbie
  • *
  • Posts: 25
Math Help
« Reply #7 on: February 03, 2010, 03:04:10 PM »
i got one.. whats 2 + 2?? no i jk

but i sadly failed math a wekk ago i couldnt under stand it
http://www.youtube.com/watch?v=tee0uZubcoA


its the only way to describe me and my friends

Offline Celledor

  • Moderator
  • Full Member
  • *****
  • Posts: 151
    • http://www.veus.se
Math Help
« Reply #8 on: February 03, 2010, 03:40:58 PM »
It worked just like I wanted, a few more fixes and I can release a new version.

Offline meatwad1666

  • Newbie
  • *
  • Posts: 25
Math Help
« Reply #9 on: February 03, 2010, 06:35:07 PM »
Quote
It worked just like I wanted, a few more fixes and I can release a new version.
sweet good luck (thumbsup)  
http://www.youtube.com/watch?v=tee0uZubcoA


its the only way to describe me and my friends

Offline Simpsonboy77

  • Full Member
  • ***
  • Posts: 168
Math Help
« Reply #10 on: February 05, 2010, 11:11:37 PM »
Hidiot's method works, but for very large lists it has a long runtime.

Rather than using EVERY point, you can use the axiom that 4 points define a sphere. I honestly don't have the time to derive it, but I have the time to google someone else deriving it. I used something similar when I needed to program a GPS for a robot.


A test program
http://local.wasp.uwa.edu.au/~pbourke/geom...m4/spheretest.c

Some info, but a poor proof.
http://home.att.net/~srschmitt/zenosamples...sphere4pts.html


If you have a genuine interest in how this works, just ask and I'll make a 2 page post on it. Its really cool because if you warp space and make it an ellipse, you can use the elliptical curves to aid prime number factorization. Its kinda odd that graphics are related to cryptology.
My tutorials
Part 1
Part 2
Part 3

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Math Help
« Reply #11 on: February 06, 2010, 12:35:16 AM »
Those links are about finding a sphere given 4 points on the sphere. I don't think this is very useful if you have a random collection of points, and you want to find the center. It might very well be that no two points are on a sphere of the same radius if you take the midpoint as the center.


It is a rather interesting thing to know about though.
 
« Last Edit: February 06, 2010, 12:36:43 AM by Hooman »

Offline Simpsonboy77

  • Full Member
  • ***
  • Posts: 168
Math Help
« Reply #12 on: February 06, 2010, 09:38:53 PM »
Oops my fault, I misinterpreted this line

"I have an array of positions (vectors), if they would form a circle I would get a point in the center."

I thought the positions already created a circle (and thus a sphere if 3 dimensions).

Yes, if the distribution of points is random, then you need to iterate through them all, just like Hidiot posted.  
My tutorials
Part 1
Part 2
Part 3

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Math Help
« Reply #13 on: February 07, 2010, 02:01:58 AM »
Well, Celledor did also say that he wants to use this to make units in formation keep their formation. And groups of units will rarely stay in a circle formation.
"Nothing from nowhere, I'm no one at all"

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
Math Help
« Reply #14 on: February 07, 2010, 02:31:10 AM »
aye, but it could help with the issues of variation in unit speeds
 
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Math Help
« Reply #15 on: February 07, 2010, 04:38:10 AM »
Does unit speed become a problem?

You're not going to keep the formation throughout the journey, especially due to the terrain and its obstacles.

You could also reduce the speed of the group to the speed of the slowest unit.
"Nothing from nowhere, I'm no one at all"

Offline WooJoo

  • Jr. Member
  • **
  • Posts: 90
Math Help
« Reply #16 on: February 07, 2010, 10:43:16 AM »
the first game that used this kind of technic was warcraft 3 where a group of selected units would travel with the speed of the slowest group unit

if it where to be implemented it would be cool so you dont need to form homo squads which have all the same movement speed and need to manage 3 different attack squads at once

Offline Celledor

  • Moderator
  • Full Member
  • *****
  • Posts: 151
    • http://www.veus.se
Math Help
« Reply #17 on: February 07, 2010, 05:06:53 PM »
The thing I have left now is to  refine the functions that make sure the units don't collide or gets stuck with each other, not an easy task I learned but with only a few simple rules they move in what looks like a intelligent and organized way.... but also trap themselves in loops where no one moves from thime to time.

Right now the only moving code is the one where they try to keep the formation they had at their original position, while moving they just try to find the shortest path to the destination and reform the formation. But more types of movement will be available in the end.

Travel with the speed of the slowest group unit will be a function in the game as this is not much work to do.

All this will make the units move in a different way than op2 but I think it for the better, improvements to movment from research can still be implemented and the player shouldn't need to babysit the units all the time when they move from A to B.
 

Offline Celledor

  • Moderator
  • Full Member
  • *****
  • Posts: 151
    • http://www.veus.se
Math Help
« Reply #18 on: February 08, 2010, 04:49:26 PM »
Okej, having serious problems making them not get stuck on eachother while trying to move away... any one know any good links to how others have solved this, have searched but not found anything good that I can acctually use.

Offline WooJoo

  • Jr. Member
  • **
  • Posts: 90
Math Help
« Reply #19 on: February 08, 2010, 04:59:04 PM »
in theory you need to set up a grid for the selected units which should move from a to b and these units get all a grid point where each grid point needs a minimal distance to the next grid point? + there would be an maximum grid distance which is the formation it self which the units should favor ...

is that the logic your searching? :P
« Last Edit: February 08, 2010, 05:00:37 PM by WooJoo »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Math Help
« Reply #20 on: February 08, 2010, 05:32:24 PM »
I don't think there is much reason to use a tile grid for movement. It's been used in the past for games like Outpost 2 and Warcraft 2. But games like Starcraft had pixel level movement. When you think about it, there really is no big reason to have tile based movement for mobile units. It mostly only makes sense to align buildings along tiles. More so in Outpost style games that have tubes, although, that's mostly because the tubes are full tiles.


I assume you want some sort of flocking with collision avoidance? I'm not too sure what's out there off the top of my head, but I've come across a few things here and there. Maybe I can dig something up.
 

Offline WooJoo

  • Jr. Member
  • **
  • Posts: 90
Math Help
« Reply #21 on: February 09, 2010, 12:23:20 AM »
i meant 3d grids that have 3 axes y,x,z ...

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
Math Help
« Reply #22 on: February 09, 2010, 09:33:42 AM »
only when using cartesean coordinates, otherwise your coordinates bemoce much more interesting...
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names