Math help for Angles

kingkwong92

Well-Known Member
Reaction score
25
Got a mean headache from trying to work this out.
I have a dagger (D) throw ability and a ninja star (S) throw ability.
Both a dummy units in a slide trigger.
Every 0.01 seconds they move a distance of speed(D) or speed(S).

I'm trying to make a trigger which detects when a dagger is within X range and if they also have a dagger or a ninja star, they will throw it and hit the incoming ninja star or dagger if it is coming from the front. I want to find the angle in which I have to throw the dagger or NS to intercept the incoming projectile. Is there any formula to predict the path of the projectile?

So far I have:
Point A = Position of thrown
Point B = Position of deflecting unit

Angle(AtoB) - Angle(A-facing) = Angle - Angle(B-A)
I havn't taken into account the speed of the projectiles. Atm I have no idea what I'm doing.
Any ideas???
 

vypur85

Hibernate
Reaction score
803
> Is there any formula to predict the path of the projectile?

Err.. Just acquire the angle between the target and the thrown object. And allow the new object to travel along that angle? Don't think any math formula is required here. That is, if I understand you correctly.
 

kingkwong92

Well-Known Member
Reaction score
25
The projectile moves in the direction it is facing.
Direction of travel = Facing angle
The dagger detects within 50 units range. Therefore the dagger can still hit even if
facing angle not equal to angle from unit to dagger
Eg. Dagger goes past unit but not directly aimed at the unit.

Also I want it to deflect any dagger that comes with range.

How do you upload an image? I could show you by drawing a diagram on paint
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
612
So long as there are units within 50 range, check to see if their facing angle is within the required angle to deflect the dagger.
 

kingkwong92

Well-Known Member
Reaction score
25
I don't think I'm understood.
Eample: I have a unit (point A)
I draw a circle around the selected unit, this is the range in which a projectile is detected.
When a projectile enters the circle (point B)
If the dagger is heading straight towards the unit then Angle(A to B) equals facing of projectile.
However the projectile can also enter the circle but Angle(A to B) does not equal facing of projectile.

I want the unit to throw a projectile at Angle(X) which will then collide with the projectile at point(C). I need a formula which works out where point (C) is and use that to calculate the angle that the dagger must be thrown at.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
612
A Paint diagram would be helpful to understanding. This is doing my head in.
 

vypur85

Hibernate
Reaction score
803
Uh. To be more precise...
Below every new post window, there's a 'Upload a File' button. That one...

I hope your image will be easy to understand. From your descriptions, they're kinda confusing but seemed to be something rather simple.
 

kingkwong92

Well-Known Member
Reaction score
25
Untitled.png

-A projectile moves within the radius of detection of the hero at Point A.
-At that instant the hero throws a projectile that will intecept the incoming projectile at point B. (Blue line)
-I need to know how to calculate the path of the incoming projectile (Red line)and then get the angle in which I can throw my projectile. Also I have multiple projectiles with different speeds.
The projectiles will ricochete off each other.
Hope this is easier to understand. The maths is driving me crazy and I've drawn a million diagrams on paper to try work it out.
 

xAnaMorphine

Active Member
Reaction score
43
I need to know how to calculate the path of the incoming projectile (Red line)

The red line is a straight line which has x and y coordinates
which subtends the circle around the hero.
Running a periodic trigger which records the x and y coordinates
of the projectile after entering the circle will help to determine the
position of the projectile.
Then you want to launch a projectile which faces the incoming projectile
which flys towards the estimated point where both straight line cross each
other. If that doesn't ring a bell let me try to explain it further.
Basically what you are looking for is the point of intersection between two
straight lines. Since you got the information about the intersection point
of the straight line and the circle you know how the straight line will continue.
I would use vectors to calculate the shortest distance between the hero and the
straight line which crosses the circle and then fire the projectile.
Hope that was somehow understandable.
 

xAnaMorphine

Active Member
Reaction score
43
This should work...


Code:
g1: y=m*x+b
 
P1 (x from incoming projectile | y from incoming projectile)
P2 (x2 | y2)
 
m= (y2-y1)/(x2-x1)
 
b= y - m*x
b= (y from incoming projectile) - [(y2-y1)/(x2-x1)]* (x from incoming projectile)
 
---------------------
 
P3 (x3 from Hero | y3 from Hero)
 
m1= -1/m
 
g2: y=m1*x+b
 
b= (y3 from Hero) - (-1/m) * (x3 from Hero)
 
-------------------
 
Intersection between g1 and g2:
 
S: m*x+b = m1*x+b
S(sx | sy)
------------------
 
Euclidean distance between the
intersection Point S and the position of the Hero P3:
 
d(P,S)=sqrt(((x3-sx)^2) + ((y3-sy)^2))
 
(Just to prove it is the shortest distance.)
---------------
 
Launch projectile towards the intersection Point.
 

kingkwong92

Well-Known Member
Reaction score
25
How would this work if there are two different projectiles with different speeds.
Doesn't this just calculate a path perpendicular to the projectiles path?
 

xAnaMorphine

Active Member
Reaction score
43
As for the different speeds it will get a little bit complicated.
I don't really know if there are any limits with the World Editor GUI but I think
something like this should work for the speed:

Code:
d(t)=(a/2)*t²+v*t+d0
 
while
d(t) is the place at the time "t",
a is the acceleration,
v the constant speed and
d0 the starting point.
 
In this particular example a is equal to 0 and we lookt at 2D vectors.
 
We need another function to determine the angle of the projectile:
 
v= q* (sin(alpha), cos(alpha))
 
while q is the speed of the projectile which should reflect the incoming projectile
 
if you solve the equations you get the intersection point...
 
 
http://en.wikipedia.org/wiki/Equations_of_motion

have fun ;/
 

Imp Midna

Active Member
Reaction score
52
So, simply setting up an equation and solving it pretty much fails. Actually, i asked Wolfram matehmatica about the solution, but the Sin(x) and Cos(x) inside the direction vector makes it so complex that i cant even post it here.
So the trick to reduce it was setting the koordinate-system that way that the projectile is at (o|o) facing towards the x-achsis. You could get rid of the Sin(x) from the Hero-to-Intersept-Point line using the fact that the intersept-Point thus gotta be at y=0 and using Cos(x) = sqrt(1-Sin(x)^2).

Still, im not satisfied with what came out. Im just gonna show it to you:
Therm.jpg

where:
- rx is the difference of the x positions (X of Hero - X of Projectile)
- ry is the same with the y-positions
- v1 is the speed of the projectile
- v2 is the speed of the heros projectile
- t is the time till impact and also the way you find out the point where they are impacting (Point with offset t*speed in facing-angle degrees)

Now, the thing i marked green is the first thing you gotta care about. If this therm is <0, then you would take the sqrt of a negative number, which is not possible without i (and we dont use i). Thus, a projectile could possibly intercepted at 0 - 2 locations depending on what comes out.
Now what buggs me is the red part. Because it doesnt make sense. It would say that they can not intercept if the speed of the projectiles are the same, which pretty much makes no sense at all, because they can. Now, if you, for example, have two projectiles with a speed of 400 m/s, you could use 4.000.000m/s for v1 and 4.000.001 m/s for v2 and then divide the t that comes out by 10000 again, and you would get the correct position, but its still so god damned weird that i first decided not to share this "solution". Well, but now i do, dont ask me why. If thats enough for you, just implement it in such a way that you do this v2*10.000 + 1 stuff so it gives you the correct point again.
 

xAnaMorphine

Active Member
Reaction score
43
Just wanted to update my previous posts;

Trigger:
  • Erstelle Einheit
    • Events
    • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
    • Unit - Create 1 Footman for Player 2 (Blue) at (Center of Region 000 &lt;gen&gt;) facing Default building facing degrees
    • Set Anfangspunkt = (Position of (Last created unit))
    • Set X_Koordinate_Anfangspunkt = (X of Anfangspunkt)
    • Set Y_Koordinate_Anfangspunkt = (Y of Anfangspunkt)
    • Unit - Order (Last created unit) to Move To (Center of Region 001 &lt;gen&gt;)


Code:
Vektoren: (x-c)^2 = r^2, wobei x = Ortsvektoren auf dem Kreis und c = Ortsvektore des Mittelpunktes des Kreises
Gerade: x(t) = o + t * d, wobei o = der Ortsvektor eines beliebigen Punktes auf der Geraden ist und d = Richtungsvektor der Geraden
 
Da es sich um eine belibige Gerade handeln kann muss o neu definiert werden:
o'x = ox * cos(alpha) - oy * sin(alpha)
und
o'y= ox * sin(alpha) - oy * cos(alpha)

Trigger:
  • Variablen
    • Events
    • Unit - A unit comes within 512.00 of Paladin 0001 &lt;gen&gt;
    • Conditions
    • Actions
    • Set Winkel = (Facing of (Triggering unit))
    • Set Radius = 256.00
    • Set Mittelpunkt = (Position of Paladin 0001 &lt;gen&gt;)
    • -------- Position des Footman beim eintreten in den Kreis --------
    • Set Schnittpunkt = (Position of (Triggering unit))
    • Set X_Koordinate = (X of Schnittpunkt)
    • Set Y_Koordinate = (Y of Schnittpunkt)
    • -------- Beliebige Position des Footman --------
    • Set X_Cos_Zwischenergebnis = (X_Koordinate x (Cos(Winkel)))
    • Set X_Sin_Zwischenergebnis = (X_Koordinate x (Sin(Winkel)))
    • Set Y_Cos_Zwischenergebnis = (Y_Koordinate x (Cos(Winkel)))
    • Set Y_Sin_Zwischenergebnis = (Y_Koordinate x (Sin(Winkel)))
    • -------- Beliebige Position (Anpassung der Koordinaten) --------
    • Set Neue_X_Koordinate = (X_Cos_Zwischenergebnis - Y_Sin_Zwischenergebnis)
    • Set Neue_Y_Koordinate = (X_Sin_Zwischenergebnis - Y_Cos_Zwischenergebnis)
    • -------- Punkt nach der Drehung --------
    • Set Neuer_Punkt = (Point(Neue_X_Koordinate, Neue_Y_Koordinate))
    • -------- Die Differenz der Punkte P und Q (Koordinaten) --------
    • Set Differenz_X = (Neue_X_Koordinate - X_Koordinate_Anfangspunkt)
    • Set Differenz_Y = (Neue_Y_Koordinate - Y_Koordinate_Anfangspunkt)
    • -------- Ermittlung der Hypotenuse --------
    • Set X_Hypotenuse_Zwischenergebnis = (Differenz_X x Differenz_X)
    • Set Y_Hypotenuse_Zwischenergebnis = (Differenz_Y x Differenz_Y)
    • Set Hypotenuse = (Square root((X_Hypotenuse_Zwischenergebnis + Y_Hypotenuse_Zwischenergebnis)))
    • -------- Berechnung --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • ((X_Koordinate Less than X_Koordinate_Anfangspunkt) and (Y_Koordinate Less than Y_Koordinate_Anfangspunkt)) or ((X_Koordinate Greater than X_Koordinate_Anfangspunkt) and (Y_Koordinate Greater than Y_Koordinate_Anfangspunkt))
    • Then - Actions
    • -------- Falls -r &lt;= x &lt;= r, dann liegt eine Kollision vor --------
    • Set X_Drehung_Kosinus = (Differenz_Y / Hypotenuse)
    • Set X_Drehung_Sinus = (Differenz_X / Hypotenuse)
    • Set X_Kosinus_Zwischenergebnis = (X_Koordinate x X_Drehung_Kosinus)
    • Set X_Sinus_Zwischenergebnis = (Y_Koordinate x X_Drehung_Sinus)
    • Set X_Koordinate_der_Drehung = (X_Kosinus_Zwischenergebnis - X_Sinus_Zwischenergebnis)
    • Else - Actions
    • -------- Falls -r &lt;= y &lt;= r, dann liegt eine Kollision vor --------
    • Set Y_Drehung_Kosinus = (Differenz_X / Hypotenuse)
    • Set Y_Drehung_Sinus = (Differenz_Y / Hypotenuse)
    • Set Y_Kosinus_Zwischenergebnis = (X_Koordinate x Y_Drehung_Sinus)
    • Set Y_Sinus_Zwischenergebnis = (Y_Koordinate x Y_Drehung_Kosinus)
    • -------- Gemeinsame Schnittpunkte zwischen Kreis und Gerade berechnen --------
    • -------- Wir berechnen Terme die mehrfach benötigt werden und setzen sie in eine Variable --------
    • -------- Term: d*c --------
    • Set X_Koordinate_von_D_und_C = (Differenz_X x (X of Mittelpunkt))
    • Set Y_Koordinate_von_D_und_C = (Differenz_Y x (Y of Mittelpunkt))
    • Set Term_D_und_C_zusammengefasst = (X_Koordinate_von_D_und_C + Y_Koordinate_von_D_und_C)
    • -------- Term: o*d --------
    • Set X_Koordinate_von_O_und_D = (X_Koordinate x Differenz_X)
    • Set Y_Koordinate_von_O_und_D = (Y_Koordinate x Differenz_Y)
    • Set Term_O_und_D_zusammengefasst = (X_Koordinate_von_O_und_D + Y_Koordinate_von_O_und_D)
    • -------- Term: d^2 --------
    • Set X_Koordinate_von_D_und_D = (Differenz_X x Differenz_X)
    • Set Y_Koordinate_von_D_und_D = (Differenz_Y x Differenz_Y)
    • Set Term_D_und_D_zusammengefasst = (X_Koordinate_von_D_und_D + Y_Koordinate_von_D_und_D)
    • -------- Term: d*c - o*d --------
    • Set Term_D_C_O_D = (Term_D_und_C_zusammengefasst - Term_O_und_D_zusammengefasst)
    • -------- Term: (d*c - o*d) / d^2 --------
    • Set Term_D_C_O_D_Durch_D2 = (Term_D_C_O_D / Term_D_und_D_zusammengefasst)
    • -------- Term: [(d*c - o*d) / d^2]^2 --------
    • Set Term_DCOD_Durch_D2_Quadriert = (Term_D_C_O_D_Durch_D2 x Term_D_C_O_D_Durch_D2)
    • -------- Term: o-c --------
    • Set X_Koordinate_von_O_und_C = (X_Koordinate - (X of Mittelpunkt))
    • Set Y_Koordinate_von_O_und_C = (Y_Koordinate - (Y of Mittelpunkt))
    • Set X_Koordinate_von_OC_Quadriert = (X_Koordinate_von_O_und_C x X_Koordinate_von_O_und_C)
    • Set Y_Koordinate_von_OC_Quadriert = (Y_Koordinate_von_O_und_C x Y_Koordinate_von_O_und_C)
    • Set Term_O_und_C_zusammengefasst = (X_Koordinate_von_OC_Quadriert + Y_Koordinate_von_OC_Quadriert)
    • -------- Term: r^2 --------
    • Set Radius_Quadriert = (Radius x Radius)
    • -------- Term: (o-c)^2 - r^2 --------
    • Set Term_OC2_R2 = (Term_O_und_C_zusammengefasst - Radius_Quadriert)
    • -------- Term: ((o-c)^2 - r^2) / d^2 --------
    • Set Term_OC2_R2_Durch_D2 = (Term_OC2_R2 / Term_D_und_D_zusammengefasst)
    • -------- Term: Differenz von [(d*c - o*d) / d^2]^2 und ((o-c)^2 - r^2) / d^2 --------
    • Set T1_Unter_Wurzel_Differenz = (Term_DCOD_Durch_D2_Quadriert - Term_OC2_R2_Durch_D2)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • T1_Unter_Wurzel_Differenz Less than 0.00
    • Then - Actions
    • Game - Display to (All players) the text: Die Wurzel einer ne...
    • Else - Actions
    • -------- Wurzelziehen aus der Differenz --------
    • Set T1_Wurzel_Aus_Differenz = (Square root(T1_Unter_Wurzel_Differenz))
    • -------- T1 berechnen aus der Differenz der gezogenen Wurzel und (d*c - o*d) / d^2 --------
    • Set T1 = (Term_D_C_O_D_Durch_D2 - T1_Wurzel_Aus_Differenz)
    • Game - Display to (All players) the text: (Der Kreis wird berührt oder durchdrungen: + (String(T1)))


This is an example use which isn't perfect yet but it works.
It detects the unit and tracks the position.
For today I've got enough, will look into this tomorrow and finish it the next days :p

EDIT: Sorry for the german commentary but else I would loose track, will change it when it works how you demanded.

EDIT2: The system now fully detects the path of the unit :)
 

xAnaMorphine

Active Member
Reaction score
43
Okay got it working now, here is the system.
Just play the map and check out the results, tell me if that's how you imagined.

For everyone who wants to look at the code I will post a pastebin right here
since my post else exceeds 10000 characters :(

http://pastebin.com/vRcmcffs
 

Attachments

  • Matheproblemv5.zip
    25.7 KB · Views: 224

kingkwong92

Well-Known Member
Reaction score
25
Wow thank you so much guys. I kinda feel reallys tupid because I have to read the things you guys post up about 10 times before I can even understand a wee bit.

@xAnaMorphine:
I've just tested it and it works almost exactly the way that I want it too. Sometimes when the footman just enters the circle and leaves again, it is impossible for it to be intercepted but a shade still flies out to that point. It would be possible to intercept it if the velocity of the projectile is faster (in some cases).I would like it so if it is impossible to intercept then nothing happens. I normally like to know what I'm doing when adding stuff to a map but this just seems too complex for me. I might just have to copy and paste it. I didn't think it was as hard as I thought it was. Also could you please tell me why the speed of the shade keeps varying? Also why sometimes there are three other shades appearing and sometimes they don't.

EDIT!! I've also noticed that when I move the hero to the top-right or bottom-left, the shade moves to the wrong point. The footmans distance between lessens so therefore should be able to be intercepted.

@Imp Midna:
I really don't like the different velocity thing but I think xAnaMorphine's way works really well. Your way I can understand a wee bit more. I'll play around with both methods and see how they work out.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top