POV-Ray : Newsgroups : povray.tools.general : sin cos delta Server Time
22 Dec 2024 01:27:37 EST (-0500)
  sin cos delta (Message 1 to 7 of 7)  
From: def gsus-
Subject: sin cos delta
Date: 29 May 2007 08:50:01
Message: <web.465c207f1626778dbd61fc7e0@news.povray.org>
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
;)


Post a reply to this message

From: Warp
Subject: Re: sin cos delta
Date: 29 May 2007 09:29:46
Message: <465c2aca@news.povray.org>
atan2() is the function you are looking for.

-- 
                                                          - Warp


Post a reply to this message

From: Roman Reiner
Subject: Re: sin cos delta
Date: 29 May 2007 09:35:01
Message: <web.465c2b8f6b42587279d2ccf20@news.povray.org>
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

(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
instead of

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


Post a reply to this message

From: def gsus-
Subject: Re: sin cos delta
Date: 29 May 2007 10:45:02
Message: <web.465c3b3e6b425872bd61fc7e0@news.povray.org>
> I recommend using one vector for the direction and speed

yeah, skipped to that, makes it much easier--- thanks


Post a reply to this message

From: Warp
Subject: Re: sin cos delta
Date: 29 May 2007 11: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

> (which is the opposite direction).

  That's exactly why atan2() exists.

-- 
                                                          - Warp


Post a reply to this message

From: def gsus-
Subject: Re: sin cos delta
Date: 29 May 2007 12:10:01
Message: <web.465c503f6b425872bd61fc7e0@news.povray.org>
>   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---


Post a reply to this message

From: Roman Reiner
Subject: Re: sin cos delta
Date: 29 May 2007 12:15:01
Message: <web.465c50ae6b42587279d2ccf20@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
>   That's exactly why atan2() exists.
>                                                           - Warp

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

Regards Roman


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.