| View previous topic :: View next topic |
| Author |
Message |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Wed Jan 06, 2010 4:17 pm Post subject: Draw Angle VB.net |
|
|
I'm making a force & motion program but I don't know how to draw angles?
_________________
CEF will always stay alive. |
|
| Back to top |
|
 |
Caelestis Expert Cheater
Reputation: 0
Joined: 03 May 2007 Posts: 153
|
Posted: Thu Jan 07, 2010 12:46 am Post subject: |
|
|
| What, are you confused about the math? Or you don't know which methods to call?
|
|
| Back to top |
|
 |
iPromise Grandmaster Cheater
Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Thu Jan 07, 2010 12:48 am Post subject: |
|
|
| Graphics() component
|
|
| Back to top |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Thu Jan 07, 2010 3:22 pm Post subject: |
|
|
| Caelestis wrote: | | What, are you confused about the math? Or you don't know which methods to call? |
The math part.
_________________
CEF will always stay alive. |
|
| Back to top |
|
 |
Caelestis Expert Cheater
Reputation: 0
Joined: 03 May 2007 Posts: 153
|
Posted: Thu Jan 07, 2010 3:51 pm Post subject: |
|
|
| Tell me what method you are using and what it does and I can help.
|
|
| Back to top |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Thu Jan 07, 2010 5:45 pm Post subject: |
|
|
| Caelestis wrote: | | Tell me what method you are using and what it does and I can help. |
Graphics.DrawLine Method
_________________
CEF will always stay alive. |
|
| Back to top |
|
 |
Caelestis Expert Cheater
Reputation: 0
Joined: 03 May 2007 Posts: 153
|
Posted: Thu Jan 07, 2010 7:26 pm Post subject: |
|
|
Heres a discussion for the topic:
http://www.daniweb.com/forums/thread24617.html
Sorry I could not help directly, I hate VB
With math, do you have a vector that you need to draw with a magnitude and angle, or a vector with x and y components and you need to draw the line between them?
To do the first one, the length of x to pass to drawline would be cos(angle)*length_of_line and the y would be sin(angle)*length_of_line. The second one you just make points and pass them to drawline.
|
|
| Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Fri Jan 08, 2010 6:37 am Post subject: |
|
|
In C# you could do it like this: | Code: | public static Point GetVectorByLengthAndAngle(double length, double angle)
{
length = Math.Abs(length);
return new Point(length * Math.Cos(angle), length * Math.Sin(angle));
}
public Static void DrawAngle(Point pos,int length,double angle, Graphics g)
{
g.DrawLine(new Pen(Brushes.RoyalBlue,5.0f),pos,new Point(pos.X +length,pos.Y));
Point vector = GetVectorByLengthAndAngle(length,angle);
g.DrawLine(new Pen(Brushes.RoyalBlue,5.0f),pos,new Point(pos.X+vector.X,pos.Y+vector.Y));
}
|
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
| Back to top |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Fri Jan 08, 2010 7:17 am Post subject: |
|
|
| Odecey wrote: | In C# you could do it like this: | Code: | public static Point GetVectorByLengthAndAngle(double length, double angle)
{
length = Math.Abs(length);
return new Point(length * Math.Cos(angle), length * Math.Sin(angle));
}
public Static void DrawAngle(Point pos,int length,double angle, Graphics g)
{
g.DrawLine(new Pen(Brushes.RoyalBlue,5.0f),pos,new Point(pos.X +length,pos.Y));
Point vector = GetVectorByLengthAndAngle(length,angle);
g.DrawLine(new Pen(Brushes.RoyalBlue,5.0f),pos,new Point(pos.X+vector.X,pos.Y+vector.Y));
}
|
|
This did the trick! Thanks @ other guy for help though.
_________________
CEF will always stay alive. |
|
| Back to top |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Fri Jan 08, 2010 5:03 pm Post subject: |
|
|
I got it to work manually converting the code from C# to VB.net
| Code: | Public Function GetVectorByLengthAndAngle(ByVal length As Double, ByVal angle As Double)
length = Math.Abs(length)
Return New Point(length * Math.Cos(angle), length * Math.Sin(angle))
End Function
Public Sub DrawAngle(ByVal pos As Point, ByVal length As Integer, ByVal angle As Double, ByVal g As Graphics)
g.DrawLine(New Pen(Brushes.RoyalBlue, 5.0F), pos, New Point(pos.X + length, pos.Y))
Dim Vector As Point = GetVectorByLengthAndAngle(length, angle)
g.DrawLine(New Pen(Brushes.RoyalBlue, 5.0F), pos, New Point(pos.X + Vector.X, pos.Y + Vector.Y))
End Sub
|
But... It draws the angle upside down, the 180 line is on the top. How can I make it on the bottom? (Despite I'm not in triginometry/calc yet..)
_________________
CEF will always stay alive. |
|
| Back to top |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Sat Jan 09, 2010 1:03 pm Post subject: |
|
|
Nvm got it to work by changing the length in GetVectorByLengthAndAngle for the Y point to a negative...
Doubles:
1.57 = 90 Angle
6.28 = 360 Angle
Equation 6.28 * (Angle/360)
_________________
CEF will always stay alive. |
|
| Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Sat Jan 09, 2010 6:47 pm Post subject: |
|
|
| ©ï & wrote: | Nvm got it to work by changing the length in GetVectorByLengthAndAngle for the Y point to a negative...
Doubles:
1.57 = 90 Angle
6.28 = 360 Angle
Equation 6.28 * (Angle/360) |
That's an approximation. If you want it more accurate, you should use this: Angle in degrees = (Angle in radians * 180)/Pi.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
| Back to top |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Sat Jan 09, 2010 6:56 pm Post subject: |
|
|
| Odecey wrote: | | Šī & wrote: | Nvm got it to work by changing the length in GetVectorByLengthAndAngle for the Y point to a negative...
Doubles:
1.57 = 90 Angle
6.28 = 360 Angle
Equation 6.28 * (Angle/360) |
That's an approximation. If you want it more accurate, you should use this: Angle in degrees = (Angle in radians * 180)/Pi. |
| Code: | (DegreeToRadian(Me.TextBox1.Text) * 180) / Math.PI
Public Function DegreeToRadian(ByVal degree As Double) As Double
Return (Math.PI / 180) * degree
End Function |
This wont work? When The input in radians is 90 the line ends up around 157.5??
When I use Radian 0 it works fine though?
Edit:
Nvm I didn't need the * 180 / Math.PI
Thanks Hitler.
_________________
CEF will always stay alive. |
|
| Back to top |
|
 |
|