Ruby get slope of a surface
-
Hi all,
I am new to Ruby and I' like so help. I am trying to write a code that gives the slope (angle between the blue line and and the the face normal) of a roof but i cannot get it workI am using this code but does not work
norm.angle_between
slope = norm.angle_between(Geom::Vector3d.new(0,0,1)).radiansany help ?
thanks
-
Hi, it's simple:
"it doesn't work" = "it doesn't do what I expected"
Then what do you expect?Your example worked with that face:
face = Sketchup.active_model.entities.add_face(ORIGIN, [0,1,0],[1,1,1],[1,0,1]).reverse slope = face.normal.angle_between(Z_AXIS).radians >> 45.0
Please make test cases (and define for each an expected result), then test each and then you either correct the code or the test case.
-
Aerillus Thanks for the reply
If I understant well at the first line you design a surfae and at the second one you get the slope..
when I am trying to apply the second commant
slope = face.normal.angle_between(Z_AXIS).radians
on a design face i get a nill valuewhat do I make Wrong here ?
-
Give us the full code then, instead of the snippet you provided. If your code isn't working, then it might have something to do with how you are retrieving the face object. Are you sure you're actually referencing a face for example?
-
Code and sample model.
Whenever I get unexpected result I ensure I inspect the values of the variables I use - to make they they contain the values I expect them to be. Often the error can be in another place.
-
The code that i am trying to apply to get the slope of a model's surfaces is the following
<span class="syntaxdefault"> model</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br /> ss</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br /> faces</span><span class="syntaxkeyword">=[]; </span><span class="syntaxdefault">ss</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault">faces </span><span class="syntaxkeyword"><< </span><span class="syntaxdefault">e </span><span class="syntaxkeyword">if </span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.class==</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Face</span><span class="syntaxkeyword">} <br /> <br /> </span><span class="syntaxdefault">faces</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each</span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">|<br /> </span><span class="syntaxdefault">name</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">to_s</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">";"</span><span class="syntaxkeyword">)[-</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">].</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">">"</span><span class="syntaxkeyword">)[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /> </span><span class="syntaxdefault">norm</span><span class="syntaxkeyword">=</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal<br /> slope </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">normal</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">angle_between</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Z_AXIS</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">radians<br /> puts slope<br /> </span><span class="syntaxkeyword">} </span><span class="syntaxdefault"></span>
ok i now i have program somthing wrong but i cannot find out what
-
Can you also post a model with a face where the result is incorrect? (Please also describe what is expected value.)
-
Are you still using SketchUp 6 Pro ?
There was a bug in the
Geom::Vector3d#angle_between()
method that was fixed sometime in the 7.x branch.
Advertisement