(Keeps Hive Alive)
Go Back   The Hive Workshop - A Warcraft III Modding Site > Warcraft III Resources > Submissions

Submissions Submit JASS resources! If approved, they will be moved to their proper section.
Please read me first.

Reply
 
LinkBack Thread Tools Display Modes
Old 02-24-2008, 06:56 PM   #1 (permalink)
 
Zergleb's Avatar

User
 
Join Date: Dec 2004
Posts: 61

Zergleb has little to show at this moment (22)Zergleb has little to show at this moment (22)Zergleb has little to show at this moment (22)


Line Location Distance.

I was just working on my map and made some of these up. Thought I might as well post them if someone else wanted them and didn't know how to make them.

What this does is, the bottom function takes 3 locations, the 1st two form a line, and then it tells you how far the 3rd point is from the line that the 1st and 2nd make.

The above function finds which location along the line that the 1st and 2nd location make is nearest to the 3rd location.

function GetClosestLocation takes location A, location B, location P returns location
    local location AP = Location(GetLocationX(P) - GetLocationX(A), GetLocationY(P) - GetLocationY(A))
    local location AB = Location(GetLocationX(B)- GetLocationX(A), GetLocationY(B) - GetLocationY(A))
    local location LocReturn
    local real ab2 = (GetLocationX(AB) * GetLocationX(AB)) + (GetLocationY(AB) * GetLocationY(AB))
    local real t = ((GetLocationX(AP) * GetLocationX(AB)) + (GetLocationY(AP) * GetLocationY(AB)))/ab2

    if t < 0.0 then
        set t = 0.0
    elseif t > 1.0 then
        set t = 1.0
    endif

    call MoveLocation(AB, GetLocationX(AB) * t, GetLocationY(AB) * t)

    set LocReturn = Location(GetLocationX(A) + GetLocationX(AB), GetLocationY(A) + GetLocationY(AB))
    call RemoveLocation(AP)
    call RemoveLocation(AB)
    set AP = null
    set AB = null

    return LocReturn
endfunction

function LineLocationDistance takes location A, location B, location P returns real
    local location ClosestPoint = GetClosestLocation(A,B,P)
    local real ReturnThis = DistanceBetweenPoints(P, ClosestPoint)
    call RemoveLocation(ClosestPoint)
    set ClosestPoint = null
    return ReturnThis
endfunction

Now this isn't the version I actually use. Because I have made a VectorLoc struct in vJass to do this. So to get rid of the leak I would change LocReturn to a global variable.

I posted it this way so they could understand my explanation.

Last edited by Zergleb; 02-24-2008 at 07:14 PM..
Zergleb is offline   Reply With Quote
Old 08-06-2008, 02:13 PM   #2 (permalink)
 
Element of Water's Avatar

User
 
Join Date: Aug 2008
Posts: 252

Element of Water has little to show at this moment (29)Element of Water has little to show at this moment (29)Element of Water has little to show at this moment (29)


Might be better (and more efficient since no GetLocationX/Y) if you make them take coordinates rather than locations, but other than that, I like it!
__________________
Element of Water is offline   Reply With Quote
Old 08-06-2008, 03:40 PM   #3 (permalink)

iRawr
 
Join Date: Dec 2005
Posts: 8,349

PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)PurplePoot is a splendid one to behold (807)

Paired Mapping Contest #4 Winner: Fallen Angel - Lucifer's Keep Respected User: This user has been given the respected user award. Map Development Mini-Contest #1 Winner: Stand of the Elements 

Locations are deprecated whenever you can possibly avoid them... look into using raw coordinates.
PurplePoot is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Trigger] relative distance Supermj Triggers & Scripts 16 04-17-2008 10:19 PM
[Trigger] Calculating Distance Traveled Vegavak Triggers & Scripts 4 01-18-2008 01:18 AM
Distance Equation >,< Gost World Editor Help Zone 6 10-20-2007 07:43 PM
Distance between units Homicide13 World Editor Help Zone 9 05-25-2007 01:06 AM
Mathematical Distance Problem Aoen Triggers & Scripts 4 11-11-2006 04:47 PM

All times are GMT. The time now is 09:19 AM.






Your link here 
Myspace Graphics | Myspace Layouts | Debt Consolidation | Credit Cards | Free Advertising
Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Copyright©Ralle