Shape coordinates logic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nsharish20
    New Member
    • Apr 2007
    • 14

    Shape coordinates logic

    Hi,

    I have a sensor in the shape of a small circle and a hole which is larger than the sensor circle. Basically i have a small circle and a large circle. Now i would like to check these conditions:

    (1) IF the small circle is in the range of the large circle, then the result should be 0.

    (2) IF the small circle is not in the range of the large circle, the result should be 1.

    (3) IF the small circle is partially blocked by the larger circle or very close to it by 0.03 from inside or outside the larger circle, then the result should be X.

    I don't want to write any coding for this right now but a simple logic statements in the form of IF conditional statements.

    This is what I have so far. Please feel free to correct my logic statements

    r1 is radius of larger circle and same applies to x1,y1

    r2 is the radius of smaller circle and same applies to x2,y2

    (1) IF(SQRT((X2-X1)^2+(Y2-Y1)^2)< abs(R2-R1), THEN THE VALUE IS 0

    (2) IF(SQRT((X2-X1)^2+(Y2-Y1)^2)> abs(R2-R1), THEN THE VALUE IS 1

    (3) (a) IF(SQRT((X2-X1)^2+(Y2-Y1)^2)<= R1+R2, (from outside of the larger circle), THEN VALUE IS X

    (b) IF(SQRT((X2-X1)^2+(Y2-Y1)^2)= abs(R2-R1), (from the inside of the larger circle), THEN VALUE IS X.

    Now my only problem is this: -

    When the edge of the larger circle is very close to the smaller circle by 30 thou or touching, it should be regarded as X (in other words, it should not exceed 0.03 or else it would be a 1 or a 0 depending on whether the sensor in inside the hole or outside of it). Can anybody please help me out? Thanks in advance.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    That was a very good summary of the problem. However, I found you were a little unclear at the end, as to precisely which part you need help with. Is it how to tell whether they are within 0.03 (what units?) or how to return X rather than 0/1, or what?

    Also, am I correct in that we're supposed to assume the circles are concentric? (That is, have the same centre)

    I'm afraid I haven't been over your logic in detail (plus, geometry is not my strong suit). But if I'm reading correctly, abs(R2-R1) gives you the difference in radius between the two circles. So aren't you simply going to test whether this value is larger than 0 but smaller than 0.03?

    Comment

    • nsharish20
      New Member
      • Apr 2007
      • 14

      #3
      Originally posted by Killer42
      That was a very good summary of the problem. However, I found you were a little unclear at the end, as to precisely which part you need help with. Is it how to tell whether they are within 0.03 (what units?) or how to return X rather than 0/1, or what?

      Also, am I correct in that we're supposed to assume the circles are concentric? (That is, have the same centre)

      I'm afraid I haven't been over your logic in detail (plus, geometry is not my strong suit). But if I'm reading correctly, abs(R2-R1) gives you the difference in radius between the two circles. So aren't you simply going to test whether this value is larger than 0 but smaller than 0.03?
      What I want to do is to come up with two conditional statements that will check two cases and produce a result X if it is very close to the edges.

      Case 1: If the small circle is in the range of the larger circle and is very close to the edge of the large circle by 0.03, then the result should be X. What I mean is the distance between the smaller circle edge and larger circle edge should range from 0 to 0.03. So far I was able to come up with a statement which is this: IF(0<=ABS(SQRT( (X2-X1)^2+(Y2-Y1)^2) - ABS(R2-R1))<=0.01) THEN RETURN X

      Case 2: If the small circle is outside of the larger circle and is very very close to 0.03 (distance between the 2 edges), the result should be X. I haven't been able to come up with a conditional statement for that

      The circles cannot be concentric and it varies.

      I am given the X and Y coordinates of the two circles but would like to check the following conditions. Any ideas? Please feel free to correct my logic for the 2 cases.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Ah! I think I get it now, sorry.

        So you're calculating (A) the radius of each circle, and (B) the distance between their centre points. OK so far?

        So let's assume you have values R1, R2 and D. For convenience, I'll add R1 + R2 and call the result AreaCovered (feel free to make up a better name).

        You actually have three conditions to test - close to the edge, overlapping, and not overlapping.

        Sorry, but I find this sort of logic easier to write in a programming language than "pseduo-code". Anyway, how does this sound...
        Code:
        Select Case (AreaCovered - D)
          Case -0.03 To 0.03 ' Gray area.
            ReturnVal = "X"
          Case Is < 0        ' Not touching.
            ReturnVal = 1
          Case Else          ' Overlap.
            ReturnVal = 0
        End Select

        Comment

        • nsharish20
          New Member
          • Apr 2007
          • 14

          #5
          Hey,

          Sorry for my late reply. Your logic seems a little right and I have solved this problem with your help. However I have another problem with another kind of shape design.

          I have a rectangle with a semi-circle on top and I am given X,Y coordinates of the center of the semi-circle. Now I want to come up with conditions that will check whether the smaller circle is in the boundary region of this shape, out of the boundary and in mid-boundary. Can you please think of some mathematical conditions that will produce the desired output?

          IF the smaller circle is out of the boundary, the result is a 1, If it is in the boundary, it is a 0. If it is in the middle, it is an X.

          thanks

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            I won't have time to think this through for at least a couple of hours (at work right now). But it doesn't seem too tough. You can check for overlap with the rectangle and the (half) circle independently. If it overlaps either, then bingo.

            For simplicity I believe the half-circle can be treated as a full circle, since half of it is inside the rectangle (unless the rectangle is smaller, I guess).

            Comment

            • nsharish20
              New Member
              • Apr 2007
              • 14

              #7
              If I have 4 coodinates of the rectangle: x1,y1,x2,y2, x3,y3, x4,y4 and the radius of the semi-circle, what mathematical approach should i use to determine whether the sensor is in or out or mid? The width of the rectangle is always equal to 2 times the radius of the semi-circle.

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by nsharish20
                If I have 4 coodinates of the rectangle: x1,y1,x2,y2, x3,y3, x4,y4 and the radius of the semi-circle, what mathematical approach should i use to determine whether the sensor is in or out or mid? The width of the rectangle is always equal to 2 times the radius of the semi-circle.
                Some parts are simple. For instance, if the centre of the sensor is within the boundaries of the rectangle on both axes, then it's definitely "in". In other words, if we call the sensor's centre (sx, sy) then

                If (SX + R) >= X1 (left side of rectangle)
                And (SX - R) <= X2 (right side of rectangle)
                then horizontally we are within the bounds.

                Do the same for the Y axis, and you should be close to the right result Still a bit fuzzy around the corners, though - I think this will cause some false positives there.

                There must be a more elegant way to go about this, but it seems to me if you determine that the centre of the sensor is sitting off a corner (in one of the “fuzzy” zones) then you could just check the distance between the corner and (SX, SY). If it’s <= R then you’ve got a hit.

                I’m thinking that I should move this thread to a more general-interest sort of area – would that be alright with you? Not that it’s a problem in the VB forum, but we should try to open up the discussion more to find people who understand collision-detection. I’m just making it up as I go.

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  On my lunch break today, I spent some time playing, and built a very simple little test application. I'll attach a copy here, in case anyone wants to try it out.

                  It just lets you draw a rectangle+circl e shape (which I've referred to as an "object) and wave around a "sensor" with the mouse. The sensor changes colour to indicate whether it's detecting a "collision" with the object.

                  I haven't done anything about the boundary effects yet. That is, the < 0.03 thing. This is just to see whether my logic works so far, and also hopefully get some feedback from you on whether I've understood properly what you're trying to do.

                  It's a VB6 project.
                  Attached Files

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    P.S. I commented out Picture1.Cls so that the "sensor" leaves a trail everywhere it goes. If you put back the Cls (just before the .Circle method) you'll see what it was supposed to look like.

                    Comment

                    • Killer42
                      Recognized Expert Expert
                      • Oct 2006
                      • 8429

                      #11
                      Ok, here's the third version of my test program. The code is pretty messy (though I've now commented it better) but the collision detection seems to be working quite well.

                      Don't worry if you didn't need this - I've been having a ball, playing with it. :)
                      Attached Files

                      Comment

                      • nsharish20
                        New Member
                        • Apr 2007
                        • 14

                        #12
                        Originally posted by Killer42
                        Ok, here's the third version of my test program. The code is pretty messy (though I've now commented it better) but the collision detection seems to be working quite well.

                        Don't worry if you didn't need this - I've been having a ball, playing with it. :)
                        Thanks a lot for your help. I wonder how you are staying up all night to work on this.

                        I am coordinating with excel and VB. In VB, my friend has written some coding and all i do is to put up the conditions for the sensor to read the holes (larger circles) and slots (slot is a hole shape that consists of a semi-circle and a rectangle. There is more that I have to tell you about this assignment and I'll tell you more later as I am busy right now. Thanks for your assistance.

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #13
                          Originally posted by nsharish20
                          Thanks a lot for your help. I wonder how you are staying up all night to work on this.
                          I'm not. Different timezones. I started on my lunch break, continued later on at home. My last message was posted at 9:02PM. It's now 8am, and I'm back at work.

                          Originally posted by nsharish20
                          I am coordinating with excel and VB. In VB, my friend has written some coding and all i do is to put up the conditions for the sensor to read the holes (larger circles) and slots (slot is a hole shape that consists of a semi-circle and a rectangle. There is more that I have to tell you about this assignment and I'll tell you more later as I am busy right now. Thanks for your assistance.
                          No problem. That's pretty much what TheScripts is here for, so we can share our expertise in different areas.

                          Besides, it's been fun so far.

                          Comment

                          • nsharish20
                            New Member
                            • Apr 2007
                            • 14

                            #14
                            So I'll brief you on the problem and I'll give you some excel files that has all the rough work. Later, I can show you the excel file with all the VB codes (to be quiet frank, I haven't changed much in this as I was working a lot on excel). I dont know how I can attach them in this forum?

                            So I have a big circle that consists of 32 small circles called sensors oriented at different places. On top of this I am going to put a blue print of the part. This part print consists of 3 design features. It consists of a bigger inner hole which is always (0,0,r) and is called pilot bore hole. It also consists of holes oriented at different places and they are circular. They are always medium than sensor circles and are called mounting holes. Some part consists of slots that consists of a rectangle and a semi-circle (this kind of a shaped hole is connected to the pilot bore hole (bigger inner circle). The slot can be oriented at any angle on the part.

                            The job of the sensors is to read this print properly thru mathematical formulas and coordinates and assign corresponding values to each hole and slot. If a sensor finds a hole or a slot (meaning if it is in that range), then the value should be 0, if it is close or touching or blocked by the edges, then it should be an X, or else it should be a 1 because the sensor is not in that range. I'll show you my data structure if you can give me your e-mail address so that I can send it you and you can get a good picture of what i am talking about. After doing all this, I have a summary sheet called output worksheet and one column consists of all part numbers and the 32 column consists sensor information. Wherever the sensor finds a 0 in any mounting hole, it reports back to this worksheet.

                            As of now, the problem for the holes is solved and the sensor is able to distinguish whether it is in, out or close/mid/blocked. Now I am trying to solve the problem for slots. For slots, I have created a calculation which will calculate x1,y1,x2,y2,x3, y3,x4,y4 upon the input of 3 information.

                            If you can come up with a conditional statement for the sensors that will be able to read the slot using these pieces of information, that would be awesome. Please take your own time to think this through.

                            Please feel free to ask any questions if you have any. Thanks for your help

                            Swamy

                            Comment

                            • Killer42
                              Recognized Expert Expert
                              • Oct 2006
                              • 8429

                              #15
                              Sorry, I don't think I'll have a chance to read (and think about) this until tomorrow morning (around 11 hours from now). Depending on how busy things are at work, maybe not until lunch time.

                              In the meantime, hang in there. My sample code was mostly broken down into steps to illustrate thiings. You should be able to work out what they do and try different combinations of things. With work, I would imagine that the entire routine could be combined into one or two (extremely long) comparison statements. I could be wrong, though.

                              (Note that none of my stuff would work for any arbitrary shape - it is written for this one specific one. I've never done much collision-detection before.)

                              I'm going to move this thread over to a general-interst area, like I mentioned. Hopefully that way you'll get more than just my input. If you're lucky, you might even find someone who knows what they're talking about.

                              Comment

                              Working...