Loading...
Searching...
No Matches
gs_util.c File Reference

OGSF library - loading and manipulating surfaces. More...

`#include <stdlib.h>`
`#include <math.h>`
`#include <string.h>`
`#include <grass/gis.h>`
`#include <grass/ogsf.h>`
Include dependency graph for gs_util.c:

Go to the source code of this file.

## Functions

double | GS_geodistance (double *from, double *to, const char *units)
| Calculate distance between 2 coordinates.
float | GS_distance (float *from, float *to)
| Calculate distance.
float | GS_P2distance (float *from, float *to)
| Calculate distance in plane.
void | GS_v3eq (float *v1, float *v2)
| Copy vector values.
void | GS_v3add (float *v1, float *v2)
| Sum vectors.
void | GS_v3sub (float *v1, float *v2)
| Subtract vectors.
void | GS_v3mult (float *v1, float k)
| Multiple vectors.
int | GS_v3norm (float *v1)
| Change v1 so that it is a unit vector (3D).
int | GS_v2norm (float *v1)
| Change v1 so that it is a unit vector (2D).
int | GS_dv3norm (double *dv1)
| Changes v1 so that it is a unit vector.
int | GS_v3normalize (float *v1, float *v2)
| Change v2 so that v1v2 is a unit vector.
int | GS_v3dir (float *v1, float *v2, float *v3)
| Get a normalized direction from v1 to v2, store in v3.
void | GS_v2dir (float *v1, float *v2, float *v3)
| Get a normalized direction from v1 to v2, store in v3 (2D).
void | GS_v3cross (float *v1, float *v2, float *v3)
| Get the cross product v3 = v1 cross v2.
void | GS_v3mag (float *v1, float *mag)
| Magnitude of vector.
int | GS_coordpair_repeats (float *p1, float *p2, int nhist)
| ADD.

## Detailed Description

OGSF library - loading and manipulating surfaces.

GRASS OpenGL gsurf OGSF Library

(C) 1999-2008 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
  Bill Brown USACERL, GMSL/University of Illinois
  Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)

Definition in file gs_util.c.

## Function Documentation

## GS_coordpair_repeats()

int GS_coordpair_repeats | ( | float * | p1,
|  | float * | p2,
|  | int | nhist )

ADD.

Initialize by calling with a number nhist to represent number of previous entries to check, then call with zero as nhist

Parameters

  [in] | p1 | first point
  [in] | p2 | second point
  [in] | nhist | ?

Returns
  -1 on error
  -2
  1
  9

Definition at line 440 of file gs_util.c.

References G_free(), and NULL.

Referenced by GS_draw_flowline_at_xy().

## GS_distance()

float GS_distance | ( | float * | from,
|  | float * | to )

Calculate distance.

Parameters

  [in] | from | 'from' point (X,Y,Z)
  [in] | to | 'to' point (X,Y,Z)

Returns
  distance

Definition at line 141 of file gs_util.c.

References X, x, and Y.

Referenced by gs_distance_onsurf(), GS_get_selected_point_on_surface(), GS_look_here(), gs_los_intersect1(), gs_setlos_enterdata(), gsd_zup_twist(), gv_line_length(), and Nviz_set_cplane_here().

## GS_dv3norm()

int GS_dv3norm | ( | double * | dv1 | ) |

Changes v1 so that it is a unit vector.

Parameters

  [in,out] | dv1 | 3D vector (X,Y,Z)

Returns
  0 if magnitude of dv1 is zero
  1 if magnitude of dv1 > 0

Definition at line 295 of file gs_util.c.

References X, and Y.

Referenced by gsd_def_cplane().

## GS_geodistance()

double GS_geodistance | ( | double * | from,
|  | double * | to,
|  | const char * | units )

Calculate distance between 2 coordinates.

Units is one of:

- "meters",
- "miles",
- "kilometers",
- "feet",
- "yards",
- "nmiles" (nautical miles),
- "rods",
- "inches",
- "centimeters",
- "millimeters",
- "micron",
- "nanometers",
- "cubits",
- "hands",
- "furlongs",
- "chains"

Default is meters.

Parameters

  [in] | from | starting point (X,Y)
  [in] | to | ending point (X,Y)
  [in] | units | map units

Returns
  distance between two geographic coordinates in current projection

Definition at line 55 of file gs_util.c.

References Gs_distance().

## GS_P2distance()

float GS_P2distance | ( | float * | from,
|  | float * | to )

Calculate distance in plane.

Parameters

  [in] | from | 'from' point (X,Y)
  [in] | to | 'to' point (X,Y)

Returns
  distance

Definition at line 160 of file gs_util.c.

References X, x, and Y.

Referenced by gsd_arrow(), gsd_draw_cplane_fence(), gv_line_length(), and seg_intersect_vregion().

## GS_v2dir()

void GS_v2dir | ( | float * | v1,
|  | float * | v2,
|  | float * | v3 )

Get a normalized direction from v1 to v2, store in v3 (2D).

Parameters

  [in] | v1 | first 2D vector (X,Y)
  [in] | v2 | second 2D vector (X,Y)
  [out] | v3 | output 2D vector (X,Y)

Returns
  0 if magnitude of dx is zero
  1 if magnitude of dx > 0

Definition at line 382 of file gs_util.c.

References X, and Y.

## GS_v2norm()

int GS_v2norm | ( | float * | v1 | ) |

Change v1 so that it is a unit vector (2D).

Parameters

  [in,out] | v1 | 2D vector (X,Y)

Returns
  0 if magnitude of v1 is zero
  1 if magnitude of v1 > 0

Definition at line 271 of file gs_util.c.

References X, and Y.

Referenced by GS_draw_flowline_at_xy().

## GS_v3add()

void GS_v3add | ( | float * | v1,
|  | float * | v2 )

Sum vectors.

v1 += v2

Parameters

  [in,out] | v1 | first 3D vector (X,Y,Z)
  [in] | v2 | second 3D vector (X,Y,Z)

Definition at line 195 of file gs_util.c.

References X, and Y.

Referenced by GS_moveto(), GS_set_viewdir(), gs_setlos_enterdata(), and gsd_arrow_onsurf().

## GS_v3cross()

void GS_v3cross | ( | float * | v1,
|  | float * | v2,
|  | float * | v3 )

Get the cross product v3 = v1 cross v2.

Parameters

  [in] | v1 | first 3D vector (X,Y,Z)
  [in] | v2 | second 3D vector (X,Y,Z)
  [out] | v3 | output 3D vector (X,Y,Z)

Definition at line 403 of file gs_util.c.

References X, and Y.

Referenced by gsd_arrow_onsurf(), gsd_surf_map_old(), and Gv_load_vect().

## GS_v3dir()

int GS_v3dir | ( | float * | v1,
|  | float * | v2,
|  | float * | v3 )

Get a normalized direction from v1 to v2, store in v3.

Parameters

  [in] | v1 | first 3D vector (X,Y,Z)
  [in] | v2 | second 3D vector (X,Y,Z)
  [out] | v3 | output 3D vector (X,Y,Z)

Returns
  0 if magnitude of dx is zero
  1 if magnitude of dx > 0

Definition at line 351 of file gs_util.c.

References X, and Y.

Referenced by GS_get_modelposition(), GS_get_viewdir(), GS_look_here(), gs_los_intersect(), gs_los_intersect1(), gs_setlos_enterdata(), gsd_arrow_onsurf(), gsd_get_zup(), and Nviz_set_cplane_here().

## GS_v3eq()

void GS_v3eq | ( | float * | v1,
|  | float * | v2 )

Copy vector values.

v1 = v2

Parameters

  [out] | v1 | first 3D vector (X,Y,Z)
  [in] | v2 | second 3D vector (X,Y,Z)

Definition at line 178 of file gs_util.c.

References X, and Y.

Referenced by gpd_obj(), GS_draw_lighting_model(), GS_draw_lighting_model1(), GS_get_focus(), GS_get_from(), GS_get_from_real(), GS_get_selected_point_on_surface(), GS_get_to(), GS_init_view(), gs_los_intersect(), GS_moveto(), Gs_save_3dview(), GS_set_focus(), GS_set_focus_real(), GS_set_viewdir(), gsd_arrow_onsurf(), gsd_check_focus(), gsd_surf_map_old(), gsd_wall(), gsd_zup_twist(), gsdrape_get_allsegments(), and gsdrape_get_segments().

## GS_v3mag()

void GS_v3mag | ( | float * | v1,
|  | float * | mag )

Magnitude of vector.

Parameters

  [in] | v1 | 3D vector (X,Y,Z)
  [out] | mag | magnitude value

Definition at line 418 of file gs_util.c.

References X, and Y.

Referenced by gsd_arrow_onsurf(), and gsd_surf_map_old().

## GS_v3mult()

void GS_v3mult | ( | float * | v1,
|  | float | k )

Multiple vectors.

v1 *= k

Parameters

  [in,out] | v1 | 3D vector (X,Y,Z)
  [in] | k | multiplicator

Definition at line 229 of file gs_util.c.

References X, and Y.

Referenced by GS_look_here(), Gs_save_3dview(), gs_setlos_enterdata(), gsd_arrow_onsurf(), gsd_check_focus(), and Nviz_set_cplane_here().

## GS_v3norm()

int GS_v3norm | ( | float * | v1 | ) |

Change v1 so that it is a unit vector (3D).

Parameters

  [in,out] | v1 | 3D vector (X,Y,Z)

Returns
  0 if magnitude of v1 is zero
  1 if magnitude of v1 > 0

Definition at line 246 of file gs_util.c.

References X, and Y.

Referenced by GS_set_viewdir(), gsd_3darrow(), gsd_arrow(), gsd_draw_cplane_fence(), and iso_calc_cube().

## GS_v3normalize()

int GS_v3normalize | ( | float * | v1,
|  | float * | v2 )

Change v2 so that v1v2 is a unit vector.

Parameters

  [in] | v1 | first 3D vector (X,Y,Z)
  [in,out] | v2 | second 3D vector (X,Y,Z)

Returns
  0 if magnitude of dx is zero
  1 if magnitude of dx > 0

Definition at line 321 of file gs_util.c.

References X, and Y.

Referenced by GS_init_view(), GS_moveto(), and gsd_check_focus().

## GS_v3sub()

void GS_v3sub | ( | float * | v1,
|  | float * | v2 )

Subtract vectors.

v1 -= v2

Parameters

  [in,out] | v1 | first 3D vector (X,Y,Z)
  | v2 | second 3D vector (X,Y,Z)

Definition at line 212 of file gs_util.c.

References X, and Y.

Referenced by GS_moveto(), and gsd_surf_map_old().