.NET

## .NET

Contributor
Posts: 12
Registered: ‎09-23-2011
Message 1 of 6 (232 Views)

# UCS 3points

232 Views, 5 Replies
10-30-2012 05:26 AM

Hi,

I'm trying to place a UCS based on 3 points

- the origin of the UCS (PTOrigin)

- the x-direction (PTX)

- the y-direction (PTY)

The thing is that the angle between the vectorX (from origin to PTX) and vectorY (from origin to PTY) is not always 90°. Currently a create a new UCS in the UCSTable change the origin of the record to PTOrigin. Then I create a 3D vector from PTOrigin to PTX and then I'm stuck. I 'm unable to create a vector perpendicular to the vectorX which goes through PTY

Can anyone help me creating the Y-vector or are there other solutions for this?

thanks

Filip

Posts: 610
Registered: ‎03-21-2011
Message 2 of 6 (193 Views)

# Re: UCS 3points

11-04-2012 09:58 PM in reply to: f.roels

Hi Filip,

Have you tried rotating the PTX about the PTOrigin by 90 degrees to determine the PTY ?

or)

the other option is to first create a vector from PTX to PTOrigin and then use the "Vector3d.GetPerpendicularVector" method using that vector.

Balaji
Developer Technical Services
Autodesk Developer Network

*Expert Elite*
Posts: 1,992
Registered: ‎04-29-2006
Message 3 of 6 (187 Views)

# Re: UCS 3points

11-04-2012 11:28 PM in reply to: Balaji_Ram

Hi,

you can use the cross product of X axis  and Y axis to define the Z axis, then recalculate Y axis with the cross product of z axis and X axis.

Here's a quick and dirty (no error handling if points are overlapped or if xaxis is parallel to Y axis)

```        private CoordinateSystem3d UcsBy3points(Point3d org, Point3d ptX, Point3d ptY)
{
Vector3d xAxis = org.GetVectorTo(ptX).GetNormal();
Vector3d zAxis = xAxis.CrossProduct(org.GetVectorTo(ptY)).GetNormal();
Vector3d yAxis = zAxis.CrossProduct(xAxis).GetNormal();
return new CoordinateSystem3d(org, xAxis, yAxis);
}```

Gilles Chanteau
Contributor
Posts: 12
Registered: ‎09-23-2011
Message 4 of 6 (180 Views)

# Re: UCS 3points

11-05-2012 12:33 AM in reply to: _gile

Hi,

I think the solution with "Vector3d.GetPerpendicularVector" seems easy, but I've tried it without the desired result. The UCS is not always correct because some times the Y-direction must point to the negative Z-direction (from World UCS)

your second solutions seems more like it. I will try it in a few days and report the result.

best

Filip

*Expert Elite*
Posts: 1,992
Registered: ‎04-29-2006
Message 5 of 6 (174 Views)

# Re: UCS 3points

11-05-2012 12:45 AM in reply to: f.roels

The way I purposed will also work whatever the new XY plane (i.e. 3D UCS rotated on X and/or Y axis).

Gilles Chanteau
Contributor
Posts: 12
Registered: ‎09-23-2011
Message 6 of 6 (119 Views)

# Re: UCS 3points

01-10-2013 03:54 AM in reply to: _gile

Hi Gilles

I was indeed incorrect. I tried your code again and it works fine now.

Thx

Filip

### You are not logged in.

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!