How to draw a intersection point on two cures?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

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

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

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    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
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    Quote Originally Posted by Hack View Post
    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

  1. Replies: 4
    Last Post: 04-22-2009, 06:38 PM
  2. vb.net point of intersection
    By noobsaibot in forum .NET
    Replies: 5
    Last Post: 09-16-2007, 10:01 PM
  3. JAVA RMI : A Shared Whiteboard
    By eclipt in forum Java
    Replies: 1
    Last Post: 01-09-2007, 05:33 PM
  4. already defined error
    By rssmps in forum C++
    Replies: 6
    Last Post: 05-31-2006, 06:07 PM
  5. Replies: 1
    Last Post: 09-01-2002, 09: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center