questions about geometry, trigonometry functions

SanKakU

Member
Reaction score
21
"geometry, trigonometry" is what i'm trying to figure out here.

got a question about math functions with x and y reals.

actually, i don't know almost anything about those, and wish someone would make a tutorial on them.

anyway...here's the pressing question i have for now.

let's say i have a hero select a target x/y a certain distance away from him...let's say 200-750 range away.

now i want to get the math to get the x/y points for two more angles of a triangle. but i don't know anything about the math functions to do that.

let's say that there is a line for the triangle crossing with the caster's facing direction. since he's facing the direction of the target x/y when casting there...the line will cross his viewing angle...and i want to in the trigger select the points a certain distance away from there.

so let's say the spell is casted 500 range or more away from the caster. now we want to get a line to draw us a couple more points that will be closer to the caster. each a certain distance from the center of the line.
Code:
    t

p_______p


    c
something like that.
i need the math functions to be able to get those points so i can use them...also i want to be able to select targets within this triangle of the target, and 2 other points which are extrapolated from the caster's position.

of course...if the target is close to the hero, then the triangle will be drawn differently.

Code:
p_______p


    t

    c
like that

i knowthere's a tutorial
http://www.hiveworkshop.com/forums/archive/index.php/t-172620.html
there, but i don't understand it.

looks like i can find some angles...but i don't know what their degrees are! here's what i mean:

JASS:

local real uf=GetUnitFacing(SpellEvent.CastingUnit)
local real lf=uf+90.00//these two reals go left and right from the center of the
local real rf=uf-90.00//hypotanuse...thus, getting ready to form the two angles of it
local real dist=getdisr(SpellEvent.TargetX,SpellEvent.TargetY,SpellEvent.CastingUnit)
local integer lvl=GetUnitAbilityLevel(SpellEvent.CastingUnit,iac)
local real disfrocen=300.00//we will use this 3 times, twice in establishing
// the angles of the hypotanuse, and once to get the last angle.
//  the distance numbers can change, that doesn't matter what they are.
local unit xa=null
local unit xb=null
local unit xc=null
local player y = GetOwningPlayer(SpellEvent.CastingUnit)
local real tx = SpellEvent.TargetX
local real ty = SpellEvent.TargetY
if dist<500 then
set xa = CreateUnit(y, 'ospw', tx + disfrocen * Cos(lf * bj_DEGTORAD), ty + disfrocen * Sin(lf * bj_DEGTORAD), lf+180.00)
//i don't know what these functions do...i only know they seem to let me make units
//that are at an angle at a distance from a point...(Cos, Sin, bjDEG)
set xb = CreateUnit(y, 'ospw', tx + disfrocen * Cos(rf * bj_DEGTORAD), ty + disfrocen * Sin(rf * bj_DEGTORAD), rf+180.00)
set xc = CreateUnit(y, 'ospw', tx + disfrocen * Cos(uf * bj_DEGTORAD), ty + disfrocen * Sin(uf * bj_DEGTORAD), uf+180.00)
else
set xa = CreateUnit(y, 'ospw', tx - disfrocen * Cos(lf * bj_DEGTORAD), ty - disfrocen * Sin(lf * bj_DEGTORAD), lf-180.00)
set xb = CreateUnit(y, 'ospw', tx - disfrocen * Cos(rf * bj_DEGTORAD), ty - disfrocen * Sin(rf * bj_DEGTORAD), rf-180.00)
set xc = CreateUnit(y, 'ospw', tx - disfrocen * Cos(uf * bj_DEGTORAD), ty - disfrocen * Sin(uf * bj_DEGTORAD), uf-180.00)
endif
set xa = null
set xb = null
set xc = null


so here's where i'm stuck. although i can target the 3 points depending on where the target point is...how am i to calculate for what is in the triangle?

i would think that it would be good to get the degrees of the angles. but i don't know how to do that. i don't know how to get the degrees in the triangle even though with those functions which i don't even know what they do i was able to establish the angles of the triangle. i could make 3 units cast siphon mana on eachother...that would display the sides...but i have no way to know how to do anything physically with that. it's not like you could make units that try to cross that line get attacked by the line.

and what about figuring out how to make one of the 3 units face the direction that is in the middle of the other two units? like i said, i don't know how to figure out what the degrees of an angle is, so how can i cut it in half if i don't even know what it is? wouldn't the degrees of an angle depend on the distances?

hmm...well, i think i figured out kindof how to do it by reading some wiki articles about triangles.

in my code if i write it like this, then the 3 sides will be the same length...meaning that they have the same angle, which is 1/3 of 180, or 60.

they said that

c/ca=b/ba=c/ca. that's the formula.
there was another formula that made me realize that the 3 sides were the same length...lol

2d^2+2m^2=a^2+b^2
so since the line going to the far angle was 300, and it going to the other angles was both 300, that was 600times 600...or shorten it to 6x6 giving me 36. and m was c cut in half. which was what i did. and d was that first number. so it was all the same. another 36. so a and b making the 72 meant they both had to have the range of 600 each. it didn't take long after that to realize the angles all had the same degrees.

EDIT: ah...somehow the triangles aren't making sense to me...i thought i figured it out but it's somehow...i think i messed up in interpreting the calculations...meh...whatever. i guess angle of 60 for all three is close enough...
 

Laiev

Hey Listen!!
Reaction score
188
The Helper Forums > Warcraft Zone > World Editor Help > Tutorials and Resources
questions about geometry, trigonometry functions


should be



The Helper Forums > Warcraft Zone > World Editor Help >
questions about geometry, trigonometry functions


and at least make things more readable =.= no one like text wall

JASS:

local real uf=GetUnitFacing(SpellEvent.CastingUnit)
local real lf=uf+90.00//these two reals go left and right from the center of the
local real rf=uf-90.00//hypotanuse...thus, getting ready to form the two angles of it
local real dist=getdisr(SpellEvent.TargetX,SpellEvent.TargetY,SpellEvent.CastingUnit)
local integer lvl=GetUnitAbilityLevel(SpellEvent.CastingUnit,iac)
local real disfrocen=300.00//we will use this 3 times, twice in establishing
// the angles of the hypotanuse, and once to get the last angle.
//  the distance numbers can change, that doesn't matter what they are.
local unit xa=null //variable are created with nulled value -.- u don't need it
local unit xb=null //variable are created with nulled value -.- u don't need it
local unit xc=null //variable are created with nulled value -.- u don't need it
local player y = GetOwningPlayer(SpellEvent.CastingUnit)
local real tx = SpellEvent.TargetX
local real ty = SpellEvent.TargetY

    if dist<500 then
        set xa = CreateUnit(y, 'ospw', tx + disfrocen * Cos(lf * bj_DEGTORAD), ty + disfrocen * Sin(lf * bj_DEGTORAD), lf+180.00)
        //i don't know what these functions do...i only know they seem to let me make units
        //that are at an angle at a distance from a point...(Cos, Sin, bjDEG)
        set xb = CreateUnit(y, 'ospw', tx + disfrocen * Cos(rf * bj_DEGTORAD), ty + disfrocen * Sin(rf * bj_DEGTORAD), rf+180.00)
        set xc = CreateUnit(y, 'ospw', tx + disfrocen * Cos(uf * bj_DEGTORAD), ty + disfrocen * Sin(uf * bj_DEGTORAD), uf+180.00)
    else
        set xa = CreateUnit(y, 'ospw', tx - disfrocen * Cos(lf * bj_DEGTORAD), ty - disfrocen * Sin(lf * bj_DEGTORAD), lf-180.00)
        set xb = CreateUnit(y, 'ospw', tx - disfrocen * Cos(rf * bj_DEGTORAD), ty - disfrocen * Sin(rf * bj_DEGTORAD), rf-180.00)
        set xc = CreateUnit(y, 'ospw', tx - disfrocen * Cos(uf * bj_DEGTORAD), ty - disfrocen * Sin(uf * bj_DEGTORAD), uf-180.00)
    endif

set xa = null
set xb = null
set xc = null
 

SanKakU

Member
Reaction score
21
well, anyway i think i was going about it the wrong way...i was trying to make the casting point be the middle of the hypotenuse, but i think it's better to make the casting point be an angle...of course i have an idea that it might be better still...or anyway not difficult at least...to make the casting point be the middle of the triangle.

The Helper Forums > Warcraft Zone > World Editor Help > Tutorials and Resources
questions about geometry, trigonometry functions

should be

The Helper Forums > Warcraft Zone > World Editor Help >
questions about geometry, trigonometry functions

if i posted this here and it wasn't moved by a mod...it's probably because i was searching this forum for a resource that explained this. i still don't understand the functions what they do like atan atan2 and cos and sin and all that. sorry for posting in the wrong spot.
 

saw792

Is known to say things. That is all.
Reaction score
280
Clearly you haven't studied trigonometry in school yet... Start learning some basic trig and you will probably find a simpler way to do this. What you're asking doesn't really make sense, since it seems you are arbitrarily picking a distance for the horizontal line (one side of your triangle), and there seems to be no guideline as to how long the line should be and when it should be above the target and when it should be below.

Having said that:

Direction vector between target and caster:
JASS:
vx = targx - castx
vy = targy - casty
General equation of line perpendicular to this line:
JASS:
(vx)x + (vy)y = 0
Which means that given some point (x0, y0) (basically some point some distance between the caster and target that you decide) you can find other points perpendicular to the line between the target and the caster by picking a random other x and y as follows:
JASS:
vy(y - y0) = -vx(x - x0)


If you then want the perpendicular line to be a certain length (say, 300 units for example) then you can work out the angle from the caster to that point:
JASS:
theta = Atan2(300/2, D)
where D is the distance you chose for the line to be from the caster. Then you can work out the absolute angle from the axis to the two points using the angle between the caster and the target:
JASS:
gamma1 = Atan2(vy, vx) + theta
gamma2 = Atan2(vy, vx) - theta

And then you calculate the points based on the two angles and the original (x0, y0):
JASS:
hypotenuse = sqrt((300/2)^2 + D^2)
x1 = hypotenuse * cos(gamma1)
y1 = hypotenuse * sin(gamma1)
x2 = hypotenuse * cos(gamma2)
y2 = hypotenuse * sin(gamma2)


Possibly not the most efficient way, but the maths is solid.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top