# Trig question re line/circle intersections

**URL:** https://discourse.processing.org/t/trig-question-re-line-circle-intersections/29671
**Category:** Coding Questions
**Created:** [April 27, 2021, 3:42am UTC](https://discourse.processing.org/t/trig-question-re-line-circle-intersections/29671 "2021-04-27T03:42:11Z")
**Posts on this page:** 1
**Showing post:** 3

<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: [April 27, 2021, 1:56pm UTC](https://discourse.processing.org/t/trig-question-re-line-circle-intersections/29671/3 "2021-04-27T13:56:16Z")

</div>

@psemme,

A couple of ways… I a sure there are many more.

Consider:

> **[Intersection (geometry) | A line and a circle](https://en.wikipedia.org/wiki/Intersection_(Euclidean_geometry)#A_line_and_a_circle)**
>
> For the intersection of
> 1.line 
>   
>     
>       
> a
> x
> +
> b
> y
> =
> c
>       
>     
> {\\displaystyle ax+by=c}
>   
> and circle 
>   
>     
>       
>         
> x
>           
> 2
>           
>         
> +
>         
> y
>           
> 2
>           
>         
> =
>         
> r
>           
> 2
>           
>         
>       
>     
> {\\displaystyle x^{2}+y^{2}=r^{2}}
>   
> one solves the line equation for x or y ...

You could draw a circle and then a line and use get(x, y) to detect where it intersects.  
I have used this technique to detect intersections of objects with a curve and following a curve.

Emulate a rotary encoder:

> [@Best way to emulate a rotary encoder wheel?](https://discourse.processing.org/t/best-way-to-emulate-a-rotary-encoder-wheel/21982/6):
>
> Hello, Thanks for asking this! Had some fun with it… Sharing my initial steps… I did not look at other examples. Create a PGraphic image. I used random circles but this could be your encoded wheel or anything. Move the mouse over the canvas to detect colors. Do something with the detected colors. The rest is up to your creativity and imagination. I used the same concepts in the past to do something similar. In my example the mouse location turned red or green depending on color it detected…

`:)`

---

_[View the full topic](https://discourse.processing.org/t/trig-question-re-line-circle-intersections/29671)._
