Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/08/26 22:41
Stooq now requires an API key
by VHX. 06/08/26 20:14
ZorroGPT
by TipmyPip. 06/06/26 12:36
Zorro 3.01 recoded MMI function issue
by TipmyPip. 06/04/26 05:44
SGT_FW
by Aku_Aku. 05/31/26 11:05
Issues resuming trades on Demo account
by Martin_HH. 05/22/26 13:31
XTB
by pr0logic. 05/18/26 12:27
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
3 registered members (TipmyPip, Grant, 1 invisible), 3,415 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Seraphinang, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Find out if a vector is between two others #464370
02/07/17 19:32
02/07/17 19:32
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hi, I'd like to know, if a vector is between two others. Here some examples.



Basically, I want to check if v(x) is right of v(1) and left of v(2).

Re: Find out if a vector is between two others [Re: PadMalcom] #464371
02/07/17 21:23
02/07/17 21:23
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
hmm, maybe
dot(v1, vx) > dot(v1, v2)
using normalized (unit) vectors


edit: oops, I just saw that you wanted to check if they are in a specific order.

in that case calculate the angle of each vector and compare them.


POTATO-MAN saves the day! - Random
Re: Find out if a vector is between two others [Re: Kartoffel] #464372
02/07/17 21:40
02/07/17 21:40
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hi thanks, calculate the the of each vector related to what? laugh

Re: Find out if a vector is between two others [Re: PadMalcom] #464373
02/07/17 22:02
02/07/17 22:02
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
here's the theory in 2d.
using counter-clockwise (ccw) angles, your condition would be something like:

angle(vx) - angle(v2) < angle(v1) - angle(v2) => ccw order: v2, vx, v1

to calculate the angle of each vector* just use atan2(dy, dx) with dx/dy = the x & y components of each vector
(* the angle between the positive x axis and the vector, like in mathematics)

keep in mind that special cases can cause the area between v1 and v2 to exceed the [0° - 360°] range. to compensate for that, a simple modulo-operation should do the trick:

Code:
ang_diff_2x = (angle(vx) - angle(v2)) % 360
ang_diff_21 = (angle(v1) - angle(v2)) % 360

if(ang_diff_2x < ang_diff_21)
...


Last edited by Kartoffel; 02/07/17 22:04.

POTATO-MAN saves the day! - Random

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1