Drawing functions ? [Solved - Thank you ]

Shentaku

New member
Joined
Jun 14, 2005
Messages
2
Programming Experience
1-3
Can someone please help me, I have exams tomorrow on VB.net and I am having some trouble. We have to make a proggy that allows you to chose a shape(square, triangle, hexagon, pentagram ... ) . After making them you can move them or fill them. Also you should be able to calculate the combined surface of every shape in the same color.

So far I can only draw circles, sqaures , rectangles and triangles. Im using the graphics.AddRectangle and .fillRectangle. But someone suggested using region or something ? And how can I calculate the surface ? Is there a function for that too ?

Any help would be massivly appreciated.
 
Last edited:
To calculate area of certain forms you don't need a graphics but you need System.Math Class for the purpose ... for instance to calculate area of circle you need Pow and the Math.PI field to calculate the area of a circle like so:

PHP:
circleArea = Math.PI * Math.Pow(circleRadius, 2)

for square:
PHP:
squareArea = Math.Pow(squareSide, 2)

and so on ... :cool:


Cheers ;)
 
the 2 being the numbers after the comma I suppose? But say I place two squares, and one is partialy covering the other, then calculating both surfaces and adding them together would be too much...

So how would I have to go at that then ?

Thank you for your help so far Kulrom
 
You would need to calculate the area of each, add them together and then subtract the overlapping portion. You would use the coordinates of the vertices of the two squares to determine the coordinates of the vertices of the overlapping section. Then it's just another shape whose area you can determine. You would have to apply the same mathematics as you would if you were doing it on paper.
 
Hi, i just noted the status of jmcilhinney "VB.NET Forum Moderator" ... yaba daba doo ~ welcome Jim!!! I've told you about this before !!! Now you'll have to open my attachments :p

However, very well done by Neal and my sincerely congratulations to Jim. Keep going with your usual nice and quality replies.

Cheers ;)
 
If you need to find the 'combined surface of every shape in the same color', just go over all the pixels. Add one for every pixel of the give colour, that you find.

You can find the vertices of of regular pentagon / hexagon / n gon by

If n -> no of sides, epoch -> initial angle of first vertext, boundingRadius -> Radius of the bounding circle

stepAngle = math.pi * 2 / n

x = boundingRadius * Math.cos(epoch + stepAngle * i)
y = boundingRadius * Math.cos(epoch + stepAngle * i)

A pentagram is contained within pentagon. If the vertices of a pentagon are A, B, C, D, E draw line from A->C, B->D
, C-> E, D->A, E->B. In short, for join every vertex to the next-to-next vertex

:)

Cheers

Rohit
 
If you are simply talking about squares and rectangles you can use a Region and an intersecting GraphicsPath and call the Exclude method. You can then calculate the area based on the RectangleF array returned from the GetRegionScans method. It would be nice to return a resultant PointF array from the Region after the Exclude method but I have yet to find a way of doing so. Region seem to have a lot of power but have this shortcoming of returning a point array. I would think the RegionData method would do something of the sort but its retrun format is unpublished... I think. Please someone correct me if I am wrong or can answer the question of how to return a point array from a Region.


jglobe
 
Back
Top