We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to check if a Polygon object intersects with another object, we use the intersectsWithObject method. This method checks whether the object that is passed to it, intersects with the polygon object. Syntax intersectsWithObject(other: Object, absolute: Boolean, calculate: Boolean ): Boolean Parameters ... Read More
In this article, we will learn how to write a swift program to calculate standard deviation. Standard deviation is a measure, which will represent how much variation from the mean exists, or we can say that it is used to calculate the extent to which the values are differ from the average. $$\mathrm{\sigma\:=\:\sqrt{{\frac{1}{N}}\sum_{i=1}^N\:(X_i-\mu)^2}}$$ The mathematical formula of standard deviation is- σ = standard deviation N = total number of elements Xi = ith element \mu = Mean of the given elements Therefore, in this article, we calculate the standard deviation of the given array by using the ... Read More
In this article, we will learn how to write a swift program to check whether two matrices are equal or not. Here, we create two matrices, and using the not equal to the operator (!=), we check whether all the elements of both matrices are equal or not. Algorithm Step 1 − Create a function. Step 2 − Use nested for loop to iterate through each row and column. Step 3 − Check if the element of matrix1 is not equal to matrix2. If the condition is true, then return 0, otherwise, return 1. Step 4 − Create two ... Read More
In this article, we will learn how to write a swift program to compute the sum of diagonals of a matrix. Every matrix has two diagonals which are known as primary and secondary diagonals. For example, we have the following 5x5 square matrix − 2 3 4 5 6 4 6 7 8 9 1 1 1 3 4 4 0 4 0 4 0 0 1 1 1 So the primary diagonal is formed by using elements 2, 6, 1, 0, 1 and the secondary diagonal is formed by using elements 6, 8, 1, 0, 0. Hence the ... Read More
In this article, we will learn how to write a swift program to display upper triangular matrix. Upper triangular matrix is a matrix in which all the elements below the primary diagonal are zero. As shown in the below image − $$\mathrm{\begin{bmatrix} 1 & 4 & 6 & 7 & 8 & 8ewline 0 & 5 & 6 & 8 & 9 & 9ewline 0 & 0 & 6 & 7 & 8 & 3ewline 0 & 0 & 0 & 2 & 1 & 1ewline 0 & 0 & 0 & 0 & 2 & 1ewline 0 & 0 ... Read More
In this article, we will learn how to write a swift program to find the sum of the boundary elements of a matrix. Boundary elements of a matrix are those elements that are present on the boundary of the matrix that are elements in the first row, last row, first column, and last column. For example − Given Matrix: 2 4 5 6 7 8 4 5 6 7 3 2 3 4 5 6 2 1 1 1 1 1 1 1 3 4 3 4 3 4 2 2 2 2 2 2 Boundary elements are: ... Read More
In this article, we will learn how to write a swift program to find trace and normal of a given matrix. Calculating the Trace of a given Matrix Trace is known as the sum of primary diagonal elements of the given square matrix. For example, we have a 3x3 square matrix − 2 3 4 3 4 6 1 3 2 So the primary diagonal elements are 2, 4 and 2. Hence the trace of the given 3x3 matrix is 2+4+2 = 8. Algorithm Step 1 − Define the size of the matrix. Step 2 − Create a ... Read More
In this article, we will learn how to write a swift program to interchange the elements of first and last in a matrix across rows. Therefore, to interchange the elements we need to swap the elements of the first row with the elements of the last row of the given matrix. For example − Original matrix: 2 4 5 6 3 4 6 2 6 7 7 2 1 1 1 1 So after swapping the first and last rows we get: 1 1 1 1 3 4 6 2 6 7 7 2 2 4 5 6 ... Read More
In this article, we will learn how to write a swift program to interchange the diagonals. Therefore, to interchange the diagonals we need to swap the elements of primary diagonal with the elements of secondary diagonal of the given matrix. For example − Original matrix: 2 4 5 6 3 4 6 2 6 7 7 2 1 1 1 1 So after swapping diagonals we get: 6 4 5 2 3 6 4 2 6 7 7 2 1 1 1 1 Algorithm Step 1 − Create a function. Step 2 − Run a for loop ... Read More
In this article, we will learn how to write a swift program to print boundary elements of a matrix. Boundary elements of a matrix are those elements that are present on the boundary of the matrix that are elements in the first row, last row, first column, and last column. For example − Given Matrix: 2 4 5 6 7 8 4 5 6 7 3 2 3 4 5 6 2 1 1 1 1 1 1 1 3 4 3 4 3 4 2 2 2 2 2 2 Boundary elements are: 2 4 5 6 ... Read More