/// <summary> /// The my get normal for plane face. /// </summary> /// <param name="firstFace"> /// The first face. /// </param> /// <param name="firstPoint"> /// The first point. /// </param> /// <returns> /// The <see cref="double[]"/>. /// </returns> public static double[] MyGetNormalForPlaneFace(Face2 firstFace, out double[] firstPoint) { var firstSurface = (Surface)firstFace.GetSurface(); var firstNormal = new double[3]; firstPoint = new double[3]; Array firstValuesPlane = null; if (firstSurface.IsPlane()) { firstValuesPlane = firstSurface.PlaneParams; Array.Copy(firstValuesPlane, 0, firstNormal, 0, 3); Array.Copy(firstValuesPlane, 3, firstPoint, 0, 3); } // Pongo il verso della normale alla superficie concorde con quello della faccia. if (!firstFace.FaceInSurfaceSense()) { firstNormal.SetValue((double)firstValuesPlane.GetValue(0), 0); firstNormal.SetValue((double)firstValuesPlane.GetValue(1), 1); firstNormal.SetValue((double)firstValuesPlane.GetValue(2), 2); } else { firstNormal.SetValue(-(double)firstValuesPlane.GetValue(0), 0); firstNormal.SetValue(-(double)firstValuesPlane.GetValue(1), 1); firstNormal.SetValue(-(double)firstValuesPlane.GetValue(2), 2); } return(firstNormal); }
private void GetInfoPlan() { Boolean Reverse = SwFace.FaceInSurfaceSense(); if (Surface.IsPlane()) { Double[] Param = Surface.PlaneParams; if (Reverse) { Param[0] = Param[0] * -1; Param[1] = Param[1] * -1; Param[2] = Param[2] * -1; } Origine = new gPoint(Param[3], Param[4], Param[5]); Normale = new gVecteur(Param[0], Param[1], Param[2]); } }
public static double[] KLMyGetNormalForPlaneFace(Face2 firstFace, out double[] firstPoint, double[,] transformMatrix) { var firstSurface = (Surface)firstFace.GetSurface(); var firstNormal = new double[3]; firstPoint = new double[3]; Array firstValuesPlane = null; if (firstSurface.IsPlane()) { firstValuesPlane = firstSurface.PlaneParams; Array.Copy(firstValuesPlane, 0, firstNormal, 0, 3); Array.Copy(firstValuesPlane, 3, firstPoint, 0, 3); } // Pongo il verso della normale alla superficie concorde con quello della faccia. if (!firstFace.FaceInSurfaceSense()) { firstNormal.SetValue((double)firstValuesPlane.GetValue(0), 0); firstNormal.SetValue((double)firstValuesPlane.GetValue(1), 1); firstNormal.SetValue((double)firstValuesPlane.GetValue(2), 2); } else { firstNormal.SetValue(-(double)firstValuesPlane.GetValue(0), 0); firstNormal.SetValue(-(double)firstValuesPlane.GetValue(1), 1); firstNormal.SetValue(-(double)firstValuesPlane.GetValue(2), 2); } if (transformMatrix != null) { double[] firstNormalAffine = { (double)firstNormal.GetValue(0), (double)firstNormal.GetValue(1), (double)firstNormal.GetValue(2), 1 }; double[] firstPointAffine = { (double)firstPoint.GetValue(0), (double)firstPoint.GetValue(1), (double)firstPoint.GetValue(2), 1 }; var newFirstNormal = Matrix.Multiply(transformMatrix, firstNormalAffine); var newFirstPoint = Matrix.Multiply(transformMatrix, firstPointAffine); firstNormal.SetValue((double)newFirstNormal.GetValue(0), 0); firstNormal.SetValue((double)newFirstNormal.GetValue(1), 1); firstNormal.SetValue((double)newFirstNormal.GetValue(2), 2); firstPoint.SetValue((double)newFirstPoint.GetValue(0), 0); firstPoint.SetValue((double)newFirstPoint.GetValue(1), 1); firstPoint.SetValue((double)newFirstPoint.GetValue(2), 2); } return(firstNormal); }
public static Array MyNormalInPoint(Face2 face, double x, double y, double z) { var normal = new double[3]; var mySurf = (Surface)face.GetSurface(); double[] firstEvalutation = mySurf.EvaluateAtPoint(x, y, z); // --> EvaluateAtPoint restituisce la normale alla superficie in un punto! if (face.FaceInSurfaceSense()) { normal.SetValue((double)firstEvalutation.GetValue(0), 0); normal.SetValue((double)firstEvalutation.GetValue(1), 1); normal.SetValue((double)firstEvalutation.GetValue(2), 2); } else { normal.SetValue(-(double)firstEvalutation.GetValue(0), 0); normal.SetValue(-(double)firstEvalutation.GetValue(1), 1); normal.SetValue(-(double)firstEvalutation.GetValue(2), 2); } return(normal); }
public static bool samePlane(Face2 firstFace, Face2 secondFace, SldWorks swApp) { var firstSurf = (Surface)firstFace.GetSurface(); var secondSurf = (Surface)secondFace.GetSurface(); var firstParameters = (Array)firstSurf.PlaneParams; var secondParameters = (Array)secondSurf.PlaneParams; var firstNormal = new double[3]; var firstPoint = new double[3]; var secondNormal = new double[3]; var secondPoint = new double[3]; Array.Copy(firstParameters, 0, firstNormal, 0, 3); Array.Copy(firstParameters, 3, firstPoint, 0, 3); Array.Copy(secondParameters, 0, secondNormal, 0, 3); Array.Copy(secondParameters, 3, secondPoint, 0, 3); if (!firstFace.FaceInSurfaceSense()) { firstNormal.SetValue(-(double)firstNormal.GetValue(0), 0); firstNormal.SetValue(-(double)firstNormal.GetValue(1), 1); firstNormal.SetValue(-(double)firstNormal.GetValue(2), 2); } if (!secondFace.FaceInSurfaceSense()) { secondNormal.SetValue(-(double)secondNormal.GetValue(0), 0); secondNormal.SetValue(-(double)secondNormal.GetValue(1), 1); secondNormal.SetValue(-(double)secondNormal.GetValue(2), 2); } var results = Math.Abs(Matrix.InnerProduct(firstNormal, secondNormal) - 1); var normalPrint = String.Format("{0} {1} {2} --- {3} {4} {5} = {6}", firstNormal[0], firstNormal[1], firstNormal[2], secondNormal[0], secondNormal[1], secondNormal[2], results); var firstEquation = new double[4] { (double)firstNormal.GetValue(0), (double)firstNormal.GetValue(1), (double)firstNormal.GetValue(2), -(double)firstNormal.GetValue(0) * (double)firstPoint.GetValue(0) - (double)firstNormal.GetValue(1) * (double)firstPoint.GetValue(1) - (double)firstNormal.GetValue(2) * (double)firstPoint.GetValue(2), }; var secondEquation = new double[4] { (double)secondNormal.GetValue(0), (double)secondNormal.GetValue(1), (double)secondNormal.GetValue(2), -(double)secondNormal.GetValue(0) * (double)secondPoint.GetValue(0) - (double)secondNormal.GetValue(1) * (double)secondPoint.GetValue(1) - (double)secondNormal.GetValue(2) * (double)secondPoint.GetValue(2), }; var equationPrint = String.Format("Eq: {0}x {1}y {2}z = {3}", firstEquation[0], firstEquation[1], firstEquation[2], firstEquation[3]); /* * if (Math.Abs(Accord.Math.Matrix.InnerProduct(firstNormal, secondNormal) - 1) < 0.001) * { * swApp.SendMsgToUser("Normale uguale"); * return false; * } */ //return firstEquation.Equals(secondFace); if (Math.Abs(firstEquation[0] - secondEquation[0]) < 0.01 && Math.Abs(firstEquation[1] - secondEquation[1]) < 0.01 && Math.Abs(firstEquation[2] - secondEquation[2]) < 0.01 && Math.Abs(firstEquation[3] - secondEquation[3]) < 0.01) { swApp.SendMsgToUser("Equazione uguale"); return(true); } return(false); }