Author Topic: Any Sketchup/Ruby experts?  (Read 497 times)

KD5NRH

  • friends
  • Senior Member
  • ***
  • Posts: 10,926
  • I'm too sexy for you people.
Any Sketchup/Ruby experts?
« on: February 04, 2016, 04:35:21 PM »
Snagged from elsewhere and modified a bit already.  Need to be able to get pitch and azimuth of a face relative to the root axes of the model.  (Even if the face is inside a component that isn't aligned with the same axes.)  I'll fix azimuth at some point (it's 90 degrees off, so a simple translation there) but pitch is always 90 degrees within a small error margin, regardless of how I orient the face being measured.

Code: [Select]
mod = Sketchup.active_model
ent = mod.active_entities
sel = mod.selection
sel.grep(Sketchup::Face).each{|fac|
rpt = fac.bounds.center;
nrm = fac.normal;
rax = nrm.axes[0]
tr = Geom::Transformation.rotation(rpt,rax,Math.asin(nrm.z))
nrm.transform! tr
if nrm.x < 0
  azm = Math::PI - Math::asin(nrm.y) # Quadrant III or IV
elsif nrm.y < 0
  azm = Math::PI * 2 + Math::asin(nrm.y) # Quadrant II
else
  azm = Math::asin(nrm.y) # Quadrant I
end
deg = azm.radians;
deg=deg%360;
d=deg.floor;
m=((deg-d)*60).floor;s=(((deg-d)*3600)-m*60).round(2)
pitch=Math::acos(nrm.z);
pitchd=pitch.radians;
ent.add_text "Pitch=#{altd}\nAzimuth=#{d}#{176.chr} #{m}' #{s}\"",rpt,nrm
}

Hawkmoon

  • friend
  • Senior Member
  • ***
  • Posts: 27,344
Re: Any Sketchup/Ruby experts?
« Reply #1 on: February 04, 2016, 06:02:43 PM »
Snagged from elsewhere and modified a bit already.  Need to be able to get pitch and azimuth of a face relative to the root axes of the model.  (Even if the face is inside a component that isn't aligned with the same axes.)  I'll fix azimuth at some point (it's 90 degrees off, so a simple translation there) but pitch is always 90 degrees within a small error margin, regardless of how I orient the face being measured.

BING Translator couldn't render this in English. Give me a hint -- what language is it?
- - - - - - - - - - - - -
100% Politically Incorrect by Design

cordex

  • Administrator
  • Senior Member
  • *****
  • Posts: 8,682
Re: Any Sketchup/Ruby experts?
« Reply #2 on: February 05, 2016, 03:59:13 AM »
I am no expert in any of that, but it looks like you are outputting the wrong variable for pitch. Aren't you printing the value of altd instead of pitchd?

RoadKingLarry

  • friends
  • Senior Member
  • ***
  • Posts: 21,841
Re: Any Sketchup/Ruby experts?
« Reply #3 on: February 05, 2016, 04:42:15 AM »
I am no expert in any of that, but it looks like you are outputting the wrong variable for pitch. Aren't you printing the value of altd instead of pitchd?

That's what I was thinking.

 :facepalm:
If ye love wealth better than liberty, the tranquility of servitude better than the animating contest of freedom, go home from us in peace. We ask not your counsels or your arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that you were our countrymen.

Samuel Adams

KD5NRH

  • friends
  • Senior Member
  • ***
  • Posts: 10,926
  • I'm too sexy for you people.
Re: Any Sketchup/Ruby experts?
« Reply #4 on: February 05, 2016, 09:44:21 AM »
Must have grabbed one of my interim drafts.  I swear, I can't look at raw code without introducing silly bugs like that.  Unfortunately, sometimes I hit save at the wrong time and then forget to hit it at the right time.  Made a small alteration to the calculation code, changed the variable name to be a bit more clear, and didn't change the name in the output until I'd run it a few times trying to figure out the error.