示例#1
0
        /// <summary>
        ///  returns a pnt rotated from angle degrees around the axis
        /// </summary>
        /// <param name="angle">in defree</param>
        /// <param name="axis"></param>
        /// <returns></returns>
        public Pnt Rotate(double angle, Pnt axis)
        {
            Pnt p = this;

            p.Rotated(angle, axis);
            return(p);
        }
示例#2
0
 public Edge(Edge e)
 {
     v        = e.v;
     this.p1  = e.p1;
     this.p2  = e.p2;
     this.pts = e.pts;
 }
示例#3
0
        // constructors
        public Edge(List <gp_Pnt> pts)
        {
            this.pts = ToPnt(pts);
            p1       = ToPnt(pts[0]);
            p2       = ToPnt(pts[1]);

            v = ToPnt(pts[1]) - ToPnt(pts[0]);
        }
示例#4
0
 // comparison
 public bool IsEqual(Pnt p2)
 {
     if (this.x == p2.x && this.y == p2.y && this.z == p2.z)
     {
         return(true);
     }
     return(false);
 }
示例#5
0
 public Pnt(Pnt p)
 {
     x = p.x;
     y = p.y;
     z = p.z;
     d.Clear();
     d.Add(p.x);
     d.Add(p.y);
     d.Add(p.z);
 }
示例#6
0
        /// <summary>
        /// modifies the edge
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        public void Replace(Pnt p1, Pnt p2)
        {
            v = p2 - p1;


            this.pts.Clear();
            this.pts.Add(p1);
            this.pts.Add(p2);
            this.p1 = p1;
            this.p2 = p2;
        }
示例#7
0
        }//*/

        /// <summary>
        /// we want to know if the vertex "what" already exists in our list of unique vertices "from"
        /// </summary>
        /// <param name="from"> the list of unique vertices</param>
        /// <param name="what"> the vertex we are looking at</param>
        /// <returns>returns the index of the vertex or -1 if it is the first time we see that vertex</returns>
        public int ExistsIn(List <Pnt> from, Pnt what)
        {
            for (int i = 0; i < from.Count; i++)
            {
                if (from[i].x == what.x && from[i].y == what.y && from[i].z == what.z)
                {
                    return(i);
                }
            }
            return(-1);
        }//*/
示例#8
0
        public Edge(gp_Pnt p1, gp_Pnt p2)
        {
            v = ToPnt(p2) - ToPnt(p1);


            this.pts.Clear();
            this.pts.Add(ToPnt(p1));
            this.pts.Add(ToPnt(p2));
            this.p1 = ToPnt(p1);
            this.p2 = ToPnt(p2);
        }
示例#9
0
        public Edge(Pnt p1, Pnt p2)
        {
            v = p2 - p1;


            this.pts.Clear();
            this.pts.Add(p1);
            this.pts.Add(p2);
            this.p1 = p1;
            this.p2 = p2;
        }
示例#10
0
        /// <summary>
        /// modifies the edge
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        public void Replace(gp_Pnt p1, gp_Pnt p2)
        {
            v = ToPnt(p2) - ToPnt(p1);


            this.pts.Clear();
            this.pts.Add(ToPnt(p1));
            this.pts.Add(ToPnt(p2));
            this.p1 = ToPnt(p1);
            this.p2 = ToPnt(p2);
        }
示例#11
0
        /// <summary>
        /// signed angle between two vectors defined by p1 and p2
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="axis">normale of the plane defined by the two vectors</param>
        /// <returns></returns>
        public static double SignedAngle(Pnt p1, Pnt p2, Pnt axis)
        {
            double angle = Math.Acos(DotProduct(Normalize(p1), Normalize(p2)));
            Pnt    cross = Cross(p1, p2);

            if (DotProduct(axis, cross) < 0)
            { // Or > 0
                angle = -angle;
            }
            return(angle * 360 / (2 * Math.PI)); // in degree
        }
示例#12
0
 /// <summary>
 ///  retrieves the index of the vertex (pt)
 /// </summary>
 /// <param name="pt"> the vertex for which we want to know the index</param>
 /// <returns>returns the index of pt</returns>
 public int RetrievesIndex(Pnt pt)
 {
     // if we don't know that vertex, we add it to the vertices
     if (ExistsIn(vertices, pt) == -1)
     {
         vertices.Add(pt);
         return(vertices.Count - 1);
     }
     else
     {
         // otherwise we get the index of that already known vertex
         return(ExistsIn(vertices, pt));
     }
 }//*/
示例#13
0
        /// <summary>
        /// rotate this from the angle "angle" around the axis "axis"
        /// </summary>
        /// <param name="angle">in degree</param>
        /// <param name="axis"></param>
        public void Rotated(double angle, Pnt axis)
        {
            angle = angle * Math.PI / 180; // converting to radians


            double rx = x * (Math.Cos(angle) + axis.x * axis.x * (1 - Math.Cos(angle))) + y * (axis.x * axis.y * (1 - Math.Cos(angle)) - axis.z * Math.Sin(angle)) + z * (axis.x * axis.z * (1 - Math.Cos(angle)) + axis.y * Math.Sin(angle));
            double ry = x * (axis.y * axis.x * (1 - Math.Cos(angle)) + axis.z * Math.Sin(angle)) + y * (Math.Cos(angle) + axis.y * axis.y * (1 - Math.Cos(angle))) + z * (axis.y * axis.z * (1 - Math.Cos(angle)) - axis.x * Math.Sin(angle));
            double rz = x * (axis.z * axis.x * (1 - Math.Cos(angle) - axis.y * Math.Sin(angle))) + y * (axis.z * axis.y * (1 - Math.Cos(angle)) + axis.x * Math.Sin(angle)) + z * (Math.Cos(angle) + axis.z * axis.z * (1 - Math.Cos(angle)));

            x = rx;
            y = ry;
            z = rz;
            d.Clear();
            d.Add(rx);
            d.Add(ry);
            d.Add(rz);
        }
示例#14
0
 /// <summary>
 /// angle between two edges
 /// </summary>
 /// <param name="e"></param>
 /// <param name="axis"></param>
 /// <returns></returns>
 public double Angle(Edge e, Pnt axis)
 {
     return(this.v.IsEqual(e.v) ? 0 : Pnt.SignedAngle(v, e.v, axis));
 }
示例#15
0
        /// <summary>
        /// angle between the two vectors
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        public static double Angle(Pnt p1, Pnt p2)
        {
            double angle = Math.Acos(DotProduct(Normalize(p1), Normalize(p2)));

            return(angle * 360 / (2 * Math.PI)); // in degree;
        }
示例#16
0
 /// <summary>
 /// dot product of the two vectors
 /// </summary>
 /// <param name="e1"></param>
 /// <param name="e2"></param>
 /// <returns></returns>
 public static double DotProduct(Pnt e1, Pnt e2)
 {
     return(e1.x * e2.x + e1.y * e2.y + e1.z * e2.z);
 }
示例#17
0
 /// <summary>
 /// dot product between this and the vector e2
 /// </summary>
 /// <param name="e2"></param>
 /// <returns></returns>
 public double DotProduct(Pnt e2)
 {
     return(x * e2.x + y * e2.y + z * e2.z);
 }
示例#18
0
 /// <summary>
 /// returns the distance between this and pt
 /// </summary>
 /// <param name="pt"></param>
 /// <returns></returns>
 public double Distance(Pnt pt)
 {
     return(Math.Sqrt((x - pt.x) * (x - pt.x) + (y - pt.y) * (y - pt.y) + (z - pt.z) * (z - pt.z)));
 }
示例#19
0
 /// <summary>
 /// cross product between the two vectors
 /// </summary>
 /// <param name="p1"></param>
 /// <param name="p2"></param>
 /// <returns></returns>
 public static Pnt Cross(Pnt p1, Pnt p2)
 {
     return(new Pnt(p1.y * p2.z - p1.z * p2.y, p1.z * p2.x - p1.x * p2.z, p1.x * p2.y - p1.y * p2.x));
 }
示例#20
0
        /// <summary>
        /// normalization of the vector
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static Pnt Normalize(Pnt p)
        {
            double L = Math.Sqrt(p.x * p.x + p.y * p.y + p.z * p.z);

            return(L == 0 ? p : p / L);
        }