Point to point on a graph (with a picture)
Author |
Message |
hockeymi #1 / 6
|
 Point to point on a graph (with a picture)
Alright....since the subject sounds a little wierd, I'm gonna break the question down.... I have this form (form1) I also want to have this graph(could someone suggest a good control for this?) I also have this picture (picture1) What I want to do is place the picture on top of the graph, so that people could select certain points on the picture (without knowing there is a graph underneath), and then I need my program to use the distance formula: _____________________ D=\/((X1-X2)^2+(Y1-Y2)^2) to find out how far the two points are on the graph (but it looks like the user has clicked on the picture) I also want to know how I can superimpose a small, green square where the user has clicked, and connect the lines in the order they were clicked I know it is a big task, But that is why I have left it in the hands of people far more capable than myself.....YOU GUYS!!
|
Thu, 30 Jun 2005 21:58:32 GMT |
|
 |
D.. #2 / 6
|
 Point to point on a graph (with a picture)
Not sure of the graph part but here is an example of little green squares and lines Start a New project and add a picturebox and a shapecontrol... Set the shapecontrol Index to 0 (zero) Paste this into the code page. (Might be line wrap) Option Explicit Private Type POINTAPI X As Long Y As Long End Type Private Sub Form_Load() With Picture1 .ScaleMode = vbPixels End With End Sub Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Static PreviousCoords As POINTAPI, bFirstPoint As Boolean 'Do something here is starting/stopping the line drawing Load Shape1(Shape1.Count + 1) With Shape1(Shape1.Count) .BorderColor = vbGreen .FillColor = vbGreen .Height = 3 .Width = 3 .Top = Y - 1 .Left = X - 1 .Visible = True End With If Not bFirstPoint Then bFirstPoint = True Else Picture1.Line (PreviousCoords.X, PreviousCoords.Y)- _ (X, Y), vbGreen End If PreviousCoords.X = X PreviousCoords.Y = Y End Sub
Quote: >Alright....since the subject sounds a little wierd, I'm gonna break >the question down.... >I have this form (form1) >I also want to have this graph(could someone suggest a good control >for this?) >I also have this picture (picture1) >What I want to do is place the picture on top of the graph, so that >people could select certain points on the picture (without knowing >there is a graph underneath), and then I need my program to use the >distance formula: > _____________________ >D=\/((X1-X2)^2+(Y1-Y2)^2) >to find out how far the two points are on the graph (but it looks like >the user has clicked on the picture) >I also want to know how I can superimpose a small, green square where >the user has clicked, and connect the lines in the order they were >clicked >I know it is a big task, But that is why I have left it in the hands >of people far more capable than myself.....YOU GUYS!!
Have a good day... Don
|
Thu, 30 Jun 2005 22:54:57 GMT |
|
 |
Mauree #3 / 6
|
 Point to point on a graph (with a picture)
I can understand your need to read the points clicked by the user and calculate the distance between the two points (which Don has already answered for you, although I haven't actually tried his code), but what is the point of the underlying graph? What do you want that for? Mike Quote:
> Alright....since the subject sounds a little wierd, I'm gonna break > the question down.... > I have this form (form1) > I also want to have this graph(could someone suggest a good control > for this?) > I also have this picture (picture1) > What I want to do is place the picture on top of the graph, so that > people could select certain points on the picture (without knowing > there is a graph underneath), and then I need my program to use the > distance formula: > _____________________ > D=\/((X1-X2)^2+(Y1-Y2)^2) > to find out how far the two points are on the graph (but it looks like > the user has clicked on the picture) > I also want to know how I can superimpose a small, green square where > the user has clicked, and connect the lines in the order they were > clicked > I know it is a big task, But that is why I have left it in the hands > of people far more capable than myself.....YOU GUYS!!
|
Fri, 01 Jul 2005 02:03:18 GMT |
|
 |
hockeymi #4 / 6
|
 Point to point on a graph (with a picture)
Yes....I wanted the graph so that I could easily place the points at the coordinates clicked, however I have discovered is irrelevent! Thanks for the help....I will try that now Quote:
> I can understand your need to read the points clicked by the user and > calculate the distance between the two points (which Don has already > answered for you, although I haven't actually tried his code), but what > is the point of the underlying graph? What do you want that for? > Mike
> > Alright....since the subject sounds a little wierd, I'm gonna break > > the question down.... > > I have this form (form1) > > I also want to have this graph(could someone suggest a good control > > for this?) > > I also have this picture (picture1) > > What I want to do is place the picture on top of the graph, so that > > people could select certain points on the picture (without knowing > > there is a graph underneath), and then I need my program to use the > > distance formula: > > D=\/((X1-X2)^2+(Y1-Y2)^2) > > to find out how far the two points are on the graph (but it looks like > > the user has clicked on the picture) > > I also want to know how I can superimpose a small, green square where > > the user has clicked, and connect the lines in the order they were > > clicked > > I know it is a big task, But that is why I have left it in the hands > > of people far more capable than myself.....YOU GUYS!!
|
Fri, 01 Jul 2005 07:16:05 GMT |
|
 |
Jacob Speddin #5 / 6
|
 Point to point on a graph (with a picture)
I was lacking anything to do so as I got some good advise from this newsgroup a few days ago, I thought I would repay someone with something useful (hopefully). At the end of this you'll find some code, copy it into a forms code portion and it should work fine. Its very sloppy and a complete bodge but it should give you some inspiration or at least help you assertain what you want. The left button creates new points, the right button moves points (when you drag the green square) and the escape button clears all points. Enjoy:- Option Explicit Private Type Point x As Long y As Long End Type Const MAXPOINTS = 32 Private Data(MAXPOINTS) As Point Private NumPoints As Long Private Pix As Long Private Current As Long Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = 27 Then NumPoints = 0 Refresh End If End Sub Private Sub Form_Load() Current = -1 Pix = 4 * ScaleX(1, vbPixels, ScaleMode) Picture = LoadPicture("C:\WINDOWS\Setup.bmp") ForeColor = RGB(191, 0, 0) FontTransparent = False DrawWidth = 2 End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Static OldX As Long Static OldY As Long Dim i As Long Select Case Button Case 0 If Current <> -1 Then Data(Current).x = Data(Current).x + x - OldX Data(Current).y = Data(Current).y + y - OldY Current = -1 End If Case 1: Current = CreatePoint(x, y) Case 2 i = 0 Current = -1 While i < NumPoints And Current = -1 If Abs(x - Data(i).x) <= Pix And Abs(y - Data(i).y) <= Pix Then Current = i i = i + 1 Wend OldX = x: OldY = y End Select Refresh End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = 2 Then Form_MouseDown 0, Shift, x, y End Sub Private Function CreatePoint(ByVal x As Long, ByVal y As Long) If NumPoints < MAXPOINTS Then Current = NumPoints NumPoints = NumPoints + 1 Data(Current).x = x Data(Current).y = y Else Beep Current = -1 End If End Function Private Sub Form_Paint() Dim Total As Double Dim i As Long Dim dx As Long Dim dy As Long i = 0 While i + 1 < NumPoints dx = Data(i + 1).x - Data(i).x dy = Data(i + 1).y - Data(i).y Line (Data(i).x - Pix, Data(i).y - Pix)-Step(2 * Pix, 2 * Pix), RGB(0, 191, 0), BF Line (Data(i).x, Data(i).y)-Step(dx, dy), RGB(191, 0, 0) CurrentX = Data(i).x + dx \ 2 CurrentY = Data(i).y + dy \ 2 Print Format(Sqr(dx ^ 2 + dy ^ 2), "#") Total = Total + Sqr(dx ^ 2 + dy ^ 2) i = i + 1 Wend Caption = Format(Total, "#.##") & "meters" End Sub
|
Mon, 04 Jul 2005 03:15:35 GMT |
|
 |
Jacob Speddin #6 / 6
|
 Point to point on a graph (with a picture)
I was lacking anything to do so as I got some good advise from this newsgroup a few days ago, I thought I would repay someone with something useful (hopefully). At the end of this you'll find some code, copy it into a forms code portion and it should work fine. Its very sloppy and a complete bodge but it should give you some inspiration or at least help you assertain what you want. The left button creates new points, the right button moves points (when you drag the green square) and the escape button clears all points. Enjoy:- Option Explicit Private Type Point x As Long y As Long End Type Const MAXPOINTS = 32 Private Data(MAXPOINTS) As Point Private NumPoints As Long Private Pix As Long Private Current As Long Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = 27 Then NumPoints = 0 Refresh End If End Sub Private Sub Form_Load() Current = -1 Pix = 4 * ScaleX(1, vbPixels, ScaleMode) Picture = LoadPicture("C:\WINDOWS\Setup.bmp") ForeColor = RGB(191, 0, 0) FontTransparent = False DrawWidth = 2 End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Static OldX As Long Static OldY As Long Dim i As Long Select Case Button Case 0 If Current <> -1 Then Data(Current).x = Data(Current).x + x - OldX Data(Current).y = Data(Current).y + y - OldY Current = -1 End If Case 1: Current = CreatePoint(x, y) Case 2 i = 0 Current = -1 While i < NumPoints And Current = -1 If Abs(x - Data(i).x) <= Pix And Abs(y - Data(i).y) <= Pix Then Current = i i = i + 1 Wend OldX = x: OldY = y End Select Refresh End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = 2 Then Form_MouseDown 0, Shift, x, y End Sub Private Function CreatePoint(ByVal x As Long, ByVal y As Long) If NumPoints < MAXPOINTS Then Current = NumPoints NumPoints = NumPoints + 1 Data(Current).x = x Data(Current).y = y Else Beep Current = -1 End If End Function Private Sub Form_Paint() Dim Total As Double Dim i As Long Dim dx As Long Dim dy As Long i = 0 While i + 1 < NumPoints dx = Data(i + 1).x - Data(i).x dy = Data(i + 1).y - Data(i).y Line (Data(i).x - Pix, Data(i).y - Pix)-Step(2 * Pix, 2 * Pix), RGB(0, 191, 0), BF Line (Data(i).x, Data(i).y)-Step(dx, dy), RGB(191, 0, 0) CurrentX = Data(i).x + dx \ 2 CurrentY = Data(i).y + dy \ 2 Print Format(Sqr(dx ^ 2 + dy ^ 2), "#") Total = Total + Sqr(dx ^ 2 + dy ^ 2) i = i + 1 Wend Caption = Format(Total, "#.##") & "meters" End Sub
|
Mon, 04 Jul 2005 03:23:02 GMT |
|
|
|