# How to draw a intersection point on two cures?

• 03-07-2010, 11:47 PM
liangchu
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.
• 03-08-2010, 10:43 AM
Hack
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
• 03-08-2010, 04:53 PM
mstraf
Quote:

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