How to transform three-dimensional coordinates into two-dimensional coordinates

How to transform three-dimensional coordinates into two-dimensional coordinates

846081597
Enthusiast Enthusiast
1,244 Views
6 Replies
Message 1 of 7

How to transform three-dimensional coordinates into two-dimensional coordinates

846081597
Enthusiast
Enthusiast

Hi,i i have no idea when i want to transform three-dimensional coordinates into two-dimensional coordinates,thie following is my code:

Reference refFace = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Face, "Please select a face!");

CurveArrArray cutProfiles = new CurveArrArray();
CurveArray cutCurves = new CurveArray();
Element elem = doc.GetElement(refFace);
GeometryObject selectedGeoObject = elem.GetGeometryObjectFromReference(refFace);

selectedFace = selectedGeoObject as Face;

EdgeArrayArray edgeArrays = selectedFace.EdgeLoops;
foreach (EdgeArray edges in edgeArrays)
{
foreach (Edge e in edges)
{
cutCurves.Append(e.AsCurve()); 

}
}
cutProfiles.Append(cutCurves);

 

CurveArray path= new CurveArray();

Line line =Line.CreateBound(new XYZ(0,0,0),new XYZ(10,10,10));

SweepProfile Sprofile = application.Create.NewCurveLoopsProfile(cutProfiles);

Sweep sweep = doc.FamilyCreate.NewSweep(false, path, sketchPlane, Sprofile, 0, ProfilePlaneLocation.Start);

 

it is failed,i find the curve in cutProfiles is three-dimensional and the profile in sweep need two-dimensional, i need your help,thankyou.

Accepted solutions (1)
1,245 Views
6 Replies
Replies (6)
Message 2 of 7

Revitalizer
Advisor
Advisor
0 Likes
Message 3 of 7

846081597
Enthusiast
Enthusiast

Thank you for your help. Now i can get the function GetTransformToZ() in jeremytammikk's code,however jeremytammikk says that"Applying the transform to the polygon is achieved by applying it individually to each vertex." with the code

List<XYZ> polygonHorizontal     = ApplyTransform( polygon, t );

i'm not quite understand it ,i hope to get your help again,thankyou.

0 Likes
Message 4 of 7

Revitalizer
Advisor
Advisor

Hi,

 

the method's argument is just a normal vector.

If your selectedFace is a PlanarFace, you can simple use its FaceNormal property.

 

Transform transformToZ = GetTransformToZ((selectedFace as PlanarFace).FaceNormal);

 

To get a transformed Curve, just use

Curve yourCurveFlatten=yourCurve.CreateTransformed(transformToZ);

 

Revitalizer

 

Edit:

Some Revit API methods and classes have been renamed since 2008, so you may have to adjust the TBC sample code. 

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 5 of 7

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

as you can see in Jeremy's posting, this method just transforms the curves to a horizontal plane, but Z coordinate may be not zero.

Since you have not only vertices but curves, you cannot simply drop the Z value for projection to zero plane.

You may add another Transform by Transform.CreateTranslation(new XYZ(0,0,-whatever)).

Note that there might be little inaccuracies when transforming geometry, so the end points of your resulting curves may have Z values of 0.000000001 or so.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 7

JimJia
Alumni
Alumni

Thanks a lot for Revitalizer's sharing and reply, I believe this can solve the desired transform.

 

@846081597 Please let us know if you still have any problem; we may communicate offline via QQ if necessary. 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes
Message 7 of 7

846081597
Enthusiast
Enthusiast

Thanks for your help,i've solved the problem.Heart