by macgile » Mon Feb 13, 2012 10:43 pm
Hi all, I have a strange result when I subtract two angle in radians!!!! example : - Code: Select all
axe = Geom::Vector3d.new(-0.999782867743517, -0.0208378829670674, 0.0) up = Geom::Vector3d.new(0.00335712544250249, -0.161071856847676, 0.98693697196954) axe.normalize! up.normalize! angle = (Math::PI/2.0) + (up.angle_between axe) puts angle.radians angle = (Math::PI/2.0) - (up.angle_between axe) puts angle.radians
can you help me ?
Last edited by thomthom on Tue Feb 14, 2012 9:52 am, edited 1 time in total.
Reason: Wrapped the code sample in a [code] block
-
macgile
-
- Posts: 33
- Joined: Sat Jan 19, 2008 10:59 am
by Dan Rathbun » Mon Feb 13, 2012 10:55 pm
What version Sketchup and build number, are you running ???
The angle_between method was bugged in early v7 releases.
But it was later fixed.
-

Dan Rathbun
- Top SketchUcator
-
- Posts: 4102
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2013
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by macgile » Mon Feb 13, 2012 11:06 pm
thank's Dan Rathbun
i have sketchup 8 !!!
it's not angle between, but the subtraction. because the calculation of the angle is good.
-
macgile
-
- Posts: 33
- Joined: Sat Jan 19, 2008 10:59 am
by TIG » Mon Feb 13, 2012 11:29 pm
Why not use 90.degrees etc and return the angle.radians to see what it is in degrees too... skip all of the PI and radian confusion... Why are you making your axe/up vectors so complex ? Your figures are off too... - Code: Select all
axe = Geom::Vector3d.new(-0.999782867743517, -0.0208378829670674, 0.0) Vector3d(-0.999783, -0.0208379, 0) axe.normalize! Vector3d(-0.999783, -0.0208379, 0) up = Geom::Vector3d.new(0.00335712544250249, -0.161071856847676, 0.98693697196954) Vector3d(0.00335713, -0.161072, 0.986937) up.normalize! Vector3d(0.00335713, -0.161072, 0.986937) 90.degrees 1.5707963267949 Math::PI/2.0 1.5707963267949 up.angle_between(axe) 1.5707963267949 angle = (Math::PI/2.0) - (up.angle_between(axe)) 2.22044604925031e-016 This is a a simple tolerance issue... angle==0 false angle=(angle*10**6).round.to_f/10**6 angle==0 true
...
Last edited by thomthom on Tue Feb 14, 2012 9:52 am, edited 1 time in total.
Reason: Wrapped the code sample in a [code] block
TIG
-

TIG
- Global Moderator
-
- Posts: 14011
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2013
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by Dan Rathbun » Mon Feb 13, 2012 11:30 pm
It's a tiny tiny wee little smidgen Floating Point Error. Round your numbers off to a reasonable number of decimal places. Your inputting double precision numbers, but Sketchup's internal tolerance for geometry is 0.001 inch. You can use the Length class to test if two numbers are equal within Sketchup's tolerance, even though they are angles: (your not changing the objects, your creating two new Length objects for comparison.) (Math::PI/2.0).to_l == up.angle_between(axe).to_l>> true
-

Dan Rathbun
- Top SketchUcator
-
- Posts: 4102
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2013
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by macgile » Tue Feb 14, 2012 12:11 am
TIG wrote:Why not use 90.degrees etc and return the angle.radians to see what it is in degrees too... skip all of the PI and radian confusion...
=====> I tested with 90.degrees, but I thought it was the conversion that was bad
Why are you making your axe/up vectors so complex ? Your figures are off too... axe = Geom::Vector3d.new(-0.999782867743517, -0.0208378829670674, 0.0)
=====> because it is real vectors returned with axe.inspect I was given a real example.
### Which is a very tiny number that's ALMOST zero This is a a simple tolerance issue...
======>Tolerance has importance here because it is cumulative.
### BUT to test for tiny values use something like: ### a 'rounding' method - here to 6dp. angle=(angle*10**6).round.to_f/10**6 angle==0 true ### This will then trap for these tiny inaccuracies... ...
-
macgile
-
- Posts: 33
- Joined: Sat Jan 19, 2008 10:59 am
by Dan Rathbun » Tue Feb 14, 2012 12:41 am
-

Dan Rathbun
- Top SketchUcator
-
- Posts: 4102
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2013
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by thomthom » Tue Feb 14, 2012 9:54 am
-

thomthom
- Global Moderator
-
- Posts: 17688
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: thomthom
- Operating system: Windows
- SketchUp version: 8
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by Ad Machine » 5 minutes ago
Need SketchUp Books, Models, Styles or Textures? Check out our One Stop Shop for SketchUp. Premium Members get 20% discount!
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|