Board index » Visual Studio » Shapes Area
|
pk4882
|
|
pk4882
|
Shapes Area
Visual Studio282
Hello guys, I've created a form that allow me to draw an Oval shape by clicking and dragging, but I would like to know or calculate the coordinates of each point inside the drawn oval shape; I mean (x,y) of each point located iside the oval shape; how can I do it..!!? Cheers - |
| Grinder
Registered User |
Wed Oct 15 08:15:00 CDT 2003
Re:Shapes Area"Rochdi" <anonymous@discussions.microsoft.com>wrote in message QuoteHello guys, I've created a form that allow me to draw an x^2 / a^2 + y^2 / b^2 = 1 a = width / 2 b = height / 2 assuming that the ellipse axes are coincident with your coordinate system (ie, it's not rotated) ____________ Option Explicit Private Sub Form_Load() Debug.Assert Shape1.Shape = vbShapeOval End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If PointInShape(X, Y, Shape1) Then Me.Caption = "In Shape1" Else Me.Caption = "Not in Shape1" End If End Sub Private Function PointInShape(ByVal X As Single, ByVal Y As Single, ByVal Target As Shape) As Boolean Dim a As Double Dim b As Double If (X < Target.Left) Or (X>= Target.Left + Target.Width) Then PointInShape = False ElseIf (Y < Target.Top) Or (Y>= Target.Top + Target.Height) Then PointInShape = False Else a = Target.Width / 2 b = Target.Height / 2 'offset to shape coordinates X = X - (Target.Left + a) Y = Y - (Target.Top + b) Select Case Target.Shape Case vbShapeOval PointInShape = (X * X / (a * a) + Y * Y / (b * b)) <= 1 'Case ... Case Else 'assume rectangle PointInShape = True End Select End If End Function - |
| Rick
Registered User |
Wed Oct 15 08:18:43 CDT 2003
Re:Shapes AreaQuoteHello guys, I've created a form that allow me to draw an to 2-Oval. The following function takes the X and Y coordinates of the point you want to test plus the Shape control (as an Object) for its arguments. It returns True if the point lies inside of the Oval and False otherwise. It assumes the ScaleMode for the Form is the default setting of Twips. Function IsInsideEllipse(X As Variant, Y As Variant, _ ShapeIn As Shape) As Boolean Dim Xstuff As Double Dim Ystuff As Double With ShapeIn Xstuff = 4 * (X - (.Left + .Width / 2)) ^ 2 / .Width ^ 2 Ystuff = 4 * (Y - (.Top + .Height / 2)) ^ 2 / .Height ^ 2 If Xstuff + Ystuff <= 1 Then IsInsideEllipse = True End With End Function Assuming the Name of the Shape is Shape1, here is an example of calling it from the Form's MouseDown event... Private Sub Form_MouseDown(Button As Integer, _ Shift As Integer, X As Single, Y As Single) Debug.Print IsInsideEllipse(X, Y, Shape1) End Sub Rick - MVP - |
| Ben
Registered User |
Wed Oct 15 09:16:17 CDT 2003
Re:Shapes Area
roll on the argument about whether there are a finite
number of points in the ellipse..... Quote-----Original Message----- |
| Rick
Registered User |
Wed Oct 15 09:30:36 CDT 2003
Re:Shapes Area
I'm not sure I understand your comment... in the real (number) plane, there
are infinitely many points within the boundary of an ellipse; however, on a Form (or PictureBox or wherever the Shape control is placed), there are only a finite number of "points" because the Form is divided (pixilated, if you will) into a fixed grid of very small areas. Rick - MVP Quoteroll on the argument about whether there are a finite - |
| Ben
Registered User |
Wed Oct 15 10:56:46 CDT 2003
Re:Shapes Area
I know! Confusion could arise where the shape is designed
to represent a 'real' plane! I only said that comment because there's been an argument before in which Larry Serflaten, who I'd previously thought to be very intelligent, insisted blindly that there were a *finite* number of points on a mathematical line. Quote-----Original Message----- |
| Rick
Registered User |
Wed Oct 15 11:23:36 CDT 2003
Re:Shapes AreaQuoteI know! Confusion could arise where the shape is designed finite number of points on a mathematical line per se... the discussion resulted from my saying that any two straight line segments contained the same number of points (more mathematically put... there was a one-to-one correspondence between all the points on each line... still a little sloppy there, but close enough<g>). That's a hard concept for most people to accept as it would mean that a one-inch line segment and a one-mile line segment contained the same number of points (that is, the infinity of points on one line was of the same magnitude as the infinity of points on the other). In case you, or anyone else, wants to review the thread, here is the Google link into that thread of 101 articles (my post that started the above subthread is somewhere towards the top of the list): groups.google.com/groups&lr=&ie=UTF-8&oe=UTF-8&threadm=%23JeAJoxSDHA.1552%40TK2MSFTNGP12.phx.gbl&rnum=1&prev=/groups%3Fas_q%3Drothstein%2520vb%2520infinity%2520line%2520points%26safe%3Dimages%26ie%3DUTF-8%26oe%3DUTF-8%26as_scoring%3Dd%26lr%3D%26num%3D100%26hl%3Den">groups.google.com/groups&lr=&ie=UTF-8&oe=UTF-8&threadm=%23JeAJoxSDHA.1552%40TK2MSFTNGP12.phx.gbl&rnum=1&prev=/groups%3Fas_q%3Drothstein%2520vb%2520infinity%2520line%2520points%26safe%3Dimages%26ie%3DUTF-8%26oe%3DUTF-8%26as_scoring%3Dd%26lr%3D%26num%3D100%26hl%3Den Rick - MVP - |
| Larry
Registered User |
Wed Oct 15 11:29:25 CDT 2003
Re:Shapes Area
"Ben Taylor" <anonymous@discussions.microsoft.com>wrote
QuoteI know! Confusion could arise where the shape is designed not say that. Obviously, as Rick pointed out, there are a finite number of points on a line, when that line is drawn a pixelated surface. Perhaps you are mistaken.... Can you cite the exact thread that argument took place in? LFS - |
| Larry
Registered User |
Wed Oct 15 12:12:01 CDT 2003
Re:Shapes Area
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in message
Quote
The part that was the crux of the problem, was your statement: "The notion of distance between two points that are "infinitely" close to each other does not apply. As a matter of fact (and you're going to love this Larry), they are as many points between any two points you select on a line, no matter how close together, as there are on the whole line segment you selected them from!" I have a line A-C, and I select a point B between them. Your statement above says that the number of points in A-B will always equal the number of points in A-B-C. And I'd have to say, that can't be true. There is at least one more point in A-B-C, than there is in A-B. For every point you add to A-B, another point is added to A-B-C. And, A-B never contains point C, which is that extra point.... :-P Your 'theories' would tell you that there could be an infinate number of points in any line segment, but in this case, you can't get to infinity, because there is always that third point C on the same line, yet not part of A-B. For every point you add to A-B, that point also increases A-B-C. Their numbers can never be equal! <g> LFS - |
| Ben
Registered User |
Wed Oct 15 17:22:09 CDT 2003
Re:Shapes Area
I think Rick is right as he obviously remembers it better than you or I do.
But I distinctly got the impression you thought that if the length of the line was finite, then the number of points on it was finite too - until Rick pointed out that there is no lower limit to the size of a point. Forgive me if I was mistaken. "Larry Serflaten" <serflaten@usinternet.com>wrote in message Quote"Ben Taylor" <anonymous@discussions.microsoft.com>wrote - |
| Ben
Registered User |
Wed Oct 15 17:24:17 CDT 2003
Re:Shapes Area
I can remember part of the conversation being:
Larry: "impossible, I tell you!" Rick: "nope, Larry - just impossible for you to *imagine*!" or something along those lines. "Larry Serflaten" <serflaten@usinternet.com>wrote in message Quote"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in message - |
| Grinder
Registered User |
Wed Oct 15 17:40:41 CDT 2003
Re:Shapes Area"Ben Taylor" <nosp@mpleasewerebritish>wrote in message QuoteI can remember part of the conversation being: QuoteNo, I said IMPOSSIBLE! for the mind to imagine It's funny how your recollection has Rick being (academically) hostile, when it appears he wasn't. - |
| anonymous
Registered User |
Wed Oct 15 20:52:02 CDT 2003
Re:Shapes Area
Hi, actually I wanted once U draw a shape, all the (x,y)s
located inside the shape will be displayed maybe some where in a textbox; but anyway thanks very match U have given me the code that I could work on it. but could U please explain to me the Idea or the logic of the this line of code: Xstuff = 4 * (X - (.Left + .Width / 2)) ^ 2 / .Width ^ 2 I mean,what have we done in this line of code..!!? Cheers Quote-----Original Message----- |
| Rick
Registered User |
Thu Oct 16 11:49:37 CDT 2003
Re:Shapes Area"Larry Serflaten" <serflaten@usinternet.com>wrote in message Quote"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in message add that I'm confused on. No points are being added to the line... all of its points (the whole infinitude of them) are what makes the line a line. I would say, however, if you are trying to examine each point (in some way) one after the other, that is not a proper thing to do with an infinite set. An infinite set cannot be enumerated... it's uncountably large. The only way to establish if one set is of the same "size" as another is to see if a one-to-one correspondence of their points can be established. If it's true that each point in one set has a unique "partner" in the other set, and vice-versa, then the two sets are of the same size. I established this in the referenced thread using the parallel line, connect the endpoints, project those connected endpoints to a "vertex" point and then draw lines from the vertex point to any point on either line to produce the unique partner on the other line. Perhaps I skewed the problem for you by saying they have the "same number of points"... technically, that would mean we could enumerate (count) those points, and we can't. All we can really say that the infinity of points in one line is of the same magnitude (not sure if that is the mathematically technical word for it) as in the other. That has significance because there are many orders of magnitude for infinity... some (actually, infinitely many) infinities are large in magnitude than others. QuoteYour 'theories' would tell you that there could be an infinate number covered by my not understanding what "add" meant above. By the way, these are not **my** theories... they are, with some allowance for my restating them without the mathematical rigor that should be placed behind them and from the fact that I was stating them from memory for math courses I took nearly 40 years ago. Here is a couple of links that you may find interesting. scidiv.bcc.ctc.edu/Math/infinity.html">scidiv.bcc.ctc.edu/Math/infinity.html www.hypermaths.org/quadibloc/math/infint.htm">www.hypermaths.org/quadibloc/math/infint.htm www.trottermath.com/infinity.html">www.trottermath.com/infinity.html www.pbs.org/wgbh/nova/archimedes/infinity.html">www.pbs.org/wgbh/nova/archimedes/infinity.html Rick - MVP - |
| Larry
Registered User |
Thu Oct 16 13:17:56 CDT 2003
Re:Shapes Area
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote
From one of those links: "Although his work changed the whole course of mathematics, Cantor was rewarded with a lifetime of controversy, including condemnation by many of the most influential mathematicians of his time." At least I'm in a notable crowd! <g> LFS - |
| Rick
Registered User |
Thu Oct 16 13:28:28 CDT 2003
Re:Shapes AreaQuoteFrom one of those links: one's mind around because it is so non-worldly... the are no concrete examples you can point to in the same way as, say, a dozen eggs in an egg carton. And in Cantor's day, the stuff he developed was a real (mathematical) foundation shaker. If was for mathematicians of his day similar to Einstein and Quantum Mechanics. As brilliant as Einstein was, and as revolutionary as his own theories were, he could not bring himself to fully accept the underlying "uncertainty principle" that is fundamental to Quantum Mechanics. His famous "I don't believe God plays dice with the universe" (that might not be the 'exact' quote) ended up holding him back from the rest of the science he basically created. Uncertainty was a foundation shaker of its day; and Einstein couldn't bring himself to accept it. It must have been like that for the mathematicians of Cantor's day too. Rick - |
