public static AbstractPolygon makePlaneWall(int lineIndex, List <AbstractLineSegment> lineList0, List <AbstractLineSegment> lineList1) { AbstractLineSegment line0 = lineList0[lineIndex]; AbstractLineSegment line1 = lineList1[lineIndex]; AbstractPoint point01; AbstractPoint point02; AbstractPoint point11; AbstractPoint point12; if (line0.GetComponent <InteractableLineSegment>() != null) { point01 = line0.transform.GetComponent <InteractableLineSegment>().point1; point02 = line0.transform.GetComponent <InteractableLineSegment>().point2; } else //(line0.GetComponent<DependentLineSegment>() != null) { point01 = line0.transform.GetComponent <DependentLineSegment>().point1; point02 = line0.transform.GetComponent <DependentLineSegment>().point2; } if (line1.GetComponent <InteractableLineSegment>() != null) { point11 = line1.transform.GetComponent <InteractableLineSegment>().point1; point12 = line1.transform.GetComponent <InteractableLineSegment>().point2; } else //(line1.GetComponent<DependentLineSegment>() != null) { point11 = line1.transform.GetComponent <DependentLineSegment>().point1; point12 = line1.transform.GetComponent <DependentLineSegment>().point2; } AbstractLineSegment line2 = iLineSegment(point01, point11); AbstractLineSegment line3 = iLineSegment(point02, point12); HW_GeoSolver.ins.AddDependence(line2, point01); HW_GeoSolver.ins.AddDependence(line2, point11); HW_GeoSolver.ins.AddDependence(line3, point02); HW_GeoSolver.ins.AddDependence(line3, point12); line2.transform.GetComponent <AbstractLineSegment>().InitializeFigure(); line3.transform.GetComponent <AbstractLineSegment>().InitializeFigure(); List <AbstractLineSegment> lineList = new List <AbstractLineSegment>(); lineList.Add(line0); lineList.Add(line1); lineList.Add(line2); lineList.Add(line3); List <AbstractPoint> pointList = new List <AbstractPoint>(); pointList.Add(point01); pointList.Add(point02); pointList.Add(point12); pointList.Add(point11); return(iPolygon(lineList, pointList)); }
public void makeRevolvedSurface(AbstractLineSegment attachedLine, Vector3 revPoint, Vector3 normDir) { #region intialize a cylinder, cone or conic /etc. InteractablePoint newPoint = InteractablePoint.Constructor(); newPoint.Position3 = revPoint; //nullreference on this line from shipswheel DependentRevolvedSurface drs = GeoObjConstruction.dRevSurface(newPoint.GetComponent <AbstractPoint>(), attachedLine, normDir); HW_GeoSolver.ins.AddDependence(drs, newPoint); HW_GeoSolver.ins.AddDependence(drs, attachedLine.GetComponent <MasterGeoObj>()); #endregion }
private void setupRelativePosition(AbstractGeoObj value) { switch (value.figType) { //case GeoObjType.point: // break; case GeoObjType.line: AbstractLineSegment line = value.GetComponent <AbstractLineSegment>(); relativeWeights.Add(Vector3.Magnitude(Position3 - line.vertex0) / Vector3.Magnitude(line.vertex0 - line.vertex1)); relativeWeights.Add(Vector3.Magnitude(Position3 - line.vertex1) / Vector3.Magnitude(line.vertex0 - line.vertex1)); break; case GeoObjType.polygon: Debug.LogWarning("Polygonsn not yet supported for Relative Movement"); break; //case GeoObjType.prism: // break; //case GeoObjType.pyramid: // break; case GeoObjType.circle: AbstractCircle circle = value.GetComponent <AbstractCircle>(); relativeWeights.Add(Vector3.SignedAngle(circle.edgePos - circle.centerPos, this.Position3 - circle.centerPos, circle.normalDir)); break; case GeoObjType.sphere: Vector3 direction = Vector3.Normalize(this.Position3 - value.GetComponent <AbstractSphere>().centerPosition); relativeWeights.Add(direction.x); relativeWeights.Add(direction.y); relativeWeights.Add(direction.z); break; //case GeoObjType.revolvedsurface: // break; //case GeoObjType.torus: // break; case GeoObjType.flatface: Debug.LogWarning("Flatface not yet supported for Relative Movement"); break; case GeoObjType.straightedge: Debug.LogWarning("Straightedge not yet supported for Relative Movement"); break; default: Debug.LogWarning(value.figType.ToString() + " not supported for relative movement"); break; } }
public static DependentRevolvedSurface dRevSurface(AbstractPoint center, AbstractLineSegment attachedLineSegment, Vector3 normDir) { DependentRevolvedSurface drs = DependentRevolvedSurface.Constructor(); drs.transform.parent = attachedLineSegment.transform.parent; drs.attachedLine = attachedLineSegment; drs.endpoint1 = attachedLineSegment.vertex0; drs.endpoint2 = attachedLineSegment.vertex1; drs.normalDirection = normDir; drs.centerPoint = center.Position3; drs.center = center; HW_GeoSolver.ins.AddDependence(drs, center); HW_GeoSolver.ins.AddDependence(drs, attachedLineSegment); drs.InitializeFigure(); return(drs); }
internal static InteractablePrism iPrism(AbstractPolygon polygon) { List <AbstractLineSegment> lineList0 = polygon.transform.GetComponent <AbstractPolygon>().lineList; List <AbstractPoint> pointList0 = polygon.transform.GetComponent <AbstractPolygon>().pointList; //make new lists for the points and lines in the new plane List <AbstractLineSegment> lineList1 = new List <AbstractLineSegment>(); List <AbstractPoint> pointList1 = new List <AbstractPoint>(); //create new points for the new plane. foreach (AbstractPoint point in pointList0) { AbstractPoint newPoint = iPoint(point.Position3); pointList1.Add(newPoint); } //create new lines for the new plane. foreach (AbstractLineSegment line in lineList0) { if (line.GetComponent <InteractableLineSegment>() != null) { int point1Index = pointList0.IndexOf(line.transform.GetComponent <InteractableLineSegment>().point1); int point2Index = pointList0.IndexOf(line.transform.GetComponent <InteractableLineSegment>().point2); AbstractLineSegment newLine = iLineSegment(pointList1[point1Index], pointList1[point2Index]); lineList1.Add(newLine); HW_GeoSolver.ins.AddDependence(newLine, pointList1[point1Index]); HW_GeoSolver.ins.AddDependence(newLine, pointList1[point2Index]); } else if (line.GetComponent <DependentLineSegment>() != null) { int point1Index = pointList0.IndexOf(line.transform.GetComponent <DependentLineSegment>().point1); int point2Index = pointList0.IndexOf(line.transform.GetComponent <DependentLineSegment>().point2); AbstractLineSegment newLine = iLineSegment(pointList1[point1Index], pointList1[point2Index]); lineList1.Add(newLine); HW_GeoSolver.ins.AddDependence(newLine, pointList1[point1Index]); HW_GeoSolver.ins.AddDependence(newLine, pointList1[point2Index]); } } AbstractPolygon plane1 = iPolygon(lineList1, pointList1); plane1.InitializeFigure(); List <AbstractPolygon> sideList = new List <AbstractPolygon>(); foreach (AbstractLineSegment l in lineList0) { int lineIndex = lineList0.IndexOf(l); sideList.Add(makePlaneWall(lineIndex, lineList0, lineList1)); } InteractablePrism prism = InteractablePrism.Constructor(); List <AbstractPolygon> baseList = new List <AbstractPolygon>(); baseList.Add(polygon); baseList.Add(plane1); prism.bases = baseList; prism.sides = sideList; prism.vertexPoints.ForEach(p => HW_GeoSolver.ins.AddDependence(prism, p)); prism.lineSegments.ForEach(l => HW_GeoSolver.ins.AddDependence(prism, l)); prism.bases.ForEach(b => HW_GeoSolver.ins.AddDependence(prism, b)); prism.sides.ForEach(b => HW_GeoSolver.ins.AddDependence(prism, b)); prism.InitializeFigure(); return(prism); }
internal static InteractablePrism dPrism(AbstractPolygon polygon, Vector3 base2Pos) { List <AbstractLineSegment> lineList0 = new List <AbstractLineSegment>(); List <AbstractPoint> pointList0 = new List <AbstractPoint>(); lineList0 = polygon.transform.GetComponent <AbstractPolygon>().lineList; pointList0 = polygon.transform.GetComponent <AbstractPolygon>().pointList; //make new lists for the points and lines in the new plane List <AbstractLineSegment> lineList1 = new List <AbstractLineSegment>(); List <AbstractPoint> pointList1 = new List <AbstractPoint>(); //create new points for the new plane. foreach (AbstractPoint point in pointList0) { AbstractPoint newPoint = dPoint(point.Position3 - polygon.Position3 + base2Pos); pointList1.Add(newPoint); } //create new lines for the new plane. foreach (AbstractLineSegment line in lineList0) { if (line.GetComponent <InteractableLineSegment>() != null) { int point1Index = pointList0.IndexOf(line.transform.GetComponent <InteractableLineSegment>().point1); int point2Index = pointList0.IndexOf(line.transform.GetComponent <InteractableLineSegment>().point2); AbstractLineSegment newLine = iLineSegment(pointList1[point1Index].GetComponent <AbstractPoint>(), pointList1[point2Index].GetComponent <AbstractPoint>()); lineList1.Add(newLine); HW_GeoSolver.ins.AddDependence(newLine, pointList1[point1Index]); HW_GeoSolver.ins.AddDependence(newLine, pointList1[point2Index]); } else if (line.GetComponent <DependentLineSegment>() != null) { int point1Index = pointList0.IndexOf(line.transform.GetComponent <DependentLineSegment>().point1); int point2Index = pointList0.IndexOf(line.transform.GetComponent <DependentLineSegment>().point2); AbstractLineSegment newLine = iLineSegment(pointList1[point1Index].GetComponent <AbstractPoint>(), pointList1[point2Index].GetComponent <AbstractPoint>()); lineList1.Add(newLine); HW_GeoSolver.ins.AddDependence(newLine, pointList1[point1Index]); HW_GeoSolver.ins.AddDependence(newLine, pointList1[point2Index]); } } AbstractPolygon plane1 = dPolygon(lineList1, pointList1); plane1.AddToRManager(); foreach (AbstractLineSegment line in lineList1) { HW_GeoSolver.ins.AddDependence(plane1, line); } plane1.transform.GetComponent <AbstractPolygon>().InitializeFigure(); List <AbstractPolygon> sideList = new List <AbstractPolygon>(); foreach (AbstractLineSegment line0 in lineList0) { int lineIndex = lineList0.IndexOf(line0); AbstractLineSegment lineTest = lineList0[lineIndex]; sideList.Add(makePlaneWall(lineIndex, lineList0, lineList1)); } InteractablePrism prism = InteractablePrism.Constructor(); List <AbstractPolygon> baseList = new List <AbstractPolygon> { polygon, plane1 }; prism.bases = baseList; prism.sides = sideList; foreach (AbstractPolygon poly in baseList) { HW_GeoSolver.ins.AddDependence(prism, poly); } foreach (AbstractPolygon poly in sideList) { HW_GeoSolver.ins.AddDependence(prism, poly); } prism.vertexPoints.ForEach(p => HW_GeoSolver.ins.AddDependence(prism, p)); prism.InitializeFigure(); return(prism); }
internal void revolve(bool v) { Vector3 spindleCenter = parentSE.GetComponent <straightEdgeBehave>().center; Vector3 normal = parentSE.GetComponent <straightEdgeBehave>().normalDir; foreach (MasterGeoObj geoObj in FindObjectsOfType <MasterGeoObj>().Where(geoObj => (geoObj.IsSelected && geoObj.figType != GeoObjType.straightedge))) { switch (geoObj.figType) { case GeoObjType.point: Vector3 center = Vector3.Project(geoObj.gameObject.transform.position - spindleCenter, parentSE.normalDir) + spindleCenter; makeCircle(center, geoObj.GetComponent <AbstractPoint>(), normal); //geoObj.IsSelected = false; break; case GeoObjType.line: Vector3 center2 = Vector3.Project(geoObj.gameObject.transform.position - spindleCenter, parentSE.normalDir) + spindleCenter; makeRevolvedSurface(geoObj.GetComponent <AbstractLineSegment>(), center2, normal); AbstractLineSegment lineALS = geoObj.GetComponent <AbstractLineSegment>(); Vector3 diff1 = Vector3.Project(lineALS.vertex0 - lineALS.transform.position, normal); Vector3 diff2 = Vector3.Project(lineALS.vertex1 - lineALS.transform.position, normal); if (geoObj.GetComponent <InteractableLineSegment>() != null) { makeCircle(center2 + diff1, geoObj.GetComponent <InteractableLineSegment>().point1, normal); makeCircle(center2 + diff2, geoObj.GetComponent <InteractableLineSegment>().point2, normal); } else if (geoObj.GetComponent <DependentLineSegment>() != null) { makeCircle(center2 + diff1, geoObj.GetComponent <DependentLineSegment>().point1, normal); makeCircle(center2 + diff2, geoObj.GetComponent <DependentLineSegment>().point2, normal); } else { Debug.LogWarning("Can't work with abstractlinesegments yet"); } //geoObj.IsSelected = false; break; case GeoObjType.polygon: foreach (AbstractLineSegment lineObj in geoObj.transform.GetComponent <AbstractPolygon>().lineList) { Vector3 center3 = Vector3.Project(lineObj.gameObject.transform.position - spindleCenter, parentSE.normalDir) + spindleCenter; makeRevolvedSurface(lineObj, center3, normal); if (lineObj.GetComponent <InteractableLineSegment>() != null) { Vector3 diff12 = Vector3.Project(lineObj.GetComponent <InteractableLineSegment>().point1.transform.position - lineObj.transform.position, normal); Vector3 diff22 = Vector3.Project(lineObj.GetComponent <InteractableLineSegment>().point2.transform.position - lineObj.transform.position, normal); makeCircle(center3 + diff12, lineObj.GetComponent <InteractableLineSegment>().point1, normal); makeCircle(center3 + diff22, lineObj.GetComponent <InteractableLineSegment>().point2, normal); } else if (lineObj.GetComponent <DependentLineSegment>() != null) { Vector3 diff12 = Vector3.Project(lineObj.GetComponent <DependentLineSegment>().point1.transform.position - lineObj.transform.position, normal); Vector3 diff22 = Vector3.Project(lineObj.GetComponent <DependentLineSegment>().point2.transform.position - lineObj.transform.position, normal); makeCircle(center3 + diff12, lineObj.GetComponent <DependentLineSegment>().point1, normal); makeCircle(center3 + diff22, lineObj.GetComponent <DependentLineSegment>().point2, normal); } else { Debug.LogWarning("Can't work with abstractlinesegments yet"); } } //geoObj.IsSelected = false; break; case GeoObjType.revolvedsurface: break; case GeoObjType.circle: // //check if the circle and the axis are orthagonal. This is a trivial case. // //if (Vector3.Magnitude(Vector3.Cross(arcObj.GetComponent<ArcBehave>().normalDirection, parentSE.normalDir())) > 0) // //{ // //check if the circle's center is on the axis of rotation. This produces a sphere. Else produce a torus. // if (Vector3.Magnitude(Vector3.ProjectOnPlane(arcObj.GetComponent<ArcBehave>().centerPoint.transform.position - parentSE.center(), parentSE.normalDir())) < .05f) // { // //make sphere // if (Vector3.Magnitude(Vector3.Cross(Vector3.Normalize(arcObj.GetComponent<ArcBehave>().normalDirection), Vector3.Normalize(parentSE.normalDir()))) - 1 < .01f) // { // makeSphere(arcObj.transform, Vector3.Magnitude(Vector3.ProjectOnPlane(arcObj.GetComponent<ArcBehave>().attachedPoint.transform.position - parentSE.center(), parentSE.normalDir()))); // }else // { // Debug.Log("Arc not Orthagonal, Doesn't make a sphere."); // } // } // else // { // makeTorus(arcObj.transform, parentSE.normalDir()); // } break; case GeoObjType.prism: foreach (AbstractLineSegment line in geoObj.GetComponent <InteractablePrism>().lineSegments) { Vector3 center3 = Vector3.Project(geoObj.gameObject.transform.position - spindleCenter, parentSE.normalDir) + spindleCenter; makeRevolvedSurface(geoObj.GetComponent <AbstractLineSegment>(), center3, normal); AbstractLineSegment lineALS2 = geoObj.GetComponent <AbstractLineSegment>(); Vector3 diff1b = Vector3.Project(lineALS2.vertex0 - lineALS2.transform.position, normal); Vector3 diff2b = Vector3.Project(lineALS2.vertex1 - lineALS2.transform.position, normal); if (geoObj.GetComponent <InteractableLineSegment>() != null) { makeCircle(center3 + diff1b, geoObj.GetComponent <InteractableLineSegment>().point1, normal); makeCircle(center3 + diff2b, geoObj.GetComponent <InteractableLineSegment>().point2, normal); } else if (geoObj.GetComponent <DependentLineSegment>() != null) { makeCircle(center3 + diff1b, geoObj.GetComponent <DependentLineSegment>().point1, normal); makeCircle(center3 + diff2b, geoObj.GetComponent <DependentLineSegment>().point2, normal); } else { Debug.LogWarning("Can't work with abstractlinesegments yet"); } } break; } } }
internal override void SnapToFigure(AbstractGeoObj toObj) { Debug.Log(name + " is attempting to snap to " + toObj.name + "."); //if object and child objects are not being grasped if (!(this.GetComponent <InteractionBehaviour>().isGrasped)) { ///this object is being grasped switch (toObj.figType) { case GeoObjType.point: Position3 = toObj.Position3; break; case GeoObjType.line: Position3 = Vector3.Project(Position3 - toObj.Position3, toObj.GetComponent <AbstractLineSegment>().vertex0 - toObj.GetComponent <AbstractLineSegment>().vertex1) + toObj.Position3; break; case GeoObjType.polygon: Vector3 positionOnPlane = Vector3.ProjectOnPlane(Position3 - toObj.Position3, toObj.GetComponent <AbstractPolygon>().normDir) + toObj.Position3; if (toObj.GetComponent <AbstractPolygon>().checkInPolygon(positionOnPlane)) { Position3 = positionOnPlane; } break; //case GeoObjType.prism: // break; //case GeoObjType.pyramid: // break; case GeoObjType.circle: Vector3 positionOnPlane2 = Vector3.ProjectOnPlane(Position3 - toObj.Position3, toObj.GetComponent <AbstractCircle>().normalDir) + toObj.Position3; if (Vector3.Magnitude(positionOnPlane2 - toObj.Position3) == toObj.GetComponent <AbstractCircle>().Radius) { Position3 = positionOnPlane2; } break; case GeoObjType.sphere: Vector3 lineDir = Vector3.Normalize(Position3 - toObj.Position3); Position3 = toObj.GetComponent <AbstractSphere>().radius *lineDir + toObj.Position3; break; //case GeoObjType.revolvedsurface: // break; //case GeoObjType.torus: // break; case GeoObjType.flatface: Position3 = Vector3.ProjectOnPlane(Position3 - toObj.Position3, toObj.GetComponent <flatfaceBehave>().normalDir) + toObj.Position3; break; case GeoObjType.straightedge: Position3 = Vector3.Project(Position3 - toObj.Position3, toObj.GetComponent <straightEdgeBehave>().normalDir) + toObj.Position3; break; default: break; } setupRelativePosition(toObj); } else { switch (toObj.figType) { case GeoObjType.point: this.Position3 = toObj.Position3; break; case GeoObjType.line: AbstractLineSegment line = toObj.GetComponent <AbstractLineSegment>(); this.Position3 = line.vertex0 * relativeWeights[0] + line.vertex1 * relativeWeights[1]; break; case GeoObjType.polygon: Debug.LogWarning("Polygon not yet supported for Relative Movement"); break; //case GeoObjType.prism: // break; //case GeoObjType.pyramid: // break; case GeoObjType.circle: AbstractCircle circle = toObj.GetComponent <AbstractCircle>(); Vector3 basis1 = circle.edgePos - circle.centerPos; Vector3 basis2 = Vector3.Cross(basis1, circle.normalDir); Vector3.OrthoNormalize(ref basis1, ref basis2); this.Position3 = circle.Radius * (basis1 * Mathf.Sin(relativeWeights[0]) + basis2 * Mathf.Cos(relativeWeights[0])) + circle.centerPos; break; case GeoObjType.sphere: Vector3 direction = relativeWeights[0] * Vector3.right + relativeWeights[1] * Vector3.up + relativeWeights[2] * Vector3.forward; this.Position3 = toObj.GetComponent <AbstractSphere>().radius *direction; break; //case GeoObjType.revolvedsurface: // break; //case GeoObjType.torus: // break; case GeoObjType.flatface: Debug.LogWarning("Straightedge not yet supported for Relative Movement"); break; case GeoObjType.straightedge: Debug.LogWarning("Straightedge not yet supported for Relative Movement"); break; default: Debug.LogWarning(toObj.figType.ToString() + " not supported for relative movement"); break; } } }