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

LinearFunctions Lib

Status
Not open for further replies.
I can't seem to think of any more functions I can include in this library:

JASS:
//****************************************************
//
//                  Linear Functions
//                   -Magtheridon96
//
//****************************************************
library LinearFunctions
    struct Linear
        real slope
        real yIntercept
        
        method parallel takes thistype d returns boolean
            return this.slope == d.slope
        endmethod
        
        method intersects takes thistype d returns boolean
            return not this.parallel(d)
        endmethod
        
        method perpendicular takes thistype d returns boolean
            return this.slope * d.slope == -1
        endmethod
        
        static method create takes real x, real y, real x2, real y2 returns thistype
            local thistype this = thistype.allocate()
            set .slope = (y2-y)/(x2-x)
            set .yIntercept = y - .slope * x
            return this
        endmethod
        
        method getY takes real x returns real
            return .slope * x + .yIntercept
        endmethod
        
        method getX takes real y returns real
            return (y - .yIntercept) / .slope
        endmethod
        
        method getSlope takes nothing returns real
            return .slope
        endmethod
        
        method getYintercept takes nothing returns real
            return .yIntercept
        endmethod
        
        method getBaseAngle takes nothing returns real
            return Atan2(getY(2)-getY(1),1)
        endmethod
    endstruct
endlibrary

Any ideas?
I'm currently just fixing it so that it can't divide by 0.
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Nah, but he could instead just do Atan(.slope)

This is a fairly useless library, so here are some useless method suggestions. You could add a method that returns the x value of the intersection between two lines. Maybe something else that returns the line bisecting the angle formed by the intersection of two lines. Maybe some different constructors for different forms of a linear function:
Ax + By + C = 0
y = mx + b
x/a + y/b = 1
 
Nah, but he could instead just do Atan(.slope)

This is a fairly useless library, so here are some useless method suggestions. You could add a method that returns the x value of the intersection between two lines. Maybe something else that returns the line bisecting the angle formed by the intersection of two lines. Maybe some different constructors for different forms of a linear function:
Ax + By + C = 0
y = mx + b
x/a + y/b = 1

@ Atan(.slope)
LOL It was right infront of me :D

I know it's useless, but if I somehow link it to spells, it could definitely be useful ^^

And thanks for suggesting a Multi-Constructor ^^

I changed this library a bit yesterday to fix a few bugs with lines parallel to the X/Y-axes.

I'm currently working on a function that can solve a system of equations as you suggested :)
 
Status
Not open for further replies.
Top