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
613
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
613
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: 228

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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top