private double AngleBetweenTwoPoints(IGTVector iVector) { double dAngleBetweenTwoPoints; dAngleBetweenTwoPoints = Math.Atan2(iVector.J, iVector.I) * (180 / Math.PI); return(dAngleBetweenTwoPoints); }
/// <summary> /// Get Vector By Angle /// </summary> /// <param name="angle"></param> /// <returns></returns> protected IGTVector VectorByAngle(double angle) { IGTVector vector = GTClassFactory.Create <IGTVector>(); vector.I = Math.Cos(angle); vector.J = Math.Sin(angle); vector.K = 0; return(vector); }
private double AngleBetweenTwoPoints(IGTVector iVector) { try { double dAngleBetweenTwoPoints; dAngleBetweenTwoPoints = Math.Atan2(iVector.J, iVector.I) * (180 / Math.PI); return(dAngleBetweenTwoPoints); } catch (Exception) { throw; } }
private IGTMatrix TranslationTransform(IGTVector Voffset) { IGTMatrix m = null; try { m = GTClassFactory.Create <IGTMatrix>(); m.M_Matrix[0, 0] = 1.0; m.M_Matrix[0, 1] = 0.0; m.M_Matrix[0, 2] = 0.0; m.M_Matrix[0, 3] = 0.0; m.M_Matrix[1, 0] = 0.0; m.M_Matrix[1, 1] = 1.0; m.M_Matrix[1, 2] = 0.0; m.M_Matrix[1, 3] = 0.0; m.M_Matrix[2, 0] = 0.0; m.M_Matrix[2, 1] = 0.0; m.M_Matrix[2, 2] = 1.0; m.M_Matrix[2, 3] = 0.0; m.M_Matrix[3, 0] = Voffset.I; m.M_Matrix[3, 1] = Voffset.J; m.M_Matrix[3, 2] = Voffset.K; m.M_Matrix[3, 3] = 1.0; return(m); } catch (Exception) { throw; } }
internal IGTMatrix TranslationTransform(IGTVector Voffset) { IGTMatrix m = null; try { m = GTClassFactory.Create <IGTMatrix>(); m.M_Matrix[0, 0] = 1.0; m.M_Matrix[0, 1] = 0.0; m.M_Matrix[0, 2] = 0.0; m.M_Matrix[0, 3] = 0.0; m.M_Matrix[1, 0] = 0.0; m.M_Matrix[1, 1] = 1.0; m.M_Matrix[1, 2] = 0.0; m.M_Matrix[1, 3] = 0.0; m.M_Matrix[2, 0] = 0.0; m.M_Matrix[2, 1] = 0.0; m.M_Matrix[2, 2] = 1.0; m.M_Matrix[2, 3] = 0.0; m.M_Matrix[3, 0] = Voffset.I; m.M_Matrix[3, 1] = Voffset.J; m.M_Matrix[3, 2] = Voffset.K; m.M_Matrix[3, 3] = 1.0; return(m); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } }
public double Vector2Angle(IGTVector vector) { double angle = 0; double x; double y; x = vector.I; y = vector.J; if (x != 0) { angle = Math.Atan(y / x) * 180 / Math.PI; if (x < 0) { angle = angle + 180; } else if (y < 0) { angle = angle + 360; } if (angle == 360) { angle = 0; } } else { if (y >= 0) { angle = 90; } else { angle = 270; } } return(angle); }
private IGTCompositePolylineGeometry BuildAreaGeometryFromPoint(IGTPoint point, double distance) { try { IGTArcGeometry arcGeometry = GTClassFactory.Create <IGTArcGeometry>(); IGTCompositePolylineGeometry compositePolylineGeometry = GTClassFactory.Create <IGTCompositePolylineGeometry>(); IGTVector vector = GTClassFactory.Create <IGTVector>(); vector.I = 0; vector.J = 0; vector.K = 1; IGTGeometry geometry = arcGeometry.ComputeArcByOriginAndAngles(point, vector, distance, 0.0, Math.PI); compositePolylineGeometry.Add(geometry); geometry = arcGeometry.ComputeArcByOriginAndAngles(point, vector, distance, Math.PI, 2 * Math.PI); compositePolylineGeometry.Add(geometry); return(compositePolylineGeometry); } catch (Exception) { throw; } }
public IGTPoint GetOffsetPoint(IGTPoint inputPt, double offsetX, double offsetY, IGTVector vector) { double angle = Vector2Angle(vector); double rotatedOffsetX = (Math.Cos(angle * Math.PI / 180) * offsetX) - (Math.Sin(angle * Math.PI / 180) * offsetY); double rotatedOffsetY = (Math.Sin(angle * Math.PI / 180) * offsetX) + (Math.Cos(angle * Math.PI / 180) * offsetY); IGTPoint gtPt = GTClassFactory.Create <IGTPoint>(); gtPt.X = inputPt.X + rotatedOffsetX; gtPt.Y = inputPt.Y + rotatedOffsetY; return(gtPt); }
/// <summary> /// Rotates input geometry relative to the reference geom /// </summary> /// <param name="ogeom"></param> /// <returns></returns> private void RotateGeom(IGTGeometry refGeom, ref IGTPolygonGeometry inpGeom) { double dAngle = 0; IGTPolygonGeometry oPolyGeom = null; try { if (refGeom == null || inpGeom == null) { return; } if (refGeom.GetType().ToString() == "Intergraph.GTechnology.Private.GTOrientedPointGeometry") { dAngle = AngleBetweenTwoPoints(((IGTOrientedPointGeometry)refGeom).Orientation); } else if (refGeom.GetType().ToString() == "Intergraph.GTechnology.Private.GTPolygonGeometry") { oPolyGeom = (IGTPolygonGeometry)refGeom.Stroke(); dAngle = AngleBetweenTwoPoints(oPolyGeom.Points[0], oPolyGeom.Points[1]); } if (dAngle < -90.0 || dAngle > 90.0) { dAngle = dAngle + 180.0; } IGTVector transVec = GTClassFactory.Create <IGTVector>(); if (inpGeom.GetType().ToString() == "Intergraph.GTechnology.Private.GTPolygonGeometry") { // move and rotate the geometry to the correct position if (m_ActiveMapWindow.DetailID == 0) { transVec.I = refGeom.FirstPoint.X * -1; transVec.J = refGeom.FirstPoint.Y * -1; transVec.K = refGeom.FirstPoint.Z * -1; } else { if (m_CentriodPoint != null) { transVec.I = m_CentriodPoint.X * -1; transVec.J = m_CentriodPoint.Y * -1; transVec.K = m_CentriodPoint.Z * -1; } } } IGTMatrix tmpTMatrix = GTClassFactory.Create <IGTMatrix>(); tmpTMatrix = TranslationTransform(transVec); inpGeom = (IGTPolygonGeometry)inpGeom.Multiply(inpGeom, tmpTMatrix); // rotate the geometry to the angle of the tmpTMatrix = GTClassFactory.Create <IGTMatrix>(); tmpTMatrix = RotateZTransform(dAngle, 'D'); inpGeom = (IGTPolygonGeometry)inpGeom.Multiply(inpGeom, tmpTMatrix); transVec = transVec.NegateVector(transVec); tmpTMatrix = GTClassFactory.Create <IGTMatrix>(); tmpTMatrix = TranslationTransform(transVec); inpGeom = (IGTPolygonGeometry)inpGeom.Multiply(inpGeom, tmpTMatrix); } catch (Exception) { throw; } finally { } }