Created
March 16, 2021 09:57
-
-
Save Dahausa/2d65a3b5910c54ced8ce81e7e64925bc to your computer and use it in GitHub Desktop.
Gist from API Documentation Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Point } from 'yfiles'; | |
// Create a new point | |
const p1 = new Point(-5, 2) | |
// Create another point somewhere else | |
const p2 = new Point(23, 42) | |
console.log(`Point 1 is at (${p1.X},${p1.Y}), point 2 is at (${p2.X},${p2.y})`) | |
// Subtract one point from the other to get a vector between them | |
// which is also represented as a Point | |
const v = p2.subtract(p1) | |
// Point offers a few handy properties when interpreting it as a vector | |
console.log(`VectorLength: ${v.vectorLength}`) | |
// VectorLength in this case is equivalent to p1.distanceTo(p2): | |
console.log(`Distance: ${p1.distanceTo(p2)}`) | |
console.log(`IsHorizontalVector: ${v.isHorizontalVector}`) | |
console.log(`IsVerticalVector: ${v.isVerticalVector}`) | |
console.log(`Normalized: ${v.normalized}`) | |
const halfLength = v.multiply(0.2).vectorLength | |
const doubleLength = v.multiply(2).vectorLength | |
console.log(`Original vector: ${v.vectorLength}`) | |
console.log(`Half-length vector: ${halfLength}`) | |
console.log(`Double-length vector: ${doubleLength}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment