Question

I'm having some trouble figuring out how to use the compass math helper functions.

Assume I have a triangle ABC with C = 90 degrees. I would like to know how many degrees A is.

The formula for that is easy: A = arctan(a/b), but how do I code that with Compass and Sass?

Was it helpful?

Solution

You'll have to create a function in Ruby to do this. Since you're already using Compass, you can take advantage of the Sassy Math extension. Their Ruby code for this function looks like this (hope I've got the right one here):

  def atan2(y, x)
    y = y.value.to_f
    x = x.value.to_f
    result = Math.atan2(y, x)
    Sass::Script::Number.new(result)
  end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top