Solved

# working with curve

Posted on 2005-05-04
246 Views
hello experts
how I paint a curve with having their dots and how I know two curve are intersecting
please write me the code of this
thank you
0

LVL 17

Accepted Solution

When you plot or calculate the points for each curve add the points into an array.

In a byte array set bit 1 if curve 1 passed that way and bit 2 if curve 2.

Example:

Option Explicit

Const Max As Single = 50

Me.AutoRedraw = True
Me.Show
DoEvents

Dim bytGrid(Max, Max) As Byte
Dim y As Long
Dim x As Long

' Now calculate the points for curve 1
For x = 0 To 2000 ' you set the start/end point for x
If y >= 0 And y < Max Then ' make sure within extents to be checked
If Not (bytGrid(x, y) And 1) = 1 Then
bytGrid(x, y) = 1
End If
Plot x, y, RGB(0, 0, 255)
End If
Next

' Now calculate the points for curve 2
For x = 0 To 2000 ' you set the start/end point for x
y = 0.1 * x ^ 2   ' add your formula here
If y >= 0 And y < Max Then ' make sure within extents to be checked
If Not (bytGrid(x, y) And 2) = 2 Then
bytGrid(x, y) = (bytGrid(x, y) And 1) + 2
End If
Plot x, y, RGB(255, 0, 0)
End If
Next

' now find ponts were intercepted
For x = 0 To Max ' you set the start/end point for x
For y = 0 To Max
If bytGrid(x, y) = 3 Then
Debug.Print "Intercepted: X=" & x & " Y=" & y
End If
Next
Next

End Sub

Sub Plot(x As Long, y As Long, col As Long)

' translate a plot point onto the printable scale for the form

Dim py As Single
Dim px As Single
Dim Offset As Single

Dim XMax As Single
Dim XMargin As Single

XMax = Me.ScaleWidth * 0.9      ' max width to use
XMargin = Me.ScaleWidth * 0.05  ' a small margin

Dim YMax As Single
Dim YMargin As Single

YMax = Me.ScaleHeight * 0.9     ' max height to use
YMargin = Me.ScaleHeight * 0.05 ' margin

px = XMargin + (XMax * (CSng(x) / Max))
py = Me.ScaleHeight - YMargin - (YMax * (CSng(y) / Max))

Static bDone As Boolean
Static lx As Single
Static ly As Single

' set initial start points
If Not bDone Then
bDone = True
ly = Me.ScaleHeight - YMargin
lx = XMargin
End If

Me.Line (lx, ly)-(px, py), col
lx = px
ly = py

End Sub

0

Author Comment

me.autoredraw is not define    in vb !!!!
0

## Featured Post

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

#### Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!