Increasing Angle Drawing Lines

I am not very good at mathematics or geometry, but I want to draw some segments of the line at increasing angles. What I want to draw is something like when you hold your hand and spread your fingers apart: lines that start from a common point and expand at angles that have an equal difference between them.

I tried this:

len = 300; angle = 10; for (i = 0; i <= 5; ++i) { endPointX = 50 + len * Math.cos(angle); endPointY = 50 + len * Math.tan(angle); draw.Line(50, 50, endPointX, endPointY); angle += 10; } 

However, this is completely wrong and creates something like this.

http://i.stack.imgur.com/taX40.png

But I want something like this (bad mspaint, sorry):

http://i.stack.imgur.com/8xfpp.png

What is the right math for this?

+4
source share
4 answers

There are two separate problems in your question, I will talk about each of them.


Here's an ASCII image of your situation:

  B
                    +
                   / |
                  / |
                 / |
                / |
          len / |  y
              / |
             / |
            / |
           / __ |
          / θ |  |
         + ---------- +
       A x C

This is a regular triangle. It has three sides:

  • The diagonal side in the image opposite 90 ° is called the hypotenuse and has the length len . Hypotenuse is what you are trying to do.
  • The vertical side is the side opposite the angle θ and having a length y .
  • The horizontal side is the side adjacent to the angle θ and having a length x .

Given the above illustration, the following equations are true:

 cos(θ) = x/len sin(θ) = y/len 

These equations are another way of saying:

  • The cosine of the angle is equal to the length of the adjacent side divided by the length of the hypotenuse.
  • The sine of the angle is equal to the length of the opposite side divided by the length of the hypotenuse.

When solving the equation for x and y you get:

 x = len * cos(θ) y = len * sin(θ) 

So you want sin() and cos() , not cos() and tan() . If point A not at the origin, you will need to offset x and y by adding, for example:

 x = len * cos(θ) + 50 y = len * sin(θ) + 50 

With the x and y values, you can find the coordinates for point B in the triangle, and thus you can draw your own lines.


Also, if you program in Java, the trigonometric functions of the Math class expect an angle in radians , not degrees. Many programming languages ​​that provide trigonometric functions are as follows.

Radians and degrees measure the same thing, but the full rotation in degrees goes from 0 to 360° , and the full rotation in radians goes from 0 to .

To convert angles in degrees to radians, multiply the angle by π/180 . In Java, the π constant is provided by Math.PI

For example, an angle of 10 ° degrees is equivalent to 10 * π/180 or π/18 radians.

+9
source

First, you want cos and sin , not cos and tan .

Secondly, most math libraries perform trigonometric functions in radians, not degrees. So 10 really a really big difference! To convert from degrees to radians, multiply by (pi/180) .

0
source

The reason you get uneven angles of view is because every time you add 10, you actually rotate the line around the circle 1.6 times.

Mathematical functions expect angles to be in radians, not degrees.

360 degrees = 2 * Math.PI radians.

Instead of 10, write "2 * Math.PI / 36.0"

Also, use sin instead of tan.

0
source

You should not use a tan, but a sin. If I remember correctly, it should be something like this: Math.cos (angle / 180); -Math.sin (angle / 180); The denial of sin is important.

0
source

Source: https://habr.com/ru/post/1346832/


All Articles