• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

getting "cords" for a triangle

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
well i need to get "cords"(x and y) for a get unit in a triangle function by vex but i have to problems with that

this is what i have to far(it sux)
JASS:
        set d.x1 = GetUnitX(d.caster)
        set d.y1 = GetUnitY(d.caster)
        set d.angle = Atan2(ty-d.y1,tx-d.x1)*180/3.15169
        set angle = d.angle - 45
        set d.x2 = d.x1+Range*Cos((angle)*(3.15169/180))
        set d.y2 = d.x1+Range*Sin((angle)*(3.15169/180))
        set angle = d.angle + 45
        set d.x3 = d.x1+Range*Cos((angle)*(3.15169/180))
        set d.y3 = d.x1+Range*Sin((angle)*(3.15169/180))
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
I'd say the most accurate (accurate meaning that the units will form a triangle, after all, the problem isn't the coordinates) way would be to set a triangle made of 3 cords (yea, maybe try making one with 5 ! that will be the shitzel !), which is basically what you've done, and then start creating units from the first one towards the second, when the creating location is farther then the second point of the triangle, you change the direction etc.

Also, why use pi/180 when you can use the constant bj_DEGTORAD (which is 0.0174532925 or so).
 
Level 11
Joined
Apr 6, 2008
Messages
760
well that not the problem -.-'

stop focusing on shit, focus on the real problem instead :)


EDIT:


i know the prob (angle+45) if this is 370 != 10 then

made this+


JASS:
if angle > 360 then
set angle = angle - 360
elseif angle < 0 then
set angle = 360+(-angle)
endif

but i want a better solution, where is pooty when u need him QQ
 
Last edited:
Level 29
Joined
Jul 29, 2007
Messages
5,174
Here's the basic idea. It doesn't work (it freezes warcraft) and it doesn't include setting the third part of the triangle, but I'm too lazy to fix it and to make it better.

JASS:
library Triangle

function getDistance takes real x1, real y1, real x2, real y2 returns real
    local real dx = x1 - x2
    local real dy = y1 - y2
    return SquareRoot(dx * dx + dy * dy)
endfunction
function getAngle takes real x1, real y1, real x2, real y2 returns real
    return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction

struct triangle
    real x1
    real x2
    real x3
    real y1
    real y2
    real y3
    real angle_one
    real angle_two
    real angle_three
    real dist_one
    real dist_two
    real dist_three
    integer model_path
    integer owner
    
    method createUnits takes real distance returns nothing
        local unit u = CreateUnit(Player(this.owner), this.model_path, this.x1, this.x2, 0)
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real x_dist = distance * Cos(this.angle_one)
        local real y_dist = distance * Sin(this.angle_one)
        loop
            set x = x + x_dist
            set y = y + y_dist
            set u = CreateUnit(Player(this.owner), this.model_path, x, y, 0) 
            exitwhen getDistance(GetUnitX(u), GetUnitY(u), this.x2, this.y2) <= distance
        endloop
        set x = this.x2
        set y = this.y2
        set x_dist = distance * Cos(this.angle_two)
        set y_dist = distance * Sin(this.angle_two)
        loop
            set x = x + x_dist
            set y = y + y_dist
            set u = CreateUnit(Player(this.owner), this.model_path, x, y, 0) 
            exitwhen getDistance(GetUnitX(u), GetUnitY(u), this.x3, this.y3) <= distance
        endloop
        set x = this.x3
        set y = this.y3
        set x_dist = distance * Cos(this.angle_three)
        set y_dist = distance * Sin(this.angle_three)
        loop
            set x = x + x_dist
            set y = y + y_dist
            set u = CreateUnit(Player(this.owner), this.model_path, x, y, 0) 
            exitwhen getDistance(GetUnitX(u), GetUnitY(u), this.x1, this.y1) <= distance
        endloop
        set u = null
    endmethod
    method setCoordinates takes real x, real y returns nothing
        set this.x1 = x
        set this.y1 = y
        set this.x2 = x + this.dist_one * Cos(this.angle_one)
        set this.y2 = y + this.dist_one * Sin(this.angle_one)
        set this.x3 = this.x2 + this.dist_two * Cos(this.angle_two)
        set this.x3 = this.x2 + this.dist_two * Sin(this.angle_two)
        set this.dist_three = getDistance(this.x1, this.y1, this.x3, this.y3)
        set this.angle_three = getAngle(this.x1, this.y1, this.x3, this.y3) * bj_DEGTORAD
    endmethod

    method init takes real x_coordinate, real y_coordinate, real angle_one, real angle_two, real length_one, real length_two, real distance_between_units, integer player_number, integer model_path returns nothing
        set this.angle_one = angle_one * bj_DEGTORAD
        set this.angle_two = angle_two * bj_DEGTORAD
        set this.dist_one = length_one
        set this.dist_two = length_two
        set this.owner = player_number
        set this.model_path = model_path
        call this.setCoordinates(x_coordinate, y_coordinate)
        call this.createUnits(distance_between_units)
    endmethod
endstruct

endlibrary
 
Level 11
Joined
Apr 6, 2008
Messages
760
unit was a spell @ a loc, i get the angle between target loc and the caster which is d.angle then from that i need to make a triangle towards that point ( Triangle -> \/ the point at down is casters loc) it gonna be 90 degrees wide ( -45 degree to left and +45 to right)
 
Level 11
Joined
Apr 6, 2008
Messages
760
like this (i r pro on paint xD)

attachment.php
 

Attachments

  • Triangle.jpg
    Triangle.jpg
    8.9 KB · Views: 154
Level 4
Joined
May 17, 2008
Messages
75
In that case:
Code:
\           t           /
  \         |         /
    \       |range  /
      \     |     / range/Sin(45) = range*Sqrt(2)
        \   |   /
          \ | /    
            c
So the distance between the caster and the other triangle corners is range/Sin(45).
 
Level 4
Joined
May 17, 2008
Messages
75
Technically I should have said Cosine, not Sine (it's the same for 45 degrees anyway)

And what I meant is to replace "range" in that equation with "range/Cos(45)"

so the coordinates are
x+(range/Cos(45))*Cos(angle),y+(range/Cos(45))*Sin(angle)

But since War3 trig uses radians by default it's:
x+(range/Cos(bj_PI/4))*Cos(angle),y+(range/Cos(bj_PI/4))*Sin(angle)
 
Status
Not open for further replies.
Top