It looks like you're new here. If you want to get involved, click one of these buttons!

Hello,

I am trying to do something with exact angle performance between two edges, so far I handle it with the code as below

Although I know the `with_angle`

function in `EdgePairs`

class, but I still prefer exact angle value, not sure there is some mystic function ?

Somehow the calculation noise will take place ( out of domian - acos ) , but it's not problem, and can be solved by simple rounding

```
include RBA
v1 = RBA::Vector.new(-17,-17)
v2 = RBA::Vector.new(-17,-17)
dot = (v1.x * v2.x + v1.y * v2.y)/(v1.abs*v2.abs)
dot1 = dot.round(5) # remove calculate noise
p dot
p dot1
arc1 = Math::acos(dot1)
arc = Math::acos(dot)
```

Thanks and Good Day

Vincent

## Comments

Hi Vincent,

Floating-point arithmetics is never exactly accurate and errors accumulate. In side KLayout I am doing something like this:

The 1e-10 value is somewhat arbitrary - it should be large enough not to be noise sensitive, but small enough to be "precise".

There is a rough estimate for the minimum angle between two edges which are not parallel: as the database is made from 32bit integer coordinates, the smallest possible angle is 1 DBU / 2^32 DBU which is about 2.5e-10 (rad). In degree units that is 1.5e-8 degree. The noise is about 1e-16 relative. For an angle value of 0..360 degree, this translates into 3.6e-14 max noise. So 1e-10 is somewhere in between and a good choice for differentiating noise from real angle differences.

To compute the angle between two vectors, I'd propose this code:

This computes the angle between v1 and v2, the angles counted in counter-clockwise direction.

Matthias

Hello Matthias,

Thanks for detail explanation, it's helpful to learn more about K-layout

Good Day

Vincent