POV-Ray : Newsgroups : povray.tools.general : sin cos delta Server Time: 19 Jun 2019 06:41:15 GMT
 sin cos delta (Message 1 to 7 of 7)
 From: def gsus- Subject: sin cos delta Date: 29 May 2007 12:50:01 Message:
hi everyone,
don't know where to post this exactly.
want to do some crowd simulation externally and have this prob.

every dude has property X,Y, SPEED and DIRECTION.
direction ranging from 0..1
they are update like
x = x + speed * sin(direction * 2*pi)
y = y + speed * cos(direction * 2*pi)

now i want people be attracted by others and move in their direction
so i'd need something to get the direction vector back into the direction
variable
i calc the delta, say dx and dy, between the dude and the dude attracted to,
and normalized to 1
but i cannot figure the final step
newdir = ....
maybe something with arcsin/arccos?
it should be just the reverse of the equation above.
it tried newdir = (arcsin(dx)+arccos(dy))/(2*pi) and stuff like this but not
with very satisfactory results.
thanks for help in advance. i know there are some true mathematicians here
;)
 From: Warp Subject: Re: sin cos delta Date: 29 May 2007 13:29:46 Message: <465c2aca@news.povray.org>
atan2() is the function you are looking for.

--
- Warp
 From: Roman Reiner Subject: Re: sin cos delta Date: 29 May 2007 13:35:01 Message:
You'd probably need to use atan(dy/dx). however the usage of atan is a
little problematic since dx is not necessarily unequal zero and it's
difficult to get exact angles since e.g. atan(1) could be both 45° or 225°
(which is the opposite direction).

I recommend using one vector for the direction and speed (with the speed
being the length of the direction vector) and one for the location. So

x = x + speed * sin(direction * 2*pi)
y = y + speed * cos(direction * 2*pi)

you'd have

Position = Position+Direction ( with Direction = vnormalize(<dx,dy>)*Speed )

if you need to access the former x and y components use

x=Position.x
y=Position.y

Hope that helps!
Regards Roman
 From: def gsus- Subject: Re: sin cos delta Date: 29 May 2007 14:45:02 Message:
> I recommend using one vector for the direction and speed

yeah, skipped to that, makes it much easier--- thanks
 From: Warp Subject: Re: sin cos delta Date: 29 May 2007 15:07:11 Message: <465c419f@news.povray.org>
Roman Reiner <lim### [at] gmxde> wrote:
> You'd probably need to use atan(dy/dx). however the usage of atan is a
> little problematic since dx is not necessarily unequal zero and it's
> difficult to get exact angles since e.g. atan(1) could be both 45° or 225°
> (which is the opposite direction).

That's exactly why atan2() exists.

--
- Warp
 From: def gsus- Subject: Re: sin cos delta Date: 29 May 2007 16:10:01 Message:
>   That's exactly why atan2() exists.
>
cool, didnt notice that func.
it's even in the delphi math lib--
thanks alot--now i changed the code anyway to direction vectors but the
next time---
 From: Roman Reiner Subject: Re: sin cos delta Date: 29 May 2007 16:15:01 Message:
Warp <war### [at] tagpovrayorg> wrote:
>   That's exactly why atan2() exists.
>                                                           - Warp

Didn't know that either. Thanks for the tip!

Regards Roman