Hello all!
I have to make an application that when I give it the length and the angle of a line it must draw the line from the center of the form and with the specified angle. I could not find any way to get a point (x and y values) out from the length and the angle. Please, any ideas?
Thanks.
Geometry and VB.NET ...
Started by sakishrist, May 04 2008 08:44 AM
13 replies to this topic
#1
Posted 04 May 2008 - 08:44 AM
|
|
|
#2
Posted 04 May 2008 - 10:03 AM
You need to use some maths. Sketch out a triangle - then, use trigonometry or something to write a formula that accepts the angle and length, giving out the first point. Then, use another formula to calculate the second point from that.
#3
Posted 04 May 2008 - 10:49 AM
It's not that easy, believe me! If you try to find what that function must do you will see that it has to convert the angle to sin, cos or tan ... from that point everything is easy but I cant figure out how should I convert it to one of the above.
#5
Posted 04 May 2008 - 11:29 AM
Familiar enough to have a mark 18 out of 20 in geometry in my class ( note that I'm 16 years old). So if you have any solution I'll try to understand it and make my program working!
#6
Posted 04 May 2008 - 11:35 AM
Well, I'm also familiar with trigonometry (note that I'm 12 years old), and I think it would be easiest for you to sketch out a diagram of a right-angled triangle, with the angle and length marked as two letters. Then, write out the various formulas and jiggle them around until you get something that can be used to input the two values, then output one of the co-ordinates.
Here's an idea - try sketching a triangle with the right angle in the bottom right corner - then, use trigonometry to work out the length of the vertical side on the right is. This will tell you how far up the point is from the original point. Then do the same with the bottom side, and hopefully that will tell you how much along and up your co-ordinate is.
Here's an idea - try sketching a triangle with the right angle in the bottom right corner - then, use trigonometry to work out the length of the vertical side on the right is. This will tell you how far up the point is from the original point. Then do the same with the bottom side, and hopefully that will tell you how much along and up your co-ordinate is.
#7
Posted 04 May 2008 - 11:47 AM
Quote
Then, write out the various formulas and jiggle them around until you get something that can be used to input the two values
Quote
Here's an idea - try sketching a triangle with the right angle in the bottom right corner - then, use trigonometry to work out the length of the vertical side on the right is. This will tell you how far up the point is from the original point. Then do the same with the bottom side, and hopefully that will tell you how much along and up your co-ordinate is.
#8
Posted 04 May 2008 - 12:00 PM
No, I meant sketch it out on paper. You can easily draw the points later using System.Graphics. Make a rough plan (on paper) of a right-angled triangle, putting the right angle (as in 90 degrees) in the bottom right hand corner.
Next, note down the formula for the sin, cos and tan bits. In this case you use sin:
The opposite side is the one we want to find out - i.e. how much further up it is from the other point:
Therefore, use System.Math to work out the sin(angle) bit, multiply it by the length of the line, and you've got the value of how much further up you want the second point to be from the first.
In the same way:
Work out cos(angle), * by length, and you've got how far across you want the next point to be from the first point. Simply minus the two distances from the co-ordinates of the first one, and you've got the second one.
Gottit? :)
Next, note down the formula for the sin, cos and tan bits. In this case you use sin:
sin(angle) = opposite / hypotenuse
The opposite side is the one we want to find out - i.e. how much further up it is from the other point:
sin(angle) = opposite / length
sin(angle) * length = opposite
Therefore, use System.Math to work out the sin(angle) bit, multiply it by the length of the line, and you've got the value of how much further up you want the second point to be from the first.
In the same way:
cos(angle) * length = adjacent
Work out cos(angle), * by length, and you've got how far across you want the next point to be from the first point. Simply minus the two distances from the co-ordinates of the first one, and you've got the second one.
Gottit? :)
#9
Posted 04 May 2008 - 08:40 PM
OK, you are right, that was my mistake as I thought sin(n) cos(n) and tan(n) give you the angle and n every time is the sin cos or tan ... anyway, that leads me to this question: how can I do the opposite, give the two points and get the angle and the length?
Thank you for your help!
Thank you for your help!
#10
Posted 04 May 2008 - 10:36 PM
What u need for that one is Atan(); Inside the method you want y/x and that gives your angle (assuming your starting from (0,0), if not you want (y2-y1)/(x2-x1)). Distance from the starting point is (y2-y1)/sin(angle) or you could use square root if you want. By the way nice math skills for your age xav. this does only work with double so its not very accurate...Maybe someone else has a way to fix that.
Edited by gaylo565, 04 May 2008 - 11:57 PM.
#11
Posted 05 May 2008 - 03:27 AM
OK, that's it! Thank you, and the two of you!


Sign In
Create Account


Back to top









