1.14 <GrapheneTriangle>

Structure: <GrapheneTriangle>

A triangle.

Procedures

Procedure: triangle:alloc ⇒ %return

Allocates a new <GrapheneTriangle>.

The contents of the returned structure are undefined.

%return

Returned: a <GrapheneTriangle>.

the newly allocated <GrapheneTriangle> structure. Use triangle:free to free the resources allocated by this function

Method: triangle:contains-point? self p ⇒ %return
Method: contains-point? self p ⇒ %return

Checks whether the given triangle self contains the point p.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

p

Passed: a <GraphenePoint3D>.

a <GraphenePoint3D>

%return

Returned: a boolean.

true if the point is inside the triangle

Method: triangle:equal? self b ⇒ %return
Method: equal? self b ⇒ %return

Checks whether the two given <GrapheneTriangle> are equal.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

b

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

%return

Returned: a boolean.

true if the triangles are equal

Method: triangle:free self
Method: free self

Frees the resources allocated by triangle:alloc.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

Method: triangle:get-area self ⇒ %return
Method: get-area self ⇒ %return

Computes the area of the given <GrapheneTriangle>.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

%return

Returned: a real number.

the area of the triangle

Method: triangle:get-barycoords! self p res ⇒ %return res
Method: get-barycoords! self p res ⇒ %return res

Computes the barycentric coordinates of the given point p.

The point p must lie on the same plane as the triangle self; if the point is not coplanar, the result of this function is undefined.

If we place the origin in the coordinates of the triangle’s A point, the barycentric coordinates are u, which is on the AC vector; and v which is on the AB vector:

![](triangle-barycentric.png)

The returned <GrapheneVec2> contains the following values, in order:

  • res.x = u
  • res.y = v
self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

p

Passed: a <GraphenePoint3D>, or #f.

a <GraphenePoint3D>

res

Passed, filled in, and returned: a <GrapheneVec2>.

return location for the vector with the barycentric coordinates

%return

Returned: a boolean.

true if the barycentric coordinates are valid

Method: triangle:get-bounding-box! self res ⇒ res
Method: get-bounding-box! self res ⇒ res

Computes the bounding box of the given <GrapheneTriangle>.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

res

Passed, filled in, and returned: a <GrapheneBox>.

return location for the box

Method: triangle:get-midpoint! self res ⇒ res
Method: get-midpoint! self res ⇒ res

Computes the coordinates of the midpoint of the given <GrapheneTriangle>.

The midpoint G is the centroid of the triangle, i.e. the intersection of its medians.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

res

Passed, filled in, and returned: a <GraphenePoint3D>.

return location for the coordinates of the midpoint

Method: triangle:get-normal! self res ⇒ res
Method: get-normal! self res ⇒ res

Computes the normal vector of the given <GrapheneTriangle>.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

res

Passed, filled in, and returned: a <GrapheneVec3>.

return location for the normal vector

Method: triangle:get-plane! self res ⇒ res
Method: get-plane! self res ⇒ res

Computes the plane based on the vertices of the given <GrapheneTriangle>.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

res

Passed, filled in, and returned: a <GraphenePlane>.

return location for the plane

Method: triangle:get-points! self a b c ⇒ a b c
Method: get-points! self a b c ⇒ a b c

Retrieves the three vertices of the given <GrapheneTriangle> and returns their coordinates as <GraphenePoint3D>.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

a

Passed, filled in, and returned: a <GraphenePoint3D>.

return location for the coordinates of the first vertex

b

Passed, filled in, and returned: a <GraphenePoint3D>.

return location for the coordinates of the second vertex

c

Passed, filled in, and returned: a <GraphenePoint3D>.

return location for the coordinates of the third vertex

Method: triangle:get-uv! self p uv-a uv-b uv-c res ⇒ %return res
Method: get-uv! self p uv-a uv-b uv-c res ⇒ %return res

Computes the UV coordinates of the given point p.

The point p must lie on the same plane as the triangle self; if the point is not coplanar, the result of this function is undefined. If p is #f, the point will be set in (0, 0, 0).

The UV coordinates will be placed in the res vector:

  • res.x = u
  • res.y = v

See also: triangle:get-barycoords!

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

p

Passed: a <GraphenePoint3D>, or #f.

a <GraphenePoint3D>

uv-a

Passed: a <GrapheneVec2>.

the UV coordinates of the first point

uv-b

Passed: a <GrapheneVec2>.

the UV coordinates of the second point

uv-c

Passed: a <GrapheneVec2>.

the UV coordinates of the third point

res

Passed, filled in, and returned: a <GrapheneVec2>.

a vector containing the UV coordinates of the given point p

%return

Returned: a boolean.

true if the coordinates are valid

Method: triangle:get-vertices! self a b c ⇒ a b c
Method: get-vertices! self a b c ⇒ a b c

Retrieves the three vertices of the given <GrapheneTriangle>.

self

Passed: a <GrapheneTriangle>.

a <GrapheneTriangle>

a

Passed, filled in, and returned: a <GrapheneVec3>.

return location for the first vertex

b

Passed, filled in, and returned: a <GrapheneVec3>.

return location for the second vertex

c

Passed, filled in, and returned: a <GrapheneVec3>.

return location for the third vertex

Method: triangle:init-from-float self a b c ⇒ %return
Method: init-from-float self a b c ⇒ %return

Initializes a <GrapheneTriangle> using the three given arrays of floating point values, each representing the coordinates of a point in 3D space.

self

Passed: a <GrapheneTriangle>.

the <GrapheneTriangle> to initialize

a

Passed: a f32vector, or a list or vector, each a real number.

an array of 3 floating point values

b

Passed: a f32vector, or a list or vector, each a real number.

an array of 3 floating point values

c

Passed: a f32vector, or a list or vector, each a real number.

an array of 3 floating point values

%return

Returned: a <GrapheneTriangle>.

the initialized <GrapheneTriangle>

Method: triangle:init-from-point3d self [a] [b] [c] ⇒ %return
Method: init-from-point3d self [a] [b] [c] ⇒ %return

Initializes a <GrapheneTriangle> using the three given 3D points.

self

Passed: a <GrapheneTriangle>.

the <GrapheneTriangle> to initialize

a

Passed, or left out: a <GraphenePoint3D>, or #f.

a <GraphenePoint3D>

b

Passed, or left out: a <GraphenePoint3D>, or #f.

a <GraphenePoint3D>

c

Passed, or left out: a <GraphenePoint3D>, or #f.

a <GraphenePoint3D>

%return

Returned: a <GrapheneTriangle>.

the initialized <GrapheneTriangle>

Method: triangle:init-from-vec3 self [a] [b] [c] ⇒ %return
Method: init-from-vec3 self [a] [b] [c] ⇒ %return

Initializes a <GrapheneTriangle> using the three given vectors.

self

Passed: a <GrapheneTriangle>.

the <GrapheneTriangle> to initialize

a

Passed, or left out: a <GrapheneVec3>, or #f.

a <GrapheneVec3>

b

Passed, or left out: a <GrapheneVec3>, or #f.

a <GrapheneVec3>

c

Passed, or left out: a <GrapheneVec3>, or #f.

a <GrapheneVec3>

%return

Returned: a <GrapheneTriangle>.

the initialized <GrapheneTriangle>