Board index » Visual Studio » Shapes Area

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


-
 

Re:Shapes Area



"Rochdi" <anonymous@discussions.microsoft.com>wrote in message

Quote
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..!!?



Ellipses are defined by the equation:



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







-

Re:Shapes Area

Quote
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..!!?



I'm assuming you are using a Shape control set whose Shape property is set

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





-

Re:Shapes Area

roll on the argument about whether there are a finite

number of points in the ellipse.....







Quote
-----Original Message-----

>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..!!?



I'm assuming you are using a Shape control set whose

Shape property is set

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





.



-

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



Quote
roll on the argument about whether there are a finite

number of points in the ellipse.....







>-----Original Message-----

>>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..!!?

>

>I'm assuming you are using a Shape control set whose

Shape property is set

>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

>

>

>.

>





-

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-----

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



>roll on the argument about whether there are a finite

>number of points in the ellipse.....

>

>

>

>>-----Original Message-----

>>>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..!!?

>>

>>I'm assuming you are using a Shape control set whose

>Shape property is set

>>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

>>

>>

>>.

>>





.



-

Re:Shapes Area

Quote
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.



Oh! I remember that thread. I don't remember Larry saying there were a

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





-

Re:Shapes Area

"Ben Taylor" <anonymous@discussions.microsoft.com>wrote

Quote
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.



You can't blame your errors on me, I am not blind, and I did

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













-

Re:Shapes Area

"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in message

Quote


Oh! I remember that thread. I don't remember Larry saying there were a

finite number of points on a mathematical line per se...





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







-

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

>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.



You can't blame your errors on me, I am not blind, and I did

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

















-

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

>

>Oh! I remember that thread. I don't remember Larry saying there were a

>finite number of points on a mathematical line per se...





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











-

Re:Shapes Area



"Ben Taylor" <nosp@mpleasewerebritish>wrote in message

Quote
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.



From the thread Rick posted a link to:



Quote
No, I said IMPOSSIBLE!



Nope Larry, it's not impossible, just impossible

for the mind to imagine



It's funny how your recollection has Rick being (academically)

hostile, when it appears he wasn't.









-

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-----

>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..!!?



I'm assuming you are using a Shape control set whose

Shape property is set

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





.



-

Re:Shapes Area



"Larry Serflaten" <serflaten@usinternet.com>wrote in message

Quote
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in message

>

>Oh! I remember that thread. I don't remember Larry saying there were a

>finite number of points on a mathematical line per se...





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



I'm not sure what you mean by "for every point you add to..."; it's the word

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.





Quote
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!



I'm not wholly clear on what you are saying here... which is probably

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





-

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











-

Re:Shapes Area

Quote
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!



Infinity, infinities of infinity, and so on is really a hard concept to get

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





-