Thursday, 2024-05-02, 6:53 PM


Main
Registration
Login
Welcome Guest | RSS  
[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Hanky, Fireeye  
Clan NgO Forums » Discussions » Junk Yard » [JASS] Math Funcs: Circle, LineSeg, Parallelogram, Trapezoid (Some math functions...)
[JASS] Math Funcs: Circle, LineSeg, Parallelogram, Trapezoid
TheCheeseLoverDate: Monday, 2009-02-09, 5:00 AM | Message # 1
Sergeant
Group: Users
Messages: 22
Reputation: 0
Status: Offline
Hello...
I found those functions at wc3jass.com and I think they could help some people.
Functions: Circle, LineSeg, Parallelogram and Trapezoid

Region Add Circle:

Code
function RegionAddCircle takes region whichRegion, real x, real y, real radius returns nothing
           local real r = 16.00
           local real w = 0
           local rect t = Rect(0, 0, 0, 0)
           loop
               exitwhen r > radius
               set w = Cos(Asin(r / radius)) * radius
               call SetRect(t, x - w, y + r - 16.00, x + w, y + r + 16.00)
               call RegionAddRect(whichRegion, t)
               call SetRect(t, x - w, y - r - 16.00, x + w, y - r + 16.00)
               call RegionAddRect(whichRegion, t)
               set r = r + 32.00
           endloop
           call RemoveRect(t)
           set t = null
endfunction

Region Add LineSeg:

Code
function RegionAddLineSeg takes region whichRegion, real x1, real y1, real x2, real y2 returns nothing
           local real dist = SquareRoot((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
           local real xdist = x2 - x1
           local real ydist = y2 - y1
           loop
               exitwhen x1 > x2 and xdist > 0
               exitwhen x2 > x1 and xdist < 0
               exitwhen y1 > y2 and ydist > 0
               exitwhen y2 > y1 and ydist < 0
               call RegionAddCell(whichRegion, x1, y1)
               exitwhen dist == 0
               set x1 = x1 + 32 * (xdist/dist)
               set y1 = y1 + 32 * (ydist/dist)
           endloop
endfunction

Region Add Parallelogram:

Code
Script code        
function RegionAddParallelogram takes region whichRegion, real x1, real y1, real x2, real y2, real length, real angle returns nothing
           local integer i = 0
           loop
               exitwhen i >= R2I(length)
               call RegionAddLineSeg(whichRegion, x1, y1, x2, y2)
               set x1 = x1 + 32 * CosBJ(angle)
               set y1 = y1 + 32 * SinBJ(angle)
               set x2 = x2 + 32 * CosBJ(angle)
               set y2 = y2 + 32 * SinBJ(angle)
               set i = i + 32
           endloop

Region Add Trapezoid:

Code
function RegionAddTrapezoid takes region whichRegion, real xc, real yc, real base1, real base2, real height, real angle returns nothing
           local real x1
           local real y1
           local real x2
           local real y2
           local integer i = 1
           local integer iEnd = R2I(height / 32)
           local real bI = (base2 - base1) / I2R(iEnd)
           loop
               exitwhen i > iEnd
               set x1 = xc - 0.5 * base1 * SinBJ(angle)
               set y1 = yc - 0.5 * base1 * CosBJ(angle)
               set x2 = xc + 0.5 * base1 * SinBJ(angle)
               set y2 = yc + 0.5 * base1 * CosBJ(angle)
               call RegionAddLineSeg(whichRegion, x1, y1, x2, y2)
               set base1 = base1 + bI
               set xc = xc + 32 * CosBJ(angle)
               set yc = yc + 32 * SinBJ(angle)
               set i = i + 1
           endloop
endfunction

Links:
- Geometry: Page 1
- Geometry: Page 2


Yay I have a signature. You suck. :D

Message edited by TheCheeseLover - Monday, 2009-02-09, 5:00 AM
 
HankyDate: Thursday, 2009-02-12, 9:24 AM | Message # 2
Lieutenant colonel
Group: Moderators
Messages: 116
Reputation: 9
Status: Offline
I edited your post feel free to change it again.


Made by Smoe reworked by GiR aka Darkt3mpl3r
 
Clan NgO Forums » Discussions » Junk Yard » [JASS] Math Funcs: Circle, LineSeg, Parallelogram, Trapezoid (Some math functions...)
  • Page 1 of 1
  • 1
Search:

Clan NgO © 2024Powered by uCoz