|
Assuming the ellipse, rectangle and line will be made from points ordered uniformly around their 'perimeter'...
If they represent...
1) An ellipse: the distances from the geometric centre to each point will be linearly distributed... ie: the average distance from the centre should be within an epsilon amount to half way between the maximum and minimum distances.
2) A line: take any two points and calculate the 'linear line equation' y=mx+c... then see if all other points fit the equation.
3) A rectangle: the points would fit into four 'linear line equations', one for each side; find a pair of points that at least one other points fits into, repeat with the remaining points until four sides have been found and there are no points left. (This is the hardest of the three... there may be a better way).
4) A polygon... if none of the other conditions apply.
Calculating the bounding rectangle is simple... look for maximum/minimum points in both the vertical/horizontal directions.
I believe I've done something like this before... I'll see if I can find some code.
Hope this helps.
Matthew Butler
|
|
|
|
|
Matthew Butler wrote: points ordered uniformly
I don't think you could assume this. The points would be collected while the user drags the mouse with the main button help down. So some of the points will be "closer" to each other than others because the speed at which the user moves the mouse will probably not be very even.
Thanks for the other suggestions though!
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
To solve the 'random mouse speed' you could only draw the next point when it is a pre-determined distance from the last... however that may not fit in with your design.
However a better way may be to look at the angles between successive points...
(This is how I did it)...
For a line, the angles would be around 180 degrees.
For a rectangle, there will be (over a few points), 3 x 90 degree turns, with the rest 180 degrees. (The end point will be in proximity to the first).
For an ellipse, the angles will always be either below or above 180 degrees... depending on whether it is drawn clockwise or not.
And a polygon will not follow any of the previous patterns.
... self explanitory.
I stored each shape's pattern and iterated through them looking for a match... similar to a regex... but geometrically, with an 'accuracy' value.
If not accurate enough (<75%), I assumed it to be random.
Hope this helps.
Matthew Butler
|
|
|
|
|
Matthew Butler wrote: For an ellipse, the angles will always be either below or above 180 degrees... depending on whether it is drawn clockwise or not
All it takes is a well drawn spiral, and BOOM!
Semicolons: The number one seller of ostomy bags world wide. - dan neely
|
|
|
|
|
Oops. So much for testing... I missed that one.
-one quick copy and paste later-
if (CalcLength(points[0], points[points.Length - 1]) > maxDev) return false;
Checkmate.
Matthew Butler
|
|
|
|
|
The maximum and minimum X Y coordinates will not do for an ellipse, you need to determine the equation for the ellipse and then take the end points of the axes.
|
|
|
|
|
I was refurring to the maximum and minimum distances between the points and the geometric centre... not the bounds of the ellipse.
......ooooooooooo......
...ooo.....|.....ooo...
..o........m........o..
.o.........|.........o.
.o.........X----M----o.
.o...................o.
..o.................o..
...ooo...........ooo...
......ooooooooooo...... m is the 'minimum' radius of the ellipse.
M is the 'maximum' radius of the ellipse.
If it was an ellipse, the average distance between each point and the centre, X, would be approximately equal to the (M + m) / 2;
This was my original idea... I posted my alternative method (my prefured way and the method I actually got running - in a past program) as a different reply.
I believe I saw this method a while ago, but I can't remember where.
Matthew Butler
|
|
|
|
|
In your definition wouldn't an ellipse or a rect be a polygon? so all you want to really know is if a set of points represent a line or a polygon.
Hence the simple solution is if the points aren't all collinear then they represent a polygon, otherwise they represent a line or line-segment.
|
|
|
|
|
You might want to try finding line segments (assuming points are dense), and than base your recognition on the segment.
A trick for this is to use Hough Transforms to find significant line segments. [^]
Lines end up as local maxima in the Hough space. You can pick the segment with above value above mode, normalize them, and use the number of segments, as well as the segment values, as a discriminator.
This does a reasonable job, I used it for OCR back in the 90s.
Now that I think about it,look for mouse gesture recognition articles on CP, I think there are a couple, and it is what you are doing.
Learn to write self marginalizing code!
Call 1-888-BAD-CODE
------------------
Silver member by constant and unflinching longevity.
|
|
|
|
|
Hi,
Im trying to work out a fourier series for a wave of period T.
The wave rises in a linear fashion from 0 to T/2, to reach a value of 1
(so its a saw tooth).
From T/2 to T it is 0.
Im trying to work out Ao, Bn, and An for the general formula:
If I integrate (!), im integrating from 0 to T
<br />
Note: ! means integral<br />
<br />
Ao = 1/(2*PI)*!f(x)<br />
Bn = 1/(PI)*!(f(x)*sin(n*t)<br />
An = 1
Now, my equation and solution I got:
<br />
<br />
Waveform equation:<br />
f(t) = t/(T/2), for 0 -> t -> (T/2)<br />
f(t) = 0, for (T/2) -> t -> T<br />
<br />
Coefficients:<br />
For Ao I got: 1/4<br />
For Bn I got: -cos(n*t)/((T/2)*n)<br />
For An I got: (1/(PI*n^2)*(cos(n*PI)-1)<br />
<br />
f(x) = Ao + SUM(An*cos(n*t)) + SUM(Bn*sin(n*t))<br />
<br />
To work out An and Bn, I was using the integration shortcuts
<br />
<br />
!t*sin(n*t) = -(t*cos(n*t)/n + sin(n*t)/(n^2) + c<br />
!t*cos(n*t) = (t*sin(n*t)/n + cos(n*t)/(n^2) + c<br />
<br />
I wont post all the work because it will be too messy to follow online. I know the above answers are wrong because the harmonics don't sum to build the original wave.
If anyone who's switched on with fouriers feels like some 'revision', I'd love to know what you come out with ... (i'll even check your answer for you )
Cheers,
Mark.
|
|
|
|
|
Since your function isn't defined on the interval [-pi,pi] are you doing the change of variables properly? That is, if you are on an interval T rather than pi, you should transform according to:
x = pi * x'/T
dx = pi * dx'/T
|
|
|
|
|
Hmmm ok, i'll try that.
My line of thought was that if i'm counting t, from 0 -> T. When t gets to (T/2), the result of
<br />
f(t) = t/(T/2)<br />
will be a linear rise from 0 to 1.
I hate Fourier's
Cheers,
|
|
|
|
|
MarkBrock wrote: I hate Fourier's
You are not the only one. I had to write a dossier for the teacher of "Circuit's theory" (I don't know if it has meaning on english, on spanish is: "Teoría de circuitos") to take an A insteads a B, and I was hating it from the beggining. The worst... she didn't give me the A but she DID use my dossier to explain fourier in (at least) the following 2 years. F****ing b***h. (afterwards I went to germany and don't know anymore if she is still using it or not, so I guess my work was not so bad)
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Nelek wrote: I had to write a dossier
"Pssst... this is grey squirrel....do you have the dossier?"1
1 Reminiscing over Trigger Happy TV.[^]
Semicolons: The number one seller of ostomy bags world wide. - dan neely
|
|
|
|
|
No Sorry, that was about 8 years ago and since then I lived in 4 different places. It got lost in one of the movings.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Hi,
I just figured the problem out. Turns out it was my basic integration that was the problem :P
<br />
<br />
Ao = 1/4<br />
An = (1/(n^2*PI^2))*(cos(n*PI)-1)<br />
Bn = (-1/(PI*n))*cos(n*PI)<br />
<br />
f(t) = Ao + SUM(An*cos(n*w*t)) + SUM(Bn*sin(n*w*t))<br />
<br />
Where SUM is from n=1 -> n =infinity, and w = (2*PI)/T<br />
<br />
Thanks for your help anyway.
Cheers,
|
|
|
|
|
Ah, great. I didn't have time to do the math yesterday - had to fumigate my apartment.
Anyways, I like the problems you post here - takes me waaaaay back and is a good review to keep the basics fresh. I kind of wish there was more participation on this particular board.
|
|
|
|
|
Hi,
Sorry for my english , i will try to explain my problem, i hope someone can tell me where can i find more information.
I write a program for drawing contour which can contain lines and arces. I need to somehow make constraints beetwin points of contour. e.g. one point can be horozontally or vertically aligned with another point or a X,Y distance can be given between points.
I come to point where i can draw contour with mouse and apply constraint, but my problem is that i can't conclude when can i apply new constraint so it does not confilct with existing.
Any help is welcome.
|
|
|
|
|
How are you drawing the contours now? Do you draw them in reference to an underlying grid?
|
|
|
|
|
No, there is no grid. I have problem where i can find out when my sketch is well defined. I think i have to solve a system of equations. If you imagine rectangle with points A,B,C,D and if point A is top left and point D is top right then i woud have following constraints that defines rectangle:
1. A.x = B.x
2. B.y = C.y
3. C.x = D.x
4. A.y = D.y
5. B.x = C.x + Kx , where Kx is widith of rectangle
6. D.y = C.y + Ky , where Ky is height of rectangle
I know that this constraints completly defines rectangle, but my program doesnt so it allows more constraint to be added, it usualy hapens that curve run away like a snake from the screen when i add one constraint more.
I think i need somehow solve this system of equatations , but i don't know how yet.
|
|
|
|
|
I don't think I understand. Initially I thought you were trying to determine if a point is inside the rectangle. I think you are trying to do something different. What you can do to define the rectangle is to make 4 equations for each side of the rectangle. For example, the equation of a line connecting two points (x1,y1) and (x2,y2) is:
(y2 - y1)
0 = y - y1 - --------- (x - x1)
(x2 - x1)
I'm not exactly sure what you are trying to do with the constraints...
Are you trying to join shapes together?
Are you trying to see if a point (x,y) lies inside or outside of the rectangle?
|
|
|
|
|
I use contraints to create parametric shape. This feature can be seen in CAD like drawing programs, i only need very small part of such feature in my program.
Simply when constraints are applied to points of the shape , i can modify shape by changing parameters of constraints e.g. like distance.
|
|
|
|
|
Your constraints look correct. Perhaps it is a coding problem? Are you able to post a section of the source code? If you are using C++, you can make your code aware of the rectangle by specifying it as a struct, for example...
|
|
|
|
|
I have a problem of choosing subsets. I wonder if anyone have any idea about it.
We have n sets each having k m-tuple subsets of a known set. I want how to know to find the maximum n-tuple sets each having one and only one member from each of n given sets. These sets also should be non-overlapping. To clarify it I make an example:
n=3, k=4, m=2
set 1: {{1,8}, {2,6}, {5,7}, {2,9}}
set 2: {{3,6}, {1,4}, {2,9}, {5,6}}
set 3: {{2,3}, {1,8}, {7,8}, {3,5}}
Now we are looking for maximum 4 (k) sets that are non-overlapping. Each set have a member from set 1, set 2 and set 3.
a solution can be:{{5,7}, {3,6}, {1,8}} -- {{2,9}, {1,4}, {3,5}} but this solution has 2 sets, can we find solution with 3 or 4 sets (to cover the maximum number of 3*4 members)?
|
|
|
|
|
Assign each subset an integer and make random draws from a uniform distribution to choose subsets randomly deleting them from the set as they are selected.
|
|
|
|
|