473,396 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
Apr 15 '07 #1
16 1702
Killer42
8,435 Expert 8TB
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?
Apr 15 '07 #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?
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.
Apr 16 '07 #3
Killer42
8,435 Expert 8TB
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...
Expand|Select|Wrap|Line Numbers
  1. Select Case (AreaCovered - D)
  2.   Case -0.03 To 0.03 ' Gray area.
  3.     ReturnVal = "X"
  4.   Case Is < 0        ' Not touching.
  5.     ReturnVal = 1
  6.   Case Else          ' Overlap.
  7.     ReturnVal = 0
  8. End Select
Apr 16 '07 #4
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
Apr 17 '07 #5
Killer42
8,435 Expert 8TB
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).
Apr 17 '07 #6
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.
Apr 18 '07 #7
Killer42
8,435 Expert 8TB
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.
Apr 18 '07 #8
Killer42
8,435 Expert 8TB
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+circle 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
File Type: zip Sensor.zip (2.2 KB, 110 views)
Apr 18 '07 #9
Killer42
8,435 Expert 8TB
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.
Apr 18 '07 #10
Killer42
8,435 Expert 8TB
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
File Type: zip V03.zip (9.7 KB, 89 views)
Apr 18 '07 #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. :)
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.
Apr 18 '07 #12
Killer42
8,435 Expert 8TB
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.

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.
Apr 18 '07 #13
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
Apr 19 '07 #14
Killer42
8,435 Expert 8TB
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.
Apr 19 '07 #15
Is there a way to attach my files in this forum so that I can show what I am talking about?
Apr 21 '07 #16
Killer42
8,435 Expert 8TB
Is there a way to attach my files in this forum so that I can show what I am talking about?
I think that if you post a message, then use the "Edit" option to go back and edit it, there is a "manage attachments" option there somewhere. Keep in mind, you only have 5 minutes to edit a message before it becomes permanent.
Apr 22 '07 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Thomas Storm | last post by:
Is there a method in JavaScript that will detect and return the coordinates of a mouse click? For example, if someone clicked the mouse within the browser window, the method would return...
4
by: SStory | last post by:
I am trying very hard to take an image and fill a shape with part of it. The way I do it is get a rectangle for the basic shape, add to a region, make some other shapes and exclude form region....
3
by: steve | last post by:
Hi All I have textboxes within a TableLayoutpanel and I want to be able to position an independant control adjacent to a selected textbox This independent control allows selection of text to...
26
by: pamelafluente | last post by:
Hi , I have a DIV element in a page with a lot of other stuff (the page can scroll several times) absolutely positioned: <div id="MyDIV" <br<brFooter </div> Just after the page load, I...
0
by: saravanansvks | last post by:
Dear Friends, I have prepared a programme in Visual Basic for SHAPE OPERATOR.But my coding are changing the shape only.It does not changes the fill style of the shape tool .And it is not giving ant...
2
by: nsharish20 | last post by:
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...
1
by: Cainnech | last post by:
Hi all, I've got a bit of a challenge. I've got a script which displays the mouse coodinates if you click on an image. Now I would like to convert these coordinates to pixelnumber. Let me see if I...
0
by: raylopez99 | last post by:
keywords: logical coordinates, page coordinates, world coordinates, device coordinates, physical coordinates, screen coordinates, client coordinates. offset rectangle. WYSIWYG rubber rectangle...
12
by: ab12 | last post by:
I'm trying to write a program in C that gets a shape outlined with asterisks from the user, and returns that shape filled with asterisks. It will also get the coordinates of a point inside the shape...
4
by: mbatestblrock | last post by:
I hope this makes some sense. My ultimate goal here is to execute a block of code if the mouse has not moved in a minute or so within the broswer. The machine I am running this on is for internal...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.