math equation
Displaying 1-11 of 11 total.
1
RageCage
|
ok, I know there are other ways to do this that are much more straight forward but I'm hell bent on using an equation.
Right now I'm making a tactics BS that is radius based. In order to keep the entity from going out of bounds of the circle I have an equation that checks his position in relation to the center of the circle.
Basicly: sqrt( (x-h)^2 + (y-k)^2 )= r
I've developed an equation that will keep the character on the same slope and just put him back where he belongs.
x={2h+ sqrt[ 4h^2 +4(1+s^2)(k^2+r^2+h^2) ] }
/ [ -2(1+s^2) ]
That equation was made from the fact that
the slope s=y/x
and
y= sqrt[ r^2 - (x-h)^2 ] +k
thus:
s= { sqrt[ r^2 - (x-h)^2 ] +k } /x
solve for x and you get my uber equation. After I've found x I can plug it into:
y= sqrt[ r^2 - (x-h)^2 ] +k
-------
Now as far as I can tell, it all works. Unfortunately, because verge doesnt deal with decimals, I have to 'bitshift?' I think they call it? I dunno... basicly:
s is less than or equal to 1 and I need to make it *100 and compensate so I get the same answer for y
Posted on 2004-04-19 23:55:56 (last edited on 2004-04-20 04:11:29)
|
basil
|
I (think I) follow the maths there, but I don't quite understand the purpose of your final equation. What you do with it, what slope you're talking about, and how it all pertains to keeping an entity within a circular bound. Care to elaborate at all?
Posted on 2004-04-20 11:58:25
|
RageCage
|
sure.
the equation is for a tactics system where the player can move within a circle. If the player tries to go out of the circle, I need to push him back into the circle.
Currently I have a working method thats basicly:
while(entity is outside circle){
x--;
y--;
}
but I cant stand using that because its very shoddy and I know I can use an equation to simply put him in his place.
thus why I made the equation for finding X.
the slope is simply the relationship between x and y. its a way of keeping the angle with the circle the same. In math class they probably refered to it as rise/run or y/x. By using the slope in my equation I can find just x with out knowing the y. And obviously when I find x, I can easily find y.
Ex:
circle_x=5
circle_y=7
circle_r=10
ent_x=20
ent_y=13
slope=ent_x/ent_y
what is the maximum ent_x and ent_y can equal in order to have the same slope and be within the circle?
using my equation I get:
ent_x=5.85
ent_y=16.96
--------
NOW -ASSUMING- that all my math is flawless, I need to integrate the equation into verge. probelm=verge doesnt do decimals. slope is going to be in decimals and the x and y values might need to be rounded. thus my problem.
Posted on 2004-04-20 14:04:07
|
RageCage
|
ok well today I figured out just hopw much of a pain it would be to do what I wanted, but I found a new method so its all good. ^_^
I cant believen I went though all that and it was worthless -_-
Posted on 2004-04-20 22:54:51 (last edited on 2004-04-20 22:57:31)
|
RageCage
|
AHHH! how are you supposed to use atan without being able to use decemals!? -_-
Posted on 2004-04-20 23:35:34
|
RageCage
|
screw it... back to my old system...
Posted on 2004-04-21 00:14:40
|
Troupe
|
I just had to point out that you are talking to yourself.
Posted on 2004-04-21 00:22:12
|
basil
|
(having a mission of a time getting this post to format right...)
So you want to move something inside a circle while still maintaining the angle it makes with the center of the circle, if my understanding is correct. In which case I have no idea how your first equation would have helped to that end, but the fact that you're now talking about arctans is a little more heartening.
I still haven't quite figured out how atan works, and all my attempts to test leave me more confused. I think that's one for the docs to sort out for me. In any case, if it's giving you grief you can try Mythrils arctan script, which if you can't find elsewhere is in LOS.vc in the dirty tactics demo.
In any case, wouldn't it be easier to just make sure the entity doesn't leave the circle in the first place? i.e
Posted on 2004-04-21 04:03:18 (last edited on 2004-04-21 04:07:25)
|
basil
|
if(left && (entity.x-circlecenter.x)^2 + (entity.y-circlecenter.y)^2 [IS LESS THAN] radius^2)
go left;
else
unpress(left);
of course, it depends how the rest of your system is set up. Just my 2 cents.
And apparently I can't use less than signs. There you go then.
Posted on 2004-04-21 04:10:06
|
RageCage
|
will unpress(left) actually not let the player go left?
and as for atan()... the reason I decided to give up is you have to compensate for verge becuase it does some kind of fixed point crap. thus arcTan(y/x) = atan( x*65536 /y )
and then when you do cos, you have to do like...
cos(60)/65536 or something along that line. but then if you do that then you get 0 back because its a decimal. so you have to /655 but or something... anyway long story short I cant find a accurate enough way of bitshifting successfully.
Posted on 2004-04-21 13:46:48
|
Troupe
|
The command for less than signs is &.lt.; minus the periods (gt for greater than).
I think what you just said up there is what he was trying to avoid because it looks bad.
Posted on 2004-04-21 13:48:25
|