SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 03/12/2011, 07:58 PM   #1
KakarottoSSJ
Little Clucker
 
Join Date: Nov 2011
Posts: 3
Reputation: 0
Default How to know if a vector passes over a dot

I know how to get the distance with cross product, but I don't know that.
I want to know when a vector passes over a dot, in a "x y z" position.
I don't know too much of physics.
KakarottoSSJ is offline   Reply With Quote
Old 04/12/2011, 01:49 AM   #2
KakarottoSSJ
Little Clucker
 
Join Date: Nov 2011
Posts: 3
Reputation: 0
Default Respuesta: How to know if a vector passes over a dot

Nobody answers?
I need it please.
KakarottoSSJ is offline   Reply With Quote
Old 04/12/2011, 02:32 AM   #3
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 2,629
Reputation: 410
Default Re: How to know if a vector passes over a dot

OK, I take it you mean find if the line crosses a certain point. I'm not fully sure on 3d scales but I know how to do 2d using just x and y.

So, all we need to do is find the equation of the line then plug our values into that line to see if it is anywhere on there. We are going to need to find the gradient (y2 - y1 / x2 - x1) and the equation formula y - y1 = m(x - x1). An example is the line with the points (2, 5) and (6, 9). We are going to find if the point (3 , 6) lies on that line.

Code:
gradient
= (9 - 5) / (6 - 2)
= 4 / 4
= 1

Equation 
y - y1 = m(x - x1)
y - 5 = 1(x - 2)
y - 5 = x - 2
y = x + 3

Then plug in our values.
6 = 3 + 3
6 = 6
The point is on our line
So, now to do this using PAWN.

pawn Code:
stock IsPointOnLine(Float:Line1x, Float:Line1y, Float:Line2x, Float:Line2y, Float:Pointx, Float:Pointy)
{
    if( (Pointy - Line1y) == ( ( (Line2y - Line1y) / (Line2x - Line1x) ) * (Pointx - Line1x) ) ) return true;
    return false;
}

Hope this helps .
__________________
[HiC]TheKiller is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] CSTL - Data container(s) (Currently vector) Teprey Plugin Development 64 12/12/2015 10:36 PM
Setting an object rotation by the player's camera vector? [XST]O_x Scripting Help 3 14/07/2012 02:03 PM
[HOW]Hour passes and he/she gets +1 Score??? vakhtang Help Archive 1 19/03/2011 01:32 PM
[Discussion] New Hack which passes callbacks? (related to scripting) PoWerZ Help Archive 1 13/10/2009 07:43 PM


All times are GMT. The time now is 05:41 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.