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

    Posts

    Recent Best Controversial
    • Pickray

      Hello to all,

      There's something I don't understand (no, many things) and that's about pickray.
      Suppose I have a model existing of a single edge. Then I create a ray from the eye through one of the two endpoints of the on screen projection and try to find the intersection of that ray with the edge. Why is the ray (a line) missing the edge? I'm totally confused because I presumed that the result had to be the startposition (or endposition, depending of the screencoordinates) of the edge.

      An example

      def exp_a
        mod = Sketchup.active_model
        view = mod.active_view
        ents = mod.entities
        ents.clear!
        edges = ents.add_edges([0, 0, 0] , [100, 100, 100]) 
        edge = edges[0]
        pt = view.screen_coords(edge.start.position)
        ray = view.pickray(pt.x, pt.y)
        Geom.intersect_line_line(edge.line, ray)
      end
      

      The result is nil.

      Can anybody tell me what is wrong with my assumption that in this case the result should be [0, 0, 0]? What is wrong with my understanding of pickray?

      posted in Developers' Forum
      A
      ahjkuipers
    • RE: Loops

      Problem solved!!!
      It's all about vectors. One of the arguments of the method that is resposable for creating the protrusions must be a vector or the order of the four given points of the rectangle must choosen in a way that the vector can be derived as the difference between the first two points of de rectangle.

      ` def findface(pt)
      arr = Sketchup.active_model.entities.grep(Sketchup::Face)
      arr.each {|f| return f if f.classify_point(pt) == Sketchup::Face::PointInside}
      return nil
      end

      def body
      ents = Sketchup.active_model.entities
      ents.clear!
      f = ents.add_face([0, 0, 0], [60, 0, 0], [60, 40, 0], [0, 40, 0])
      f.pushpull(-30)
      end

      def protr(array, extrusion)
      ents = Sketchup.active_model.entities
      base = ents.add_face(array)
      arcvector = array[1].vector_to(array[0])
      basenormal = base.normal
      depthvector = basenormal.cross(arcvector).reverse
      width = array[1].distance(array[0])
      depth = array[2].distance(array[1])
      basenormal.length = extrusion - width/2
      basecenter = Geom::Point3d.new
      basecenter.x = (array[0].x + array[1].x)/2
      basecenter.y = (array[0].y + array[1].y)/2
      basecenter.z = (array[0].z + array[1].z)/2
      center = basecenter + basenormal
      base.pushpull(extrusion + 1)
      ents.add_arc(center, arcvector, depthvector, width/2, 0, Math::PI)
      basenormal.length = extrusion + 0.5
      findface(basecenter + basenormal).pushpull(-depth)
      ents.add_circle(center, depthvector, 1)
      findface(center).pushpull(-depth)
      end

      def test
      body
      protr [[22.0, 8.0, 30.0], [22.0, 20.0, 30.0], [10.0, 20.0, 30.0], [10.0, 8.0, 30.0]], 14.0
      protr [[35.0, 8.0, 30.0], [47.0, 8.0, 30.0], [47.0, 20.0, 30.0], [35.0, 20.0, 30.0]], 14.0
      end`

      posted in Developers' Forum
      A
      ahjkuipers
    • RE: Loops

      The troubles appear in the following simplified case.

      def example
        ents = Sketchup.active_model.entities
        ents.clear!
        # body
        pt0 = [0, 0, 0]
        pt1 = [10, 0, 0]
        pt2 = [10, 6, 0]
        pt3 = [0, 6, 0]
        ents.add_face(pt0, pt1, pt2, pt3).pushpull(-8)
        # protrusion 1
        pt0 = [2, 2, 8]
        pt1 = [4, 2, 8]
        pt2 = [4, 4, 8]
        pt3 = [2, 4, 8]
        ents.add_face(pt0, pt1, pt2, pt3).pushpull(6)
        center = [3, 2, 10]
        ents.add_circle(center, [0, 1, 0], 0.5)
        # protrusion 2
        pt0 = [7, 2, 8]
        pt1 = [9, 2, 8]
        pt2 = [9, 4, 8]
        pt3 = [7, 4, 8]
        ents.add_face(pt0, pt1, pt2, pt3).pushpull(6)
        center = [9, 3, 10]
        ents.add_circle(center, [1, 0, 0], 0.5)
      end
      

      I succeeded in writing a method that is able to place the spikes at all six (maybe more) sides of the body, no matter how the body is transformed in 3D. The problem is how to determine the face on which the circles (drilling holes) are placed. In the mean time I have found a solution that exists of an extra boolean parameter in the parameterlist of the method. But that's not a satisfactory solution: the choice of the parametervalue is a matter of trial and error (not such an attempt with just two possibilities). The method that generates the spikes now is something as 'dosomething(face, extrusion, semaphoor = true)'. I was hoping that all your answers lead me to the conclusion that the trial and error parameter 'semaphoor' is redundant.

      posted in Developers' Forum
      A
      ahjkuipers
    • RE: Loops

      Finally: the solution

      The face I used was part of another face. And in that case it seems that the control over the order in which the vertices of the smaller face appear is taken over by the other face. Your answers helped me to discover that phenomenon. Is this assumption correct?

      posted in Developers' Forum
      A
      ahjkuipers
    • RE: Loops

      Thank for your help. I think your answers bring the solution within sight. My apologies for the rather stupid 'dosomething' method. At least I should have written 'dosomething(face, ..)'. And there exactly lies the bottleneck. Even if all the entities are erased at the very beginning of 'helpme' the problem still occurs in the method 'dosomething(face, ..)'. But I can smell the scent of a solution.

      posted in Developers' Forum
      A
      ahjkuipers
    • RE: Loops

      Thanks TIG
      I think the solution indeed lies in matching - what you called - points and vpoints. I'm going to give it a try. It is a lot of work because my method 'dosomething' really exists of a couple of tranformations that required already all my knowledge of maths!!!

      posted in Developers' Forum
      A
      ahjkuipers
    • RE: Loops

      Still not happy with your answers.
      Take a look at the next method, based on my old one.

      ` def helpme(a0, a1, a2, a3)
      ents = Sketchup.active_model.entities
      face = ents.add_face(a0, a1, a2, a3)
      for i in 0..3
      puts face.vertices[i].position
      end

      dosomething

      end`

      There are eight possibilities to define the rectangle but the output of the method will give seven times the same answer and exactly once a different one. I need all eight different answers. The dependency of clockwise/ccw is not really the problem because the method 'dosomething' already copes with this item.

      posted in Developers' Forum
      A
      ahjkuipers
    • RE: Loops

      @slbaumgartner said:

      You provided the points in anti-clockwise order as seen from above, which means the normal vector to the face would point upward (+z). Entities#add_face automatically forces the normal of a face drawn at z=0 to point downward, which causes your vertices to be traced in the opposite (clockwise) order. You can reverse the face after drawing it to correct for this, but there is no option by which you can turn off this "feature".

      Thanks for your quick response! It helps a lot but still it is not the total solution. A clockwise definition with four points can take place in four different way's, depending on which point is the first one. I tried the four possibilities in my little method. The response is still a bit confusing!!! I need the exact order.

      posted in Developers' Forum
      A
      ahjkuipers
    • Loops

      Hello to all,

      I have a problem and wonder if someone can help me. A small example will illustrate the problem:

      ` def helpme
      ents = Sketchup.active_model.entities
      a0 = [0, 0, 0]
      a1 = [5, 0, 0]
      a2 = [5, 3, 0]
      a3 = [0, 3, 0]
      face = ents.add_face(a0, a1, a2, a3)
      for i in 0..3
      puts face.vertices[i].position
      end

      dosomething(face)

      end`

      There is a difference in the order of the four points shown in the output and the order of points, used in the definition of the face. The outcommented method needs to do something based on the original sequence. A solution or at least a hint would be appreciated.

      posted in Developers' Forum
      A
      ahjkuipers
    • 1 / 1