# Copyright 2005, @Last Software, Inc. # This software is provided as an example of using the Ruby interface # to SketchUp. # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #----------------------------------------------------------------------------- require 'sketchup.rb' #----------------------------------------------------------------------------- def closestPointsGeomTest line1 = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)] line2 = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,100)] # 0,0,0 on each line should be closest because both lines start from # that point pts = Geom.closest_points line1, line2 if (pts) UI.messagebox pts else UI.messagebox "Failure" end end def fitPlaneToPointsGeomTest point1 = Geom::Point3d.new 0,0,0 point2 = Geom::Point3d.new 10,10,10 point3 = Geom::Point3d.new 25,25,25 begin plane = Geom.fit_plane_to_points point1, point2, point3 rescue UI.messagebox $!.message end if (plane) UI.messagebox plane else UI.messagebox "Failure" end end def intersectLineLineGeomTest # This line starts on the X axis starting 10 points out and gradually goes up in Y line1 = [Geom::Point3d.new(10,0,0), Geom::Vector3d.new(1,1,0)] # This line follows the X axis but, 10 points up on Y. line2 = [Geom::Point3d.new(0,10,0), Geom::Point3d.new(20,10,0)] pt = Geom.intersect_line_line line1, line2 if (pt) UI.messagebox pt # returns nill if lines are parallel else UI.messagebox "Failure" end end def intersectLinePlaneGeomTest # This is really the normal which follows the x axis. The plane is # perpendicular plane1 = [Geom::Point3d.new(-10, 0 ,0), Geom::Vector3d.new(1,0,0)] # This line follows the x axis line1 = [Geom::Point3d.new(-10,0,0), Geom::Vector3d.new(1,0,0)] # returns -10, 0, 0 pt = Geom.intersect_line_plane(line1, plane1) if (pt) UI.messagebox pt else UI.messagebox "Failure" end end def intersectPlanePlaneGeomTest # This is really the normal which follows the x axis. The plane is # perpendicular (or parallel to the Y axis) plane1 = [Geom::Point3d.new(-10, 0 ,0), Geom::Vector3d.new(1,0,0)] # This is really the normal which follows the y axis. The plane is # perpendicular (or parallel to the X axis) plane2 = [Geom::Point3d.new(0,-10,0), Geom::Vector3d.new(0,1,0)] # returns (-10,-10,0")(0.0,0.0,1.0) line = Geom.intersect_plane_plane(plane1, plane2) if (line) UI.messagebox line else UI.messagebox "Failure" end end def linearCombinationGeomTest point1 = Geom::Point3d.new 1,1,1 point2 = Geom::Point3d.new 10,10,10 # Gets the point on the line segment connecting point1 and point2 that is # 3/4 the way from point1 to point2. point = Geom.linear_combination 0.25, point1, 0.75, point2 if (point) UI.messagebox point else UI.messagebox "Failure" end end def pointToPolygon2DTest end if( not file_loaded?("geomtests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") Geom_menu = plugins_menu.add_submenu("Geom Tests") Geom_menu.add_item("Geom.closest_points") { closestPointsGeomTest } Geom_menu.add_item("Geom.fit_plane_to_points") { fitPlaneToPointsGeomTest } Geom_menu.add_item("Geom.intersect_line_line") { intersectLineLineGeomTest } Geom_menu.add_item("Geom.intersect_line_plane") { intersectLinePlaneGeomTest } Geom_menu.add_item("Geom.intersect_plane_plane") { intersectPlanePlaneGeomTest } Geom_menu.add_item("Geom.linear_combination") { linearCombinationGeomTest } Geom_menu.add_item("Geom.point_to_polygon_2D") { pointToPolygon2DTest } end #----------------------------------------------------------------------------- file_loaded("geomtests.rb")