Tag Archives | snippet

## PHP function to parse BMP header

Read first: BMP file structure analysis by PHP Example 1: 5-5-5 16-bit Result: Example 2: 5-6-5 16-bit Result: Example 3: 4-4-4 16-bit Result:

## PHP: How to check if a Polygon is self-intersect?

How to check if a Polygon is self-intersect? Example 1: Result: bool(false) Example 2: Result: bool(true)

## PHP function: mb_ucfirst

Currently on PHP does not have a multibyte (UTF-8) version of ucfirst function. I wrote some multibyte mb_ucfirst function: You must call these functions before: Method 1: Method 2: Method 3: Method 4: Method 5: New update 12/02/2015 Example: Result: How to make a string’s first character Uppercase-Multibyte?

## PHP: How to determine the center of a Polygon

How to determine the center of a Polygon. Read first: PHP: How to calculate signed area of a Polygon Method 1: Result: array(2) { [0]=> float(1.55555555556) [1]=> int(3) } Example 2: Result: array(2) { [0]=> int(0) [1]=> int(0) }

## PHP: How to check if polygon is concave or convex?

How to check if polygon is concave or convex? Note: It is assumed that the polygon is simple (does not intersect itself or have holes) Example: Result: int(-1) The algorithm is built on base of the cross product of 2 vectors: We know that the cross product of 2 vectors: In the special case, 2 […]

## PHP: How to check if the vertices of polygon are in clockwise or counter-clockwise order?

How to check if the vertices of polygon are in clockwise or counter-clockwise order? There are many of method to check this. We offer some method below: Method 1: Use ComputeArea function: Method 2: Note: It is assumed that the polygon is simple (does not intersect itself or have holes) Example: Result: int(-1)

## PHP: How to calculate signed area of a Polygon

Calculating the signed area for an polygon can be found when you know the coordinates of the vertices. We offer 3 methods below: Method 1: Method 2: Method 3: Method 4: Note: If you list the points in a clockwise order instead of counterclockwise, you will get the negative of the area. Hence this can […]

## PHP: detect Point in Polygon

PHP function to detect Point in Polygon: Test for convex polygon: Result: IN OUT Test for concave polygon: Result: OUT IN OUT Note: we only apply this method for simple polygon (non-self-intersecting polygon). Test for complex polygon (self-intersecting polygon) Result: OUT OUT OUT Error for point 2.

## PHP: Calculate Distance Between Two Coordinates

This routine calculates the distance between two points (given the latitude/longitude of those points). It is being used to calculate the distance between two locations: Example: Result: 423232.85930123 Note: Result as meters Ellipsoidal parameters: Name Major axis, a (km) Flattening (f) WGS84 6378.13700 1/298.257223563 GRS80/NAD83 6378.13700 1/298.257222101 WGS66 6378.145 1/298.25 GRS67/IAU68 6378.16000 1/298.2472 WGS72 6378.135 […]

## PHP: calculate percentage of CPU load

Read first: Function sys_getloadavg in PHP < 5.1.3 This function can calculate percentage of CPU load, work done with LINUX and WINDOWS OS. Usage: Online demo In LINUX OS, we use file /proc/stat to calculate. This file keeps track of a variety of different statistics about the system since it was last restarted. The contents […]