# [postgis-users] Finding that third point on an arc.

Blake Crosby me at blakecrosby.com
Mon Sep 7 09:03:11 PDT 2009

```For posterity:

Here is a function to do what I want:

CREATE OR REPLACE FUNCTION st_createarc(startpoint geometry, endpoint
geometry, arcenter geometry)
RETURNS geometry AS
\$\$
DECLARE
pointonarc geometry;
thearc text;
BEGIN
pointonarc := ST_Translate( ST_Rotate( ST_Translate(
startpoint, -1*ST_X(arcenter), -1*ST_Y(arcenter)), pi()/5),
ST_X(arcenter), ST_Y(arcenter));
thearc := 'CIRCULARSTRING('||ST_X(startpoint)||'
'||ST_Y(startpoint)||','||ST_X(pointonarc)||'
'||ST_Y(pointonarc)||','||ST_X(endpoint)||' '||ST_Y(endpoint)||')';
RETURN
st_transform(st_curvetoline(st_transform(st_setsrid(thearc,st_srid(arcenter)),utmzone(arcenter))),st_srid(arcenter));
END;
\$\$
LANGUAGE 'plpgsql' IMMUTABLE;
COMMENT ON FUNCTION st_createarc(geometry,geometry,geometry) IS
'Generates an arc based on starting point, ending point and centre of
arc. All geometries must be of type POINT and this function returns a
linestring of the arc based on the original SRID and 32 points per
quarter circle. Requires the utmzone function.';

Blake Crosby wrote:
> Hello,
>
> I have:
>
> - Starting Point (lat/long, srid=4326)
> Ps = POINT(-75.7016666666667 45.1127777777778)
> - Ending Point (lat/long, srid=4326)
> Pe = POINT(-75.5627777777778 45.0972222222222)
> - Centre of arc (lat/long, srid=4326)
> Pc= POINT(-75.6333333333333 45.1)
>
> I thought I could construct a circular line string, however you need an
> odd number of points. To get that third point, I was going to use the
> rotate function found here:
>
> http://trac.osgeo.org/postgis/wiki/UsersWikiplpgsqlfunctions
>
> To rotate the starting point (Ps) 90 degrees and use that result as the
> third part of arc.
>
> The resulting arc looks more like an ellipse when being projected in my
> final projection.
>
> Does anyone know where I'm going wrong? Essentially I'm doing this:
>
> Rotate Ps:
> select astext(rotateatpoint(st_geomfromtext('POINT(-75.7016666666667
> 45.1127777777778)',4326),-75.7016666666667,45.1127777777778,pi()/2));
>                   astext
> -------------------------------------------
>  POINT(-75.7016666666667 45.1127777777778)
>
> generate arc, and convert to a linestring:
>
> select
> astext(st_curvetoline(st_geomfromtext('CIRCULARSTRING(-75.7016666666667
> 45.1127777777778,-75.5627777777778 45.0972222222222,-75.7016666666667
> 45.1127777777778)',4326)));
>
> Take a look at the screen shot here. The outer arc is the one generated
> here, the inner one is what I need to get.
>
> http://www.blakecrosby.com/arc.png
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>

```