Skip to main content
GameDev.net gamedev.net
🔒 Locked

variation of angle based on the distance

Started by gorogoro Aug 30, 2006 at 4:26 AM 4 replies 1k views
Original Post
gorogoro
gorogoro
Hi! I need a function that gives me an angle based on the distance between two points. As longer the distance, shorter should be the angle. Lets say something like: i have a distance of 10000 then the Dot should be something like 0.93 if the distance is 10 then the Dot could be 0.7 P.E. Could anyone help me finding a good method for this? Square distance is a good bonus ;) Ideally the Dot should vary between 0.7 and 1. As bigger the input (the distance) the returning value should be closer to 1 :). Thanks
Zakwayda
Zakwayda
What is the Dot; the dot product? Also, what is P.E.?

You might need to give some more info, as it's not particularly clear (to me at least) what kind of function you're looking for.
gorogoro
gorogoro
Quote:
Original post by jyk
What is the Dot; the dot product? Also, what is P.E.?

You might need to give some more info, as it's not particularly clear (to me at least) what kind of function you're looking for.


Yes I'm talking about the dot product, or if you prefer the Cos of the angle.
cos(angle).

P.E. its for example :) sorry for my bad explanation.

The function is something like:

f(d) = alpha

where d is a float (in my case a distance between two points), and alpha is another float.

As bigger the d value, the alpha should be closer to 1, as smaller the d value the alpha should be closer to 0.7.

:)
gorogoro
gorogoro
Ok! I've found it!

It's something like this:

f(x) = x / (n + x).

Where n is a constant.

Then I clamp the output between the values I want
JohnBolton
JohnBolton
What about this?
    a = pi/2 - atan( d ) 
If d is infinity, then a = 0 and Dot = cos a = 1. If d = 0, then a = pi/2 and Dot = cos a = 0.

The same result without using trig is this:
    Dot = d / sqrt( 1 + d<sup>2</sup> ) 
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
gorogoro
gorogoro
Quote:
Original post by JohnBolton
What about this?
    a = pi/2 - atan( d ) 
If d is infinity, then a = 0 and Dot = cos a = 1. If d = 0, then a = pi/2 and Dot = cos a = 0.

The same result without using trig is this:
    Dot = d / sqrt( 1 + d<sup>2</sup> ) 


Thanks for the help!


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.