Jump to content

Geometry and VB.NET ...

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
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.

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
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.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
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.

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
How familiar are you with trigonometry?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
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
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
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.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts

Quote

Then, write out the various formulas and jiggle them around until you get something that can be used to input the two values
I've been trying like this for about 1 year ... and I found nothing!

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.
I don't think that a VB program could "sketch" a triangle with the right angle (without the right formula) and ... then try to find how far the point is from the original point. So what I need is a formula or some function in vb that could do that ... is that possible?

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
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:
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? :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
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!

#10
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
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
sakishrist

sakishrist

    Programmer

  • Members
  • PipPipPipPip
  • 109 posts
OK, that's it! Thank you, and the two of you!

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts

gaylo565 said:

By the way nice math skills for your age xav

Thanks! :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums