* apply the current transform to the given 2d or 3d vector or point * @param v - the vector object to be transformed * @returns result vector object.
(v: Vector3d | Vector2d | Point)
| 500 | * @returns result vector object. |
| 501 | */ |
| 502 | apply(v: Vector3d | Vector2d | Point) { |
| 503 | const a = this.val; |
| 504 | const x = v.x; |
| 505 | const y = v.y; |
| 506 | const z = "z" in v ? v.z : 1; |
| 507 | |
| 508 | const w = a[3] * x + a[7] * y + a[11] * z + a[15] || 1.0; |
| 509 | |
| 510 | v.x = (a[0] * x + a[4] * y + a[8] * z + a[12]) / w; |
| 511 | v.y = (a[1] * x + a[5] * y + a[9] * z + a[13]) / w; |
| 512 | |
| 513 | if ("z" in v) { |
| 514 | v.z = (a[2] * x + a[6] * y + a[10] * z + a[14]) / w; |
| 515 | } |
| 516 | |
| 517 | return v; |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * apply the inverted current transform to the given 2d or 3d vector |
no outgoing calls