sketchucation logo sketchucation
    • Login
    1. Home
    2. Paciente8159
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    P
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 3
    • Groups 1

    Paciente8159

    @Paciente8159

    10
    Reputation
    1
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    Paciente8159 Unfollow Follow
    registered-users

    Latest posts made by Paciente8159

    • RE: Find out if point is inside solid

      @sdmitch said:

      It should if "point" is truly inside the solid. If it is a model point then it will need to be transformed by the inverse of the solid's transformation.

      Thanks
      Yes the point must be in the solid(group) coordinate space.

      I've changed the code a bit to allow shell (outer face) testing
      Here it is:

      Edited:
      After some testing still something was not OK.
      I realized that when the ray crosses an edge it hits 2 different planes and through a vertice it can hit an unknown number of faces. The solution I came is that the ray crosses the solid in only one point. So instead of keeping track of how many faces it hits, I register all points the ray hits the solid and then perform a uniq-like operation to the array to count the number of points/hits.
      I've updated the code.

      For the filtering uniq! doesn't work (guessing because it uses eql? and this is not implemented in Point3d)
      Also tried

      pts.uniq! {|pt| pt.to_a}
      

      but it didn't worked, but since the raycast is parallel to X axis comparing x coordinate does the trick

      def point_insidesolid?(point, solid, exclude_surface=false)		
      		vect = Geom;;Vector3d.new(1,0,0)
      		pts = []
      		solid.entities.grep(Sketchup;;Face).each do |face|
      			if(FaceTools.is_pointof_face?(point,face))
      				return true unless exclude_surface
      				return false
      			else
      				pt = Geom.intersect_line_plane([point,vect], [face.vertices[0].position, face.normal])
      				if(!pt.nil?)
      					if(FaceTools.is_pointof_face?(pt,face) && pt.x>point.x)
      						pts.push pt
      					end
      				end
      			end
      		end
      		
      		ptsuniq = pts.uniq {|pt| pt.x}
      
      		return ptsuniq.count%2!=0
      	end
      
      	def point_insideface?(point,face)
      		case(face.classify_point(point))
      			when Sketchup;;Face;;PointInside, Sketchup;;Face;;PointOnVertex, Sketchup;;Face;;PointOnEdge
      				return true
      		end
      		
      		return false
      	end
      
      
      posted in Developers' Forum
      P
      Paciente8159
    • RE: Find out if point is inside solid

      Is this OK?
      The same principle. A raycast from the testing point. I'm only counting how many faces it sees in one direction and only if the point hits the face on the inside (from the testing point)
      To also include the outter shell of the solid the point classification must be changed to validade Vertex and Edges hits.

      Thanks

      Here is the code

      def point_insidesolid?(point, solid)
      		return false unless solid.manifold?
      
      		#vector that goes through the origin
      		vec = Geom;;Vector3d.new(1,0,0).normalize
      		counter = 0
      		solid.entities.grep(Sketchup;;Face).each do |face|
      			pt = Geom.intersect_line_plane([point,vec], [face.vertices[0].position, face.normal])
      			if(!pt.nil?)
      				if(face.classify_point(pt)==Sketchup;;Face;;PointInside)
      					if(pt.x>point.x)
      						counter +=1
      					end
      				end
      			end
      		end
      		
      		return false unless counter%2!=0
      		return true
      	end
      
      posted in Developers' Forum
      P
      Paciente8159
    • RE: Sketchup CNC

      I'm cooking something too.
      Check out my blog http://paciente8159lab.blogspot.pt/2013/10/sketchup-3d-to-gcode-plugin.html

      posted in Woodworking
      P
      Paciente8159