-
How to draw a intersection point on two cures?
hi,I want to draw the point of intersection on two cures.For example,the point of inersection on Line y=x and parabola y=x*x (-2<=x<=2).But it is failure for the following program segment:
Code:
For x=-2 to 2 step 0.01
Picture1.ForeColor=vbBlack
If x=x*x then
Picture1.Forecolor=vbRed
Picture1.Pset(x,x)
Else
Picture1.Pset(x,x*x)
Endif
Next x
What's wrong with it? Hope to explain it.Thank you a lot.
Last edited by Hack; 03-08-2010 at 11:39 AM.
Reason: Added Code Tags
xuliangchu
-
For one thing, x never gets incremented or decremented so it always has a value of -2
If you put a break on your code and step through it you will see that is ALWAYS hits the Else part, and x continues to equal -2
-
 Originally Posted by Hack
For one thing, x never gets incremented or decremented so it always has a value of -2
Not if x is defined as Double (or Float), in that case the loop works ok
This is a classic rounding problem: the step is not a multiple of 2, therefore the test (x = x*x) will never be true (because incrementing by 0.01 x will never be zero)
This is one of the many ways (and not the best, but I did not want to change the code) to fix the problem:
Code:
Picture1.Scale (-2, 10)-(2, -10)
Dim x As Double
Dim dstep As Double
dstep = 2 ^ -6
For x = -2 To 2 Step dstep
If x = x * x Then
Picture1.ForeColor = vbRed
Else
Picture1.ForeColor = vbBlack
End If
Picture1.PSet (x, x * x)
Next x
"There are two ways to write error-free programs. Only the third one works."
Unknown
Similar Threads
-
By chupacabra in forum VB Classic
Replies: 4
Last Post: 04-22-2009, 05:38 PM
-
By noobsaibot in forum .NET
Replies: 5
Last Post: 09-16-2007, 09:01 PM
-
Replies: 1
Last Post: 01-09-2007, 05:33 PM
-
Replies: 6
Last Post: 05-31-2006, 05:07 PM
-
By Ad van Klink in forum .NET
Replies: 1
Last Post: 09-01-2002, 08:52 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|