[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 285

# working with curve

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
1 Solution

Commented:
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 Commented:
me.autoredraw is not define    in vb !!!!
0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.