How to draw a intersection point on two cures?

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: How to draw a intersection point on two cures?

#### Hybrid View

1. Registered User
Join Date
Sep 2004
Posts
96

## 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 10:39 AM. Reason: Added Code Tags

2. 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

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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise