POV-Ray : Newsgroups : povray.tools.general : sin cos delta Server Time17 Sep 2024 12:09:48 EDT (-0400)
 sin cos delta (Message 1 to 7 of 7)
 From: def gsus- Subject: sin cos delta Date: 29 May 2007 08:50:01 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.465c207f1626778dbd61fc7e0%40news.povray.org",
"dateCreated": "2007-05-29T12:50:01+00:00",
"datePublished": "2007-05-29T12:50:01+00:00",
"author": {
"@type": "Person",
"name": "def gsus-"
}
}
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 09:29:46 Message: <465c2aca@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#465c2aca%40news.povray.org",
"dateCreated": "2007-05-29T13:29:46+00:00",
"datePublished": "2007-05-29T13:29:46+00:00",
"author": {
"@type": "Person",
"name": "Warp"
}
}
atan2() is the function you are looking for.

--
- Warp
```
 From: Roman Reiner Subject: Re: sin cos delta Date: 29 May 2007 09:35:01 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.465c2b8f6b42587279d2ccf20%40news.povray.org",
"dateCreated": "2007-05-29T13:35:01+00:00",
"datePublished": "2007-05-29T13:35:01+00:00",
"author": {
"@type": "Person",
"name": "Roman Reiner"
}
}
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

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 10:45:02 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.465c3b3e6b425872bd61fc7e0%40news.povray.org",
"dateCreated": "2007-05-29T14:45:02+00:00",
"datePublished": "2007-05-29T14:45:02+00:00",
"author": {
"@type": "Person",
"name": "def gsus-"
}
}
> 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 11:07:11 Message: <465c419f@news.povray.org>
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#465c419f%40news.povray.org",
"dateCreated": "2007-05-29T15:07:11+00:00",
"datePublished": "2007-05-29T15:07:11+00:00",
"author": {
"@type": "Person",
"name": "Warp"
}
}
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
```
 From: def gsus- Subject: Re: sin cos delta Date: 29 May 2007 12:10:01 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.465c503f6b425872bd61fc7e0%40news.povray.org",
"dateCreated": "2007-05-29T16:10:01+00:00",
"datePublished": "2007-05-29T16:10:01+00:00",
"author": {
"@type": "Person",
"name": "def gsus-"
}
}
>   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 12:15:01 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.465c50ae6b42587279d2ccf20%40news.povray.org",
"dateCreated": "2007-05-29T16:15:01+00:00",
"datePublished": "2007-05-29T16:15:01+00:00",
"author": {
"@type": "Person",
"name": "Roman Reiner"
}
}
Warp <war### [at] tagpovrayorg> wrote:
>   That's exactly why atan2() exists.
>                                                           - Warp

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

Regards Roman
```