I am writing a recursive program to draw the lines recursively, given the
range[min,max] and number of intervals (n) between the range.
The problem is I don't know how to draw the line in point 0.375, as you see below.
Please advise! Thanks!
#include <iostream>
using namespace std;
void draw(double min, double max, int n);
int main()
{ draw(0,1,8);
}
void draw(double min, double max, int n)
{ if (n != 1)
{ double mid = (max - min)/2;
cout << mid << endl;
draw(min, mid, n/2);
}
}
The program output:
0.5
0.25
0.125
Here's the expected output:
0.5
0.25
0.125
0.375
0.75
0.625
0.875 5 6358 jr********@hotmail.com (Matt) writes: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
C has no facilities for drawing lines.
The problem is I don't know how to draw the line in point 0.375, as you see below. Please advise! Thanks!
#include <iostream>
That's not C.
The program output: 0.5 0.25 0.125
That's not a line. Those are numbers.
--
"What is appropriate for the master is not appropriate for the novice.
You must understand the Tao before transcending structure."
--The Tao of Programming
Matt <jr********@hotmail.com> wrote: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
The problem is I don't know how to draw the line in point 0.375, as you see below. Please advise! Thanks!
#include <iostream> using namespace std;
Sorry, but this a C newsgroup, there's also a C++ group in case you have
problems with C++. So let's replace this with
#include <stdio.h>
void draw(double min, double max, int n);
int main() { draw(0,1,8); }
You forgot to have main() return an int...
void draw(double min, double max, int n) { if (n != 1) { double mid = (max - min)/2;
You need to add the starting point of the interval here:
double mid = ( max - min ) / 2 + min;
(the mid-point between e.g. 4 and 5 is 4.5 and not just 0.5).
cout << mid << endl;
Sorry, this won't work in C, use instead
printf( "%f\n", mid );
draw(min, mid, n/2);
Now you're "drawing" the lower half of the interval but you forget to
also "draw" the upper half. You need an additional call:
draw( mid, max, n / 2 );
} }
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Matt wrote: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
The problem is I don't know how to draw the line in point 0.375, as you see below. Please advise! Thanks!
#include <iostream> using namespace std;
Try comp.lang.c++
--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
On 5 Oct 2003 10:44:13 -0700, jr********@hotmail.com (Matt) wrote: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
snip
Answered in alt.math. Please don't post the same message under
different subjects to multiple groups. If you must post to more than
one group, put all the group names on one message.
<<Remove the del for email>>
Matt wrote: I am writing a recursive program to draw the lines recursively, given the range[min,max] and number of intervals (n) between the range.
Search under Bresenham's Algorithm. Can also be used to draw ellipses ;-)
--
Julian V. Noble
Professor Emeritus of Physics jv*@lessspamformother.virginia.edu
^^^^^^^^^^^^^^^^^^ http://galileo.phys.virginia.edu/~jvn/
"Science knows only one commandment: contribute to science."
-- Bertolt Brecht, "Galileo". This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Matt |
last post by:
I am writing a recursive program to draw the lines recursively, given the
range and number of intervals (n) between the range.
The problem is I don't know how to draw the line in point 0.375, as...
|
by: thomasp |
last post by:
I found the following code on MSDN to draw a line in VB2005.
Public Sub DrawLinePoint(ByVal e As PaintEventArgs)
' Create pen.
Dim blackPen As New Pen(Color.Black, 3)
' Create points that...
|
by: dan heskett |
last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some
custom "fields" and text layout.
Essentially it works, but I must be missing something big, conceptually,
because I...
|
by: news |
last post by:
If anyone can recommend a more appropriate newsgroup for this question?
We recently upgraded from php 4.1.2 to php 4.3.9 and ImageMagick 5.5.7
to version 6.2.5.
I have a script that creates a...
|
by: Jason Huang |
last post by:
Hi,
In my C# Windows Form, how do I draw a Line?
Thanks for help.
Jason
|
by: Rich |
last post by:
Hello,
I have a form with a panel which contains a radiobutton. When I click the
radiobutton, I invoke the Paint event of the panel using me.Invalidate. The
paint event gets called and runs...
|
by: balakrishnan.dinesh |
last post by:
Hi frnds,
Im creating function to plot line graph in javascript .
I have marked the points in graph. but what i need to do is, i want to
draw the line between those marked point, but i dont...
|
by: IvoShalev |
last post by:
Hi there,
I just want to give some sudgestions on how to draw some plain things
only using the header file <graphics.hand of course the standart
files <stdio.h<conio.h<stdlib.h>.
First of All...
|
by: zhaow |
last post by:
Hi, All
Greetings!
I want to develop as appllication that requires a line-drawing function
in the blank area between two forms. I have looked up the MSDN, it says that
a graphics object need a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |