Raised This Month: $ Target: $400
 0% 

Math Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
VEN
Veteran Member
Join Date: Jan 2005
Old 06-11-2006 , 12:58  
Reply With Quote #1

True, true, in fact this formula is one of the basics of the geometry. :)
VEN is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 06-11-2006 , 14:45  
Reply With Quote #2

Thanks I will try that.
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
nightscreem
Veteran Member
Join Date: Jul 2004
Location: Belgium
Old 06-11-2006 , 14:52  
Reply With Quote #3

LOL just learned that in school sin, cos, tan and such
it's fun to see it here
__________________
- Bye bye!
nightscreem is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 06-13-2006 , 00:00  
Reply With Quote #4

Quote:
Originally Posted by Greenberet
atm i only know one way:

you have an triangle here.

A = Attacker
B = AIM
C = VICTIM

a = distance(aim, victim)
b = distance(attacker, victim)
c = distance(attacker, aim )

hc = distance from line to victim

so something like this could work:

s = (a+b+c)/2
area = sqrt(s *(s-a)*(s-b)*(s-c))

area = c * hc /2
hc = 2 * area / c

maybe this is not the best way, but it is a way ;)
Im really bad at math. This stock is based on your formula

Code:
stock get_user_distance(iAtkOrigin[3], iAim[3], iVicOrigin[3]) {     new a = get_distance(iAim, iVicOrigin)     new b = get_distance(iAtkOrigin, iVicOrigin)     new c = get_distance(iAtkOrigin, iAim)         new s = (a + b + c) / 2     new area = sqroot(s * (s - a) * (s - b) * (s - c))     new hc = 2 * area / c     return hc }

Code:
        new target = Players[i]         new iOrigin[3][3]         get_user_origin(id, iOrigin[0], 0)         get_user_origin(id, iOrigin[1], 3)         get_user_origin(target, iOrigin[2], 0)                 new iDistance = get_user_distance(iOrigin[0], iOrigin[1], iOrigin[2])         if(iDistance <= 75)         {             new name[32]     get_user_name(target, name, 31)     client_print(id, print_chat, "Missed %s", name)             }

It returned everyone.
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
KoST
Senior Member
Join Date: Jul 2005
Old 06-13-2006 , 01:01  
Reply With Quote #5

try this:

Code:
stock get_user_distance(Float:me[3],Float:aim[3],Float:vic[3]) {     new Float:me_aim[3]     subVec(aim,me,me_aim) // this creates a vector from me to aimpoint         new Float:me_vic[3]     subVec(vic,me,me_vic)  // a vector from me to victim         new Float:me_vic_len=getVecLen(me_vic) // get length of vector         new Float:angle=floatacos(vectorProduct(me_aim,me_vic)/(getVecLen(me_aim)*me_vic_len),1)  // determine angle between vectors return degrees       if (angle<90.0){ // if victim is on front of me         return floatround(me_vic_len*floatsin(angle,1)) // return distance     }else return -1; // return -1 if victim is behind me }   public subVec(Float:Vec1[3],Float:Vec2[3],Float:Ret[3]){     Ret[0]=Vec1[0]-Vec2[0]     Ret[1]=Vec1[1]-Vec2[1]     Ret[2]=Vec1[2]-Vec2[2] } public Float:vectorProduct(Float:Vec1[3],Float:Vec2[3]){     return Vec1[0]*Vec2[0]+Vec1[1]*Vec2[1]+Vec1[2]*Vec2[2] } public Float:getVecLen(Float:Vec[3]){     new Float:VecNull[3]={0.0,0.0,0.0}     new Float:len=get_distance_f(Vec,VecNull)     return len }
__________________
KoST is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 06-13-2006 , 01:20  
Reply With Quote #6

Okay, Just need to fix this tag mismatch.

Code:
    new distance     if(angle<90.0) // if victim is on front of me           distance = floatround(me_vic_len*floatsin(angle,1)) // return distance <-- Tag mismatch     else           distance = -1; // return -1 if victim is behind me       return distance
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 06-13-2006 , 02:26  
Reply With Quote #7

try
Code:
floatround(me_vic_len*floatsin(angle,1.0))
Freecode is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 06-13-2006 , 02:56  
Reply With Quote #8

For the mode it has to be either radian, degrees, or grades.

Code:
stock get_user_distance(Float:me[3], Float:aim[3], Float:vic[3]) {     new Float:me_aim[3]     subVec(aim, me, me_aim)     new Float:me_vic[3]     subVec(vic, me, me_vic)     new Float:me_vic_len = getVecLen(me_vic)     new Float:angle = floatacos(vectorProduct(me_aim, me_vic) / (getVecLen(me_aim) * me_vic_len), 1)     if(angle < 90.0)         return floatround( me_vic_len * floatsin(angle, radian) )     return -1 }
Code:
enum anglemode {
	radian = 0,
	degrees,
	grades
}
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
KoST
Senior Member
Join Date: Jul 2005
Old 06-13-2006 , 10:57  
Reply With Quote #9

hmm, you should use degrees with floatsin() since floatacos() returns degrees (in this example):

Code:
stock get_user_distance(Float:me[3], Float:aim[3], Float:vic[3]) {     new Float:me_aim[3]     subVec(aim, me, me_aim)     new Float:me_vic[3]     subVec(vic, me, me_vic)     new Float:me_vic_len = getVecLen(me_vic)     new Float:angle = floatacos(vectorProduct(me_aim, me_vic) / (getVecLen(me_aim) * me_vic_len), degrees)     if(angle < 90.0)         return floatround( me_vic_len * floatsin(angle, degrees) )     return -1 }


the only problem is the following:
Code:
|
|  o <- Victim
|
|
<Aim>
|
| 
|
|
|
<Me>
you could check if the (angle between aim_me and aim_vic) <=90.0 to avoid this
__________________
KoST is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 06-13-2006 , 13:38  
Reply With Quote #10

Quote:
Originally Posted by KoST
hmm, you should use degrees with floatsin() since floatacos() returns degrees (in this example):

Code:
stock get_user_distance(Float:me[3], Float:aim[3], Float:vic[3]) {     new Float:me_aim[3]     subVec(aim, me, me_aim)     new Float:me_vic[3]     subVec(vic, me, me_vic)     new Float:me_vic_len = getVecLen(me_vic)     new Float:angle = floatacos(vectorProduct(me_aim, me_vic) / (getVecLen(me_aim) * me_vic_len), degrees)     if(angle < 90.0)         return floatround( me_vic_len * floatsin(angle, degrees) )     return -1 }


the only problem is the following:
Code:
|
|  o <- Victim
|
|
<Aim>
|
| 
|
|
|
<Me>
you could check if the (angle between aim_me and aim_vic) <=90.0 to avoid this
Thanks KoST, Freecode, and v3x, it's now working properly.
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:03.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode