Geometry Functions

Home • Gallery • Tutorials • Download • Purchase • Site Map
 

Geometry Functions Support

The Fractal Science Kit fractal generator Geometry functions provide an assortment of functions, geometric in nature, used by several of the built-in instructions.

Complex Geometry.ProjectPointOnLine(z, p0, p1)
Complex Geometry.DistanceToLine(z, p0, p1)
Complex Geometry.RotatePointAboutPoint(z, origin, angle)
Complex Geometry.ReflectPointAboutLine(z, p0, p1)
Complex Geometry.ReflectPoint(z, angle)
Complex Geometry.ScalePointAboutPoint(z, origin, factor)

Geometry.ProjectPointOnLine projects z on the line formed by p0 and p1 and returns the resulting point. Geometry.DistanceToLine returns the distance from z to the line formed by the points p0 and p1. Geometry.RotatePointAboutPoint rotates z by angle radians about origin and returns the resulting point. Geometry.ReflectPointAboutLine returns the reflection of z in the line formed by the points p0 and p1. Geometry.ReflectPoint returns the reflection of z in the line through the origin, inclined angle radians relative to the X axis. Geometry.ScalePointAboutPoint scales z by factor about origin and returns the resulting point.

Complex Geometry.Quadrant(z)

Geometry.Quadrant returns the quadrant (as an integer from 1 to 4) into which z falls.

void Geometry.BarycentricCoordinates(z, p1, p2, p3, byref r1, byref r2, byref r3)
Complex Geometry.IsInsideTriangle(z, p1, p2, p3)

Geometry.IsInsideTriangle returns True if z is inside triangle given by points (p1, p2, p3). Geometry.BarycentricCoordinates returns the barycentric coordinates of z with respect to the triangle given by points (p1, p2, p3). The barycentric coordinates are returned in the real numbers (r1, r2, r3).

The following is true:

z = r1*p1 + r2*p2 + r3*p3

For additional details see:

Eric W. Weisstein. "Barycentric Coordinates."

From MathWorld--A Wolfram Web Resource.

Complex Geometry.RadialInversion(radius, z)
Complex Geometry.Inversion(center, radius, z)

Geometry.RadialInversion reflects z in a circle centered at the origin with the given radius. Geometry.Inversion reflects z in the circle with the given center and radius.

Complex Geometry.MidPoint(p0, p1)
Complex Geometry.IntersectLines(p0, p1, q0, q1)

Geometry.MidPoint returns the midpoint of the line segment defined by p0 and p1. Geometry.IntersectLines returns the point of intersection of the 2 lines formed by p0, p1 and q0, q1.

Complex Geometry.AngleDifference(ang0, ang1)
Complex Geometry.AverageAngle(a0, a1)
Complex Geometry.AverageAngle3(a0, a1, a2)
Complex Geometry.AverageAngle4(a0, a1, a2, a3)

Geometry.AngleDifference returns the difference between the angles ang0 and ang1 given in radians. The resulting angle is greater than or equal to 0 and less than or equal to Math.PI. Geometry.AverageAngle, Geometry.AverageAngle3, and Geometry.AverageAngle4 return the average of the argument angles given in radians. These are not simply arithmetic averages due to the cyclic nature of angle measures. For example, the average of 355 degrees and 5 degrees is 0 degrees not 180 degrees.

Complex Geometry.AreaOfPolygon(points[], count)
Complex Geometry.ArePolygonVerticesClockwise(points[], count)
Complex Geometry.IsInsidePolygon(points[], count, z)
void Geometry.InsetPolygon(points[], result[], count, r)

Geometry.AreaOfPolygon returns the area of the polygon given by the array points[]. The array points[] contains count vertices of a non-intersecting polygon. Geometry.ArePolygonVerticesClockwise takes points[] as the count vertices of a non-self-intersecting polygon and returns True if the vertices are given in clockwise order, False otherwise. If the polygon is self-intersecting, the result is undefined. Geometry.IsInsidePolygon returns True if z is inside the polygon given by the array points[]. The array points[] contains count vertices of a polygon. Geometry.InsetPolygon takes points[] as the count vertices of a polygon and returns a new polygon inside the given polygon where the edges of the new polygon are at a distance of r from the given polygon. If r is negative, the new polygon will be outside the original polygon. If the polygon is self-intersecting, the meaning of inside/outside the polygon simply refers to being to the left or right of the polygon edge.

Complex Geometry.MaximumDistanceToPolygonEdge(v[], N)

Geometry.MaximumDistanceToPolygonEdge returns the maximum distance, over all points inside a polygon defined by the N vertices in v[], between each point and the edge closest to that point. It does this by generating random points inside the polygon, finding the distance from that point to the closest edge, and keeping track of the largest such distance found. If we generate enough random points, this method will return a reasonable estimate for the value we seek. If I find a more elegant way to do this in the future, I will update this function.

The polygon can be convex, concave, or self-intersecting and it does not matter if the vertices are given in clockwise or counter-clockwise order.

Geometry.MaximumDistanceToPolygonEdge is slow and should not be called in time critical sections of your code. In addition, due to the nature of the algorithm, the value returned should be considered an estimate and subsequent calls may return slightly different results.

void Geometry.GeneratePointsOnCircle(points[], count, center, radius, angle0)
void Geometry.GenerateAngles(angles[], count, angle0)
void Geometry.GeneratePointsOnSegment(points[], count, p, q)
Complex Geometry.PointOnSegment(p, q, r)

Geometry.GeneratePointsOnCircle fills the points[] array with count equally spaced points on the circle with the given center and radius. The 1st point is located on the circle angle0 radians counterclockwise from horizontal. Geometry.GenerateAngles fills the angles[] array with count equally spaced angles between angle0 and angle0+2*Math.PI. Geometry.GeneratePointsOnSegment fills the points[] array with count equally spaced points on the line segment between points p and q. Geometry.PointOnSegment returns the point on the line segment between points p and q given by r; i.e., p+(q-p)*r.

void Geometry.GeneratePointsOnEpicycloid(points[], count, cusps, revolutions, delta, radius, shift)
void Geometry.GeneratePointsOnHypocycloid(points[], count, cusps, revolutions, delta, radius, shift)

Geometry.GeneratePointsOnEpicycloid fills the points[] array with count points along the curve based on the given arguments. Geometry.GeneratePointsOnHypocycloid fills the points[] array with count points along the curve based on the given arguments. cusps and revolutions should be integer values and relative primes. The epicycloid will have cusps cusps/loops in revolutions revolutions around the inner circle. The hypocycloid will have cusps cusps/loops in revolutions revolutions inside the outer circle. delta defines the size of the loop at each cusp and should be greater than or equal to 0. radius constrains the curve to be inside a circle of the given radius. shift defines the placement of the first point of the curve and should be a value between 0 and 1.

void Geometry.GeneratePointsOnOscillator(points[], count, amplitude, frequency, phaseDiff, shift)

Geometry.GeneratePointsOnOscillator fills the points[] array with count points along the curve based on the given arguments. amplitude and frequency are complex values that define the amplitude and frequency of the curve in both X and Y. phaseDiff should be a real number. The curve is constrained by the rectangle defined by the amplitude of the curve. shift defines the placement of the first point of the curve and should be a value between 0 and 1.

void Geometry.GeneratePointsOnRose(points[], count, numerator, denominator, radius, shift)

Geometry.GeneratePointsOnRose fills the points[] array with count points along the curve based on the given arguments. numerator and denominator are integer values that define the numerator and denominator of the rational value that defines the curve. radius constrains the curve to be inside a circle of the given radius. shift defines the placement of the first point of the curve and should be a value between 0 and 1.

void Geometry.PolygonSpin(points[], result[], count, rate)

Geometry.PolygonSpin fills the result[] array with count points generated from the polygon defined by the count points in points[]. result[i] is set to the point P on the segment from points[i] to points[i+1] where P is rate of the way along the segment. You may pass the same array for points[] and result[] and this method will update the array in place. Both points[] and result[] are assumed to be large enough to hold count values. count should be 3 or more.

void Geometry.TruncatePolygon(points[], result[], count, factor)

Geometry.TruncatePolygon takes points[] as the count vertices of a polygon. factor is applied to each edge length to determine the distance of the 2 truncated points from the endpoints they replace. The array result[] is assumed to be large enough to hold 2*count values. factor should be between 0 and 0.5 exclusive but values outside this range produce interesting results too. count should be 3 or more.

void Geometry.StellatePolygon(points[], result[], count, factor)

Geometry.StellatePolygon takes points[] as the count vertices of a polygon. factor is applied to each edge length to determine the distance of the stellate point from the edge. The result[] array must be dimensioned 2*count to hold the resulting points. Technically, this is not the correct way to stellate a polygon but it produces nice results and is easy to do. count should be 3 or more.

Complex Geometry.HexCellCenter(size, z)

Geometry.HexCellCenter returns the center of the hexagon cell where z falls. size is the height of each hexagon cell. The reference hexagon is size tall by size*Sqrt(3)/2 wide and is centered at the origin with vertices on the left and right, and edges on the top and bottom.

Complex Geometry.MagnitudeFactor(z)

Geometry.MagnitudeFactor(z) returns a scale factor that can be used to scale orbit trap values based on the magnitude of z. This results in lines becoming wider as they move away from the origin.

 

Copyright © 2004-2019 Ross Hilbert
All rights reserved