• 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.

[snippet] GetIntersectionDistance

We've got a line given by P1(x1, y1) and P2(x2, y2) as well as a ray given by P3(x3, y3) and angle a.
This function returns the distance from P3 to the intersection point.
The distance returned is negative if the ray points away from the line.

JASS:
library GetIntersectionDistance

function GetIntersectionDistance takes real x1, real y1, real x2, real y2, real x3, real y3, real a returns real
    local real m = x1-x2
    if m==0. then//avoid division by zero
        return (x1-x3)/Cos(a)
    endif
    set m = (y1-y2)/m
    if m==Tan(a) then//parallel (avoid division by zero again: Sin(a)-Tan(a)*Cos(a)=0)
        return 0.
    endif
    return (m*(x3-x1)+y1-y3)/(Sin(a)-m*Cos(a))
endfunction

endlibrary
 

Attachments

  • GetIntersectionDistance.w3m
    12.9 KB · Views: 84
Last edited:
I think someone should just make one library with all these functions in it .__.

I think removing the "Small Code Snippets"-thread was a bad idea (and I lost some of my functions with it 'cause I didn't backup them -.-)
also
Your library needs to contain minimal functions specific to the library.[...]
You need to split these functions up into different libraries too... don't have a huge library of line snippets, they're just little mathematical operations ; P.

maybe a library with all kind of intersection functions would be more appropiate
I guess a mod will respond as soon as he sees 20 intersection-related threads x)
 
Top