Hey, I have this problem where I want to different things to happens depending on the angle between two points. But I later found out that that angle depends on the points' locations on the map. It's like there's a line in the middle of the map, and anything north of it is a positive angle, and south = negative. I'd like that line to be between two moving points, for example the location of two units, so that the angle between them doesnt depend on anythnig else. Then I could calculate the angle between between a third point and one of the two original. But I've found no way to do this. Im no math major, so I might me embarassingly off, but please help! thanks! <3
The angle returned using the "Angle between points" function is based on the same plane as what's used in unit facing (for example, when you place a doodad and modify it's facing parameter.) I'm not sure I understand why you would want the angle to be relative to those two points. Mathematically, there HAS to be a third point for a return value to make any sense. In order to form an angle you need 3 points and at least 2 lines (imaginary or not.)
It's easier to think of the function as returning an angle that point 1 would be "facing" in order to "look at" point 2.
If you explain in more detail what you're trying to accomplish I might be able to help you further.
I was just having tons of trouble with this to build a compass in my map. For some reason, sc2 uses a scale of -180 to positive 180 instead of 0 to 360. What exactly are you trying to do, though? Move one of the units so that the angle remains the same? If that's the case, you could move the unit via polar offset toward the angle you want.
Oh, that's right. B'duh. I even made a function using this. My mistake.
If it helps at all, here's a link to the function, which includes the arduous process of me and another poster trying to figure it out: Unit Behind/Facing Unit
This function actually converts the 180/-180 scale to a 0-360 scale. I think. It's been a few months since I wrote it though :P
In further detail, what I'd like to do is have two points (in this case the location of two units), then be able to calculate the angle of a triangle made out of these two points and a third point. I hate math :D
I was having some trouble with this myself. It seems you can get the angle of 2 points, but there's no function to get the angle of 3 points. So the question is, where is this mysterious "invisible 3rd point"? I have no idea. Seems kind of strange.
Rollback Post to RevisionRollBack
Feel free to Send me a PM if you have any questions/concerns!
I havn't tested this yet, but I think that if you have 3 points; A,B and C, where A is the top of a pointy triangle, then take the angle of the line AB and subtract the AC angle from AB, you should get angle of the A-corner.
edit: nope, didnt work... GAH, this drives me nuts.
It seems that the angle between two points is determined by the angle between the invisible line between them and the blue line on the graphic. Now, I don't care about that, what I want is the angle between the line stretching from A to B and from A to C, the angle that's marked "?" in the graphic. What I tried was to take (A-B)-(A-C) = ?, and it works sometimes. I think the problem is that the angle AB isnt constant!
I'm having trouble viewing your link. Something about a security risk, I dunno. Anyways, you're going to have to set up a few conditional branches in order to get the right math. If the ABP (angle between points) for one angle (A and B or A and C) is positive while the other is negative, you need to add the absolute value of both together to get your desired angle. If both of the ABPs are positive or negative, you subtract the absolute value of one from the absolute value of the other and take the absolute value of that. This should get you the angle you are looking for.
Absolute value is the distance from, the number to 0. So the absolute value of 5 is 5. The Absolute value of -6 is 6. Basically, the absolute value of a positive number is that same number, and the absolute value of a negative number is that same number but without the negative sign.
|5| => 5
|-5| => 5
|-7| => 7
|8| => 8
Rollback Post to RevisionRollBack
Feel free to Send me a PM if you have any questions/concerns!
I tried making a trigger which did what you said, BasharTeg, but it doesnt seem to work. I'm not getting any negative angles though, which feels good :) Here's what i came up with:
Ugh... Why is this so hard? It shouldn't be this hard. Just getting the angle between 3 points. But every program for games I've used does it this way.. There must be a reason, lol.
I have no idea. Take this as a free bump.
Rollback Post to RevisionRollBack
Feel free to Send me a PM if you have any questions/concerns!
Hmm... Still doesn't work quite the way I need it to :( BasharTeg, did you write that code freehand? 'cause I can't get the math to look exactly like yours. Also I'm not sure I've fully succeeded in explaining the problem (I'd hate to believe I did succeed but you failed to understand :P). I have ten units standing in a line. The first unit is a variable called Head, the last unit is a variable called Toe. The line they form is always straight. I want it to be so that if I click in front of Head, angle 3 should always be the same, no matter where Head and Toe is positioned on the actual map. If I click behind Toe, angle 3 should always be the same, regardless of Head and Toe's positions on the map, but opposite of what it had been if I had clicked in front of Head. The same should go for any point; right of Head, Left of head, Right- and slightly down of Head, etc...
Now, this is the code I use atm. I find it to work perfectly when the line that the 10 units make out is horizontal and Head is the Eastern tip of it, and Toe the Western. In every other position I find that the scale of degrees jumps, so that it goes from 0 to 270 to 90, back to 0 (0,1,2,3...,270,90,89,88...3,2,1,0)
or from 0 to 180, then back to 0 again (0,1,2,3...,180,179,178...3,2,1,0). :( :S
The from 0 to 270 to 90 to 90 thing happens when the Head to Toe line is vertical. The from 0 to 180 back to 0 thing happens when the Head to Toe line is horizontal and Head is the Western point and Toe is the Eastern point. Confused yet?
Hey, I have this problem where I want to different things to happens depending on the angle between two points. But I later found out that that angle depends on the points' locations on the map. It's like there's a line in the middle of the map, and anything north of it is a positive angle, and south = negative. I'd like that line to be between two moving points, for example the location of two units, so that the angle between them doesnt depend on anythnig else. Then I could calculate the angle between between a third point and one of the two original. But I've found no way to do this. Im no math major, so I might me embarassingly off, but please help! thanks! <3
The angle returned using the "Angle between points" function is based on the same plane as what's used in unit facing (for example, when you place a doodad and modify it's facing parameter.) I'm not sure I understand why you would want the angle to be relative to those two points. Mathematically, there HAS to be a third point for a return value to make any sense. In order to form an angle you need 3 points and at least 2 lines (imaginary or not.)
It's easier to think of the function as returning an angle that point 1 would be "facing" in order to "look at" point 2.
If you explain in more detail what you're trying to accomplish I might be able to help you further.
@BasharTeg: Go
I was just having tons of trouble with this to build a compass in my map. For some reason, sc2 uses a scale of -180 to positive 180 instead of 0 to 360. What exactly are you trying to do, though? Move one of the units so that the angle remains the same? If that's the case, you could move the unit via polar offset toward the angle you want.
@zeldarules28: Go
Oh, that's right. B'duh. I even made a function using this. My mistake.
If it helps at all, here's a link to the function, which includes the arduous process of me and another poster trying to figure it out: Unit Behind/Facing Unit
This function actually converts the 180/-180 scale to a 0-360 scale. I think. It's been a few months since I wrote it though :P
Thnaks for anwers :)
In further detail, what I'd like to do is have two points (in this case the location of two units), then be able to calculate the angle of a triangle made out of these two points and a third point. I hate math :D
I was having some trouble with this myself. It seems you can get the angle of 2 points, but there's no function to get the angle of 3 points. So the question is, where is this mysterious "invisible 3rd point"? I have no idea. Seems kind of strange.
I havn't tested this yet, but I think that if you have 3 points; A,B and C, where A is the top of a pointy triangle, then take the angle of the line AB and subtract the AC angle from AB, you should get angle of the A-corner.
edit: nope, didnt work... GAH, this drives me nuts.
edit again: Ok, so I made a graphic over the issue: http://data.fuskbugg.se/skalman02/4e1df47584044_angles.bmp
It seems that the angle between two points is determined by the angle between the invisible line between them and the blue line on the graphic. Now, I don't care about that, what I want is the angle between the line stretching from A to B and from A to C, the angle that's marked "?" in the graphic. What I tried was to take (A-B)-(A-C) = ?, and it works sometimes. I think the problem is that the angle AB isnt constant!
I'm having trouble viewing your link. Something about a security risk, I dunno. Anyways, you're going to have to set up a few conditional branches in order to get the right math. If the ABP (angle between points) for one angle (A and B or A and C) is positive while the other is negative, you need to add the absolute value of both together to get your desired angle. If both of the ABPs are positive or negative, you subtract the absolute value of one from the absolute value of the other and take the absolute value of that. This should get you the angle you are looking for.
what the fuck.. everytime I've ever uploaded anything on a forum people have found it a security risk. i hate technology sometimes.
trying Imageshack: http://imageshack.us/f/37/angles.png/
Question: what's absolute value? thanks
@FIRETRUCKEU: Go
Absolute value is the distance from, the number to 0. So the absolute value of 5 is 5. The Absolute value of -6 is 6. Basically, the absolute value of a positive number is that same number, and the absolute value of a negative number is that same number but without the negative sign.
|5| => 5
|-5| => 5
|-7| => 7
|8| => 8
thanks
I tried making a trigger which did what you said, BasharTeg, but it doesnt seem to work. I'm not getting any negative angles though, which feels good :) Here's what i came up with:
Ugh... Why is this so hard? It shouldn't be this hard. Just getting the angle between 3 points. But every program for games I've used does it this way.. There must be a reason, lol.
I have no idea. Take this as a free bump.
@FIRETRUCKEU: Go
That's not really what I was talking about. Your trigger should look something like this:
thanks guys. Yeah, I'm no good at advanced triggering, BasharTeg. Thanks for helping out :)
edit: I thought there was a way to get the absolute value instantly! It's often just a matter of looking hard enough.
Hmm... Still doesn't work quite the way I need it to :( BasharTeg, did you write that code freehand? 'cause I can't get the math to look exactly like yours. Also I'm not sure I've fully succeeded in explaining the problem (I'd hate to believe I did succeed but you failed to understand :P). I have ten units standing in a line. The first unit is a variable called Head, the last unit is a variable called Toe. The line they form is always straight. I want it to be so that if I click in front of Head, angle 3 should always be the same, no matter where Head and Toe is positioned on the actual map. If I click behind Toe, angle 3 should always be the same, regardless of Head and Toe's positions on the map, but opposite of what it had been if I had clicked in front of Head. The same should go for any point; right of Head, Left of head, Right- and slightly down of Head, etc...
Now, this is the code I use atm. I find it to work perfectly when the line that the 10 units make out is horizontal and Head is the Eastern tip of it, and Toe the Western. In every other position I find that the scale of degrees jumps, so that it goes from 0 to 270 to 90, back to 0 (0,1,2,3...,270,90,89,88...3,2,1,0) or from 0 to 180, then back to 0 again (0,1,2,3...,180,179,178...3,2,1,0). :( :S
The from 0 to 270 to 90 to 90 thing happens when the Head to Toe line is vertical. The from 0 to 180 back to 0 thing happens when the Head to Toe line is horizontal and Head is the Western point and Toe is the Eastern point. Confused yet?
The code I'm using:
Here is the problem, as far as I can see it:
Your code:
The code you should have:
i can not believe i missed that. once again, thanks
Still doesn't work :(