---
title: "getPointClosestTo"
canonical: "https://help.vicon.com/space/ShogunPost121/1253736712/getPointClosestTo"
format: markdown
---
# Description

Identifies the point on a vector closest to a line

`l1` and `l2` specify a line segment which goes through both points. This line segment is extended to be a line of infinite length. getPointClosestTo will orthogonally project `p` onto this line to return the point which is closest to `p` and `l1-l2`.

Note that the point returned can be outside of the line segment `l1-l2`.

## Functional area

Math

# Command syntax

## Syntax

> Macro (scroll-tablelayout)

|  |
| --- |
| `getPointClosestTo vector1 vector2 vector3` |

### Arguments

> Macro (scroll-tablelayout)

| Name | Type | Required | Comments |
| --- | --- | --- | --- |
| `vector1` | vector | yes | The first endpoint of the vector which is constructed from vector1 and vector2 |
| `vector2` | vector | yes | The second endpoint of the vector which is constructed from vector1 and vector2 |
| `vector3` | vector | yes | The point in space for which the user wants to find the closest point on the line from vector1 and vector2 |

### Flags

None 

## Return value

vector

Returns a variable of type vector which is the point on the line  from vector1 and vector2 that is closest to vector3.   


> Macro (scroll-pagebreak)

## Examples

```plaintext
vector $l1 = <<1, 0, 0>>;
vector $l2 = <<0, 1, 0>>;
vector $o = <<0, 0, 0>>; 
// l1 and l2 form a line of slope -1 in the X-Y plane
// that goes through both points l1 and l2. o is the origin. 
// The point on the line closest to the origin is <<0.5, 0.5, 0>>
print(getPointClosestTo($l1, $l2, $o));
 
// This example shows that you can get a point outside of the line
// segment delineated by l1-l2 (the closest point to the line segment
// would be l2, but the closest point to the line of infinite length
// is <<-0.5, 1.5, 0>>)
vector $p = <<-1, 1, 0>>;
print(getPointClosestTo($l1, $l2, $p));
```

# Additional information

## Related commands

- [getAngleTo](https://vicon-help.atlassian.net/wiki/spaces/ShogunPost121/pages/1253737805)