# Get intersection point of line and CIE chromaticity curve

**URL:** <https://discourse.processing.org/t/get-intersection-point-of-line-and-cie-chromaticity-curve/6685>\
**Category:** Coding Questions\
**Created:** [December 17, 2018, 2:45am UTC](https://discourse.processing.org/t/get-intersection-point-of-line-and-cie-chromaticity-curve/6685 "2018-12-17T02:45:53Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [December 19, 2018, 6:42pm UTC](https://discourse.processing.org/t/get-intersection-point-of-line-and-cie-chromaticity-curve/6685/7 "2018-12-19T18:42:57Z")

</div>

> [@ProsExplorer](#):
>
> Given that, there should only be a single possible intersection point, as shown below.

Great! Sounds like you have a solution, then. Loop over your segments and test them against your line for intersection.

Here is Thompson’s tutorial method that I linked to earlier, modified to return the intersection point (or null if no intersection):

```auto
PVector lineLine(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
  // calculate the distance to intersection point
  float uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));
  float uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));
  // if uA and uB are between 0-1, lines are colliding
  if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {
    // computer intersection point
    float intersectionX = x1 + (uA * (x2-x1));
    float intersectionY = y1 + (uA * (y2-y1));
    return new PVector(intersectionX, intersectionY);
  }
  return null;
}

```

So given a list of curve segments `segments` and a line `line`, you could use that method something like this:

```auto
// loop over segments and mark the point if intersection is not null
for (float[] seg : segments){
  PVector intersection = lineLine(seg[0], seg[1], seg[2], seg[3], line[0], line[1], line[2], line[3]);
  if(intersection != null){
    ellipse(intersection.x, intersection.y, 20, 20);
    break; 
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/get-intersection-point-of-line-and-cie-chromaticity-curve/6685)._
