# Constant length line

**URL:** <https://discourse.processing.org/t/constant-length-line/37637>\
**Category:** Coding Questions\
**Created:** [June 19, 2022, 9:31am UTC](https://discourse.processing.org/t/constant-length-line/37637 "2022-06-19T09:31:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chaotic.rabbit](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chaotic.rabbit/32/14034_2.png) [@chaotic.rabbit](https://discourse.processing.org/u/chaotic.rabbit)\
**Post date:** [June 19, 2022, 9:31am UTC](https://discourse.processing.org/t/constant-length-line/37637/1 "2022-06-19T09:31:16Z")

</div>

Hi! I’m still new at processing. I’m trying to write a program that generates random line positions but all lines are of the same length. I want to further develop it to generate different coloured lines according to the line length but situated at random positions. I have no idea how to control the line length and position it at random locations. Thanksss!

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [June 19, 2022, 10:27am UTC](https://discourse.processing.org/t/constant-length-line/37637/2 "2022-06-19T10:27:56Z")

</div>

Consider the line between the points `(x, y)` and `(x+L*cos(a), y+L*sin(a))` for some values of `L` and `a`. What is the length of this line?

If `x` and `y` are random, one endpoint of this line is random. How might you randomize where the other endpoint is?

Hints: What is `L`? What is `a`?

---

<div class="post-metadata">

**Author:** ![chaotic.rabbit](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chaotic.rabbit/32/14034_2.png) [@chaotic.rabbit](https://discourse.processing.org/u/chaotic.rabbit)\
**Post date:** [June 19, 2022, 11:36am UTC](https://discourse.processing.org/t/constant-length-line/37637/3 "2022-06-19T11:36:05Z")

</div>

Thanks so much for this!!!

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 19, 2022, 1:54pm UTC](https://discourse.processing.org/t/constant-length-line/37637/4 "2022-06-19T13:54:10Z")

</div>

> [@TfGuy44](#):
>
> `(x+L*cos(a), y+L*sin(a))`

For those interested in trigonometry there is a tutorial here:  
[https://processing.org/tutorials/trig](https://processing.org/tutorials/trig)

It is not on main website but it is still available.

It is poorly formatted in places so keep an eye out for that!

For example:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/d/1/d126ad7b2131df6dbca7bafb11f3091a9c4e55fc.png)

Should be:

**x = cosine(theta) \* radius**  
**y = sine(theta) \* radius**

Have fun!

`:)`
