• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

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