• 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.
  • 💡 We're thrilled to announce that our upcoming texturing contest is in the works, and we're eager to hear your suggestions! Please take this opportunity to share your ideas in this theme discussion thread for the Texturing Contest #34!
  • 🏆 Hive's 7th HD Modeling Contest: Icecrown Creature is now open! The frozen wastes of Icecrown are home to some of Azeroth’s most terrifying and resilient creatures. For this contest, your challenge is to design and model a HD 3D monster that embodies the cold, undead, and sinister essence of Icecrown! 📅 Submissions close on April 13, 2025. Don't miss this opportunity to let your creativity shine! Enter now and show us your frozen masterpiece! 🔗 Click here to enter!

[Solved] Distance between point and line

Status
Not open for further replies.
Level 10
Joined
Jun 6, 2007
Messages
392
I've been trying to make a function that calculates the distance between a point and a line. I know one point from a line, let's call it (xl, yl), and the point whose distance I need to calculate is (xp, yp). I also know the angle of the line (just called angle). So the equation of the line is
y-yl = tan (angle) * (x-xl), in normal form

-tan (angle) * x + y - yl + tan (angle) * xl = 0

The distance between line and point can be calculated with formula

|a*x0 + b*y0 + c| / sqrt (a^2 + b^2)

in this case:

|-tan (angle) * xp + yp - yl + tan (angle) * xl| / sqrt ( (tan (angle))^2 + 1^2))

Here's my function:
JASS:
    function DistancePointLine takes location pointInLine, location pointToCheck, real angle returns real
        local real xl = GetLocationX (pointInLine)
        local real yl = GetLocationY (pointInLine)
        local real xp = GetLocationX (pointToCheck)
        local real yp = GetLocationY (pointToCheck)
        local real a = Tan (angle)

        return RAbsBJ ((-a*xp + yp + a*xl - yl) / SquareRoot (Pow (a, 2) + 1))

    endfunction
The problem is that this function doesn't return the correct value.
 
Status
Not open for further replies.
Top