473,479 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

area of PI

1 New Member
Hey everyone, kinda struggling with a part of my hw assignment. would anyone know how I could get started.?? here is the question:

Graphical Determination of Pi: The full value of pi, which no one really knows for sure, can be approximated by considering the area bounded by a quarter circle. For a quarter circle of radius r = 2 meters, the formula for the area of a full circle (4 x pi square meters) implies that the area of a quarter of a circle that is radius of 2 m should be equal to pi square meters (4*pi/4 = pi). That area can be approximated by summing the areas of vertical rectangles of fixed width w and variable height h. Write a C++ program that estimates the value of pi this way. Use this algorithm, which splits the quarter circle into a large number of rectangles of variable heights, such that the midpoint of each rectangle’s roof lies on the arc of the quarter circle. starting at the left side (x=0) and moving to the right, one rectangle at time (until x==r), the height of each rectangle lessens according to h = (r2 –x2)1/2, while the area of each rectangle is just (w x h).
Nov 22 '06 #1
2 2428
Banfa
9,065 Recognized Expert Moderator Expert
You will need a loop pseudo code something like

Expand|Select|Wrap|Line Numbers
  1. Total = 0
  2.  
  3. FOR EACH RECTANGLE IN AREA
  4.     Total = Totasl + AREA of CURRENT RECTANGLE
  5. ENDFOR
  6.  
  7. Print "PI = ", Total
  8.  
Nov 22 '06 #2
horace1
1,510 Recognized Expert Top Contributor
an algorithm is to increment thru x and y and if sqrt(x*x + y*y) < r the square counts towards the area, e.g. in pseudo-code
Expand|Select|Wrap|Line Numbers
  1.  assume radius is r
  2.  x = y  = area = 0    
  3.  while x <= r
  4.        while y <= r
  5.        if ( sqrt(x*x + y*y) < r )  increment area
  6.        y = y + 1
  7.  x = x + 1
  8.  pi = 4 * area / (r * r )
  9.  
Nov 23 '06 #3

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

Similar topics

2
8234
by: Charles Eubanks | last post by:
The enclosed html snippet displays an area map. The behavior I want is for each area to show up (eg show the outline of the poly) when the user mouses over it. This happens nicely BUT in order...
2
2022
by: Gabe Moothart | last post by:
I would like to be able to dynamically change the attributes of an <area> element in an image map. The following works in IE 6 and Opera 7: <map name="Map1"> <area shape="rect"...
1
2672
by: Ms Yaqian Fang | last post by:
Hello, I want to highlight the clicked area on an image by placing another image on it. But it replaced the whole image, not the clicked area. My code is as following, can anyone please help me?...
14
5560
by: laurence | last post by:
I am implementing a comprehensive image-map generator utility, so have been studying W3C HTML 4.01 Specification (http://www.w3.org/TR/html4/struct/objects.html#h-13.6) on image maps (among other...
1
1933
by: Michael SL | last post by:
I have an area setup <map name="linkmap"><area shape=RECT coords="0,0,135,15" href='<%=LinkDestination1 %>' ><area shape=RECT coords=150,0,285,15 href="<%=LinkDestination2 %>" ><area shape=RECT...
13
3106
by: Lars Netzel | last post by:
Hi! I have a round area which I want to be able to move the mouse over and fire off events... how do I do that? I have drawn a FillPie Graphics and I feel that there has to be a way of...
1
8197
by: JWest46088 | last post by:
I keep getting these error messages: area(double,double) in Rectangle cannot be applied to () return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter(); ...
2
1625
by: UKuser | last post by:
Hi Folks, I havent used javascript in ages, and am not the worlds guru, but I'm playing with ajax linking to my database and an updating area. I have an area named display for example which...
1
1887
by: adamprisa | last post by:
1. Go to http://webwag.com 2. On the left hand side upper corner there is an "Add new Content" button, Click on it. 3. Enter a URL(suppose www.yahoo.com) in New! Widget On DemandTM TextBox and...
1
4042
by: tiffrobe | last post by:
I'm a little lost on my program. Everything works fine except function 3. It gives out garbage numbers. Its suppose to give the distance between two points and then the area of 2 circles. ...
0
7033
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
6903
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
7027
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
7071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6726
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
4468
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
557
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.