This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

[Ayuda] Usar calculo matematico en Pawn


  
 
 
Thread Tools Display Modes
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viña del Mar, Chile
Old 07-04-2012 , 21:25   Re: [Ayuda] Usar calculo matematico en Pawn
#11

Distancias entre 2 lineas es lo mas cercano, aunque no entiendo para que la finalidad. Buscando un metodo de hallar una interseccion de 2 lineas en 3 dimensiones, es una posiblidad minima de que ocurra un caso asi y que acierte.
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
LARP
Senior Member
Join Date: Aug 2008
Location: Santiago, Chile
Old 07-04-2012 , 22:00   Re: [Ayuda] Usar calculo matematico en Pawn
#12

Quote:
Como dije, si puedes primero copiar y pegar acá mi respuesta del otro post.

Agrego que puedes revisar un post de metalicross en donde tambien respondi una pregunta acerca de rectas en el espacio vectorial(r3) y ahi si dejé código.

Ahora estoy fuera de mi casa a travez de un celular, llego el sábado a mi casa.
Aqui esta.

Code:
[==Line L1==]
Points
A(x1, y1, z1)    // Could be Start Point
B(x2, y2, z2)    // Could be End Point

Vector Direction
v = A - B

Vector Equation
A + tV     // t belongs to the real numbers


[==Line L2==]
Points 
P(x1, y1, z1)    // Could be Start Point
Q(x2, y2, z2)    // Could be End Point

Vector Direction
w = P - Q

Vector Equation
P + sw     // s belongs to the real numbers


[==Intersection of two lines L1 and L2==]
A + tv = P + sw

Equations
tv1 - sw1 = Q1 - P1
tv2 - sw2 = Q2 - P2
tv3 - sw3 = Q3 - P3

Just need to solve the unknowns t and s.

If there are solutions for t and s so that the equations of L1 and L2 are equal 
    - there are intersections between the lines.

else 
    - no intersection between the lines
Este post?
http://forums.alliedmods.net/showthread.php?t=186801

Lo revisare en detalle, gracias
__________________
------


Last edited by LARP; 07-04-2012 at 22:06.
LARP is offline
Destro-
Veteran Member
Join Date: Jun 2010
Location: $me->location();
Old 07-06-2012 , 12:41   Re: [Ayuda] Usar calculo matematico en Pawn
#13

Podrías decir el uso exacto ?,para que lo usarías.
__________________
Destro- is offline
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 07-13-2012 , 19:44   Re: [Ayuda] Usar calculo matematico en Pawn
#14

Ahora no puedo en Pawn
Code:
#include <iostream>
using namespace std;

main()
{
      float vecA[3], vecB[3], vecC[3], vecD[3]; 
      float vecDirec1[3], vecDirec2[3];
      
      // Linea L1
      // Punto A (x0, y0, z0)
      cout << "Enter the coordinates for A"; // VecStart
      cin >> vecA[0] >> vecA[1] >> vecA[2];
      // Punto B (x1, y1, z1)
      cout << "Enter the coordinates for B: "; // VecEnd
      cin >> vecB[0] >> vecB[1] >> vecB[2];
      
      // Linea L2
      // Punto C (x2, y2, z2)
      cout << "Enter the coordinates for C: "; // VecStart
      cin >> vecC[0] >> vecC[1] >> vecC[2];
      // Punto D (x3, y3, z3)
      cout << "Enter the coordinates for D: "; // VecEnd
      cin >> vecD[0] >> vecD[1] >> vecD[2];
      
      // Vector Dirección V1 = A - B
      vecDirec1[0] = vecA[0] - vecB[0];
      vecDirec1[1] = vecA[1] - vecB[1];
      vecDirec1[2] = vecA[2] - vecB[2];
      
      // Vector Dirección V2 = C - D
      vecDirec2[0] = vecC[0] - vecD[0];
      vecDirec2[1] = vecC[1] - vecD[1];
      vecDirec2[2] = vecC[2] - vecD[2];
      
      // Intersección entre 2 lineas L1 y L2
      // (V1 × V2) * AC
      // Producto Cruz
      //             | i   j   k |
      // |V1 x V2| = |V11 V12 V13| = i - j + k
      //             |V21 V22 V23|
      float vecCruz[3], vecAC[3], Total;
      vecCruz[0] = (vecDirec2[1] * vecDirec1[2]) - (vecDirec1[1] * vecDirec2[2]); // (V22*V13-V12*V23)i
      vecCruz[1] = -((vecDirec2[0] * vecDirec1[2]) - (vecDirec1[0] * vecDirec2[2])); // -(V21*V13-V11*V23)j
      vecCruz[2] = (vecDirec2[0] * vecDirec1[1]) - (vecDirec1[0] * vecDirec2[1]); // (V21*V13-V11*V22)k
      // Vector AC
      vecAC[0] = vecC[0] - vecA[0];
      vecAC[1] = vecC[1] - vecA[1];
      vecAC[2] = vecC[2] - vecA[2];
      
      Total = vecAC[0] * vecCruz[0] + vecAC[1] * vecCruz[1] + vecAC[2] * vecCruz[2];
      
      if(Total)
      {
            cout << "No Intersectan" << endl << endl;
      }
      else
      {
            cout << "Intersectan" << endl << endl;
      }
      system("pause");
}
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).

gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 07-13-2012 , 19:50   Re: [Ayuda] Usar calculo matematico en Pawn
#15

Quote:
Originally Posted by meTaLiCroSS View Post
Distancias entre 2 lineas es lo mas cercano, aunque no entiendo para que la finalidad. Buscando un metodo de hallar una interseccion de 2 lineas en 3 dimensiones, es una posiblidad minima de que ocurra un caso asi y que acierte.
Y en el caso de que estas líneas se muevan por el mapa o sean entidades que tengan un laser ó rayos X, puede ser muchas cosas que quizás necesite calcular si se tocan.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).


Last edited by gladius; 07-13-2012 at 19:51.
gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
LARP
Senior Member
Join Date: Aug 2008
Location: Santiago, Chile
Old 07-13-2012 , 21:51   Re: [Ayuda] Usar calculo matematico en Pawn
#16

No me resulta, te muestro el code que hice para ver si esta bien:

Code:
    if(Hook[id] && !canThrowHook[id]){
        //Linea L1
        /*
        Punto A (x0,        y0,        z0)
        vecA    (vecA[0],    vecA[1],    vecA[2])
            
        Punto B (x1,        y1,        z1)
        vecB    (vecB[0],    vecB[1],    vecB[2])
        */
        static Float:vecA[3], Float: vecB[3]
        pev(id, pev_origin, vecA)
        pev(Hook[id], pev_origin, vecB)
        
        //Buscar otras lineas y hacer el calculo
        for (new i=1; i<=32; i++)
        {
            
            if (pev_valid(Hook[i])){
                new uid = pev(Hook[i], pev_owner)
                if(uid != id){
                    //Linea L2
                    /*
                    Punto C (x2,        y2,        z2)
                    vecC    (vecC[0],    vecC[1],    vecC[2])
                        
                    Punto D (x3,        y3,        z3)
                    vecD    (vecD[0],    vecD[1],    vecD[2])
                    */
                    static Float:vecC[3], Float: vecD[3]
                    pev(uid, pev_origin, vecC)
                    pev(Hook[i], pev_origin, vecD)
                    
                    // Vector Dirección V1 = A - B
                    static Float:vecDirec1[3]
                    vecDirec1[0] = vecA[0] - vecB[0]
                    vecDirec1[1] = vecA[1] - vecB[1]
                    vecDirec1[2] = vecA[2] - vecB[2]
                    
                    // Vector Dirección V2 = C - D
                    static Float:vecDirec2[3]
                    vecDirec2[0] = vecC[0] - vecD[0]
                    vecDirec2[1] = vecC[1] - vecD[1]
                    vecDirec2[2] = vecC[2] - vecD[2]
                    
                    
                    // Intersección entre 2 lineas L1 y L2
                    // (V1 × V2) * AC
                    // Producto Cruz
                    //             | i   j   k |
                    // |V1 x V2| = |V11 V12 V13| = i - j + k
                    //             |V21 V22 V23|
                    static Float:vecCruz[3], Float:vecAC[3], Float:Total
                    vecCruz[0] = (vecDirec2[1] * vecDirec1[2]) - (vecDirec1[1] * vecDirec2[2]);// (V22*V13-V12*V23)i
                    vecCruz[1] = -((vecDirec2[0] * vecDirec1[2]) - (vecDirec1[0] * vecDirec2[2])); // -(V21*V13-V11*V23)j
                    vecCruz[2] = (vecDirec2[0] * vecDirec1[1]) - (vecDirec1[0] * vecDirec2[1]); // (V21*V13-V11*V22)k
                    // Vector AC
                    vecAC[0] = vecC[0] - vecA[0];
                    vecAC[1] = vecC[1] - vecA[1];
                    vecAC[2] = vecC[2] - vecA[2];
                    
                    Total = vecAC[0] * vecCruz[0] + vecAC[1] * vecCruz[1] + vecAC[2] * vecCruz[2];
                                 
                    if(Total)
                    {
                       client_print(id, print_chat, "No Intersectan") 
                    }
                    else
                    {
                       client_print(id, print_chat, "Intersectan") 
                    }
                    
                }
                
                           
            }
        }
    }
Me dice "No intersectan" todo el tiempo :/
¿Cual tendria que ser el valor del Float Total para que de falso?
__________________
------


Last edited by LARP; 07-14-2012 at 00:57.
LARP is offline
DJHD!
Veteran Member
Join Date: Dec 2009
Location: Santiago, Chile
Old 07-13-2012 , 22:06   Re: [Ayuda] Usar calculo matematico en Pawn
#17

Pero No Entiendo Para qué quieres hacer ese calculo que quieres lograr?.
__________________
Quote:
Originally Posted by XINLEI View Post
Porque rocccos trata de ser el metalicross que nunca va a poder ser.
DJHD! is offline
Send a message via MSN to DJHD!
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 07-14-2012 , 01:31   Re: [Ayuda] Usar calculo matematico en Pawn
#18

Quote:
Originally Posted by LARP View Post
No me resulta, te muestro el code que hice para ver si esta bien:

Code:
    if(Hook[id] && !canThrowHook[id]){
        //Linea L1
        /*
        Punto A (x0,        y0,        z0)
        vecA    (vecA[0],    vecA[1],    vecA[2])
            
        Punto B (x1,        y1,        z1)
        vecB    (vecB[0],    vecB[1],    vecB[2])
        */
        static Float:vecA[3], Float: vecB[3]
        pev(id, pev_origin, vecA)
        pev(Hook[id], pev_origin, vecB)
        
        //Buscar otras lineas y hacer el calculo
        for (new i=1; i<=32; i++)
        {
            
            if (pev_valid(Hook[i])){
                new uid = pev(Hook[i], pev_owner)
                if(uid != id){
                    //Linea L2
                    /*
                    Punto C (x2,        y2,        z2)
                    vecC    (vecC[0],    vecC[1],    vecC[2])
                        
                    Punto D (x3,        y3,        z3)
                    vecD    (vecD[0],    vecD[1],    vecD[2])
                    */
                    static Float:vecC[3], Float: vecD[3]
                    pev(uid, pev_origin, vecC)
                    pev(Hook[i], pev_origin, vecD)
                    
                    // Vector Dirección V1 = A - B
                    static Float:vecDirec1[3]
                    vecDirec1[0] = vecA[0] - vecB[0]
                    vecDirec1[1] = vecA[1] - vecB[1]
                    vecDirec1[2] = vecA[2] - vecB[2]
                    
                    // Vector Dirección V2 = C - D
                    static Float:vecDirec2[3]
                    vecDirec2[0] = vecC[0] - vecD[0]
                    vecDirec2[1] = vecC[1] - vecD[1]
                    vecDirec2[2] = vecC[2] - vecD[2]
                    
                    
                    // Intersección entre 2 lineas L1 y L2
                    // (V1 × V2) * AC
                    // Producto Cruz
                    //             | i   j   k |
                    // |V1 x V2| = |V11 V12 V13| = i - j + k
                    //             |V21 V22 V23|
                    static Float:vecCruz[3], Float:vecAC[3], Float:Total
                    vecCruz[0] = (vecDirec2[1] * vecDirec1[2]) - (vecDirec1[1] * vecDirec2[2]);// (V22*V13-V12*V23)i
                    vecCruz[1] = -((vecDirec2[0] * vecDirec1[2]) - (vecDirec1[0] * vecDirec2[2])); // -(V21*V13-V11*V23)j
                    vecCruz[2] = (vecDirec2[0] * vecDirec1[1]) - (vecDirec1[0] * vecDirec2[1]); // (V21*V13-V11*V22)k
                    // Vector AC
                    vecAC[0] = vecC[0] - vecA[0];
                    vecAC[1] = vecC[1] - vecA[1];
                    vecAC[2] = vecC[2] - vecA[2];
                    
                    Total = vecAC[0] * vecCruz[0] + vecAC[1] * vecCruz[1] + vecAC[2] * vecCruz[2];
                                 
                    if(Total)
                    {
                       client_print(id, print_chat, "No Intersectan") 
                    }
                    else
                    {
                       client_print(id, print_chat, "Intersectan") 
                    }
                    
                }
                
                           
            }
        }
    }
Me dice "No intersectan" todo el tiempo :/
¿Cual tendria que ser el valor del Float Total para que de falso?
Debes calcular la distancia que hace la recta. No desde tu posición y la del hook que es infinita(el hook no es un punto es una línea). Deben ser 2 puntos al menos pertenecientes a la recta y claramente en sus extremos (start | end).

Si el hook lo haces obteniendo el aim origin y tu punto. Obten esos 2 puntos como los que necesitas. Y luego comparas 2 hook, y tendrás los 4 puntos.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).


Last edited by gladius; 07-14-2012 at 01:33.
gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
LARP
Senior Member
Join Date: Aug 2008
Location: Santiago, Chile
Old 07-16-2012 , 00:39   Re: [Ayuda] Usar calculo matematico en Pawn
#19

Quote:
Originally Posted by gladius View Post
Debes calcular la distancia que hace la recta. No desde tu posición y la del hook que es infinita(el hook no es un punto es una línea). Deben ser 2 puntos al menos pertenecientes a la recta y claramente en sus extremos (start | end).

Si el hook lo haces obteniendo el aim origin y tu punto. Obten esos 2 puntos como los que necesitas. Y luego comparas 2 hook, y tendrás los 4 puntos.
Lo que pasa esque ocmo te explique anteriormente, el punto de inicio es necesariamente el ID y El V Corresponde al Hook, entonces hago la recta de esa forma, para controlar el Hook no utizo el AIM.

Comprendes?
__________________
------


Last edited by LARP; 07-16-2012 at 01:34.
LARP is offline
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 07-17-2012 , 15:19   Re: [Ayuda] Usar calculo matematico en Pawn
#20

Hablando particularmente de tu plugin.

El punto de Start debe ser el vector origin del player.
El punto de End debe ser el vector origin del volantín.

Con esos 2 puntos se forma la recta del Hook (el hilo). Y esa recta es la que debe ser comparada con las otras rectas de los otros volantines.

No comparar vector origin del player con una recta. Que no es lo mismo.

De acuerdo a tu pregunta como se sabe si se intersectan? cuando el valor del producto mixto es 0.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).


Last edited by gladius; 07-17-2012 at 15:22.
gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
 



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 09:09.


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