duckwit
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 1310 |
|
|
| 19 Jun 2013 11:38 AM |
I am developing some scripts to procedurally generate smooth curves for some slides using CFrame.
To make sure certain parts overlap nicely and don't leave jagged edges sticking out from any of the sides I need to be able to reference certain points in the geometry.
The slides are being constructed using an iteration sequence, so each rectangle is placed based on the CFrame of the previous one.
1. Place new Part in front of previous using lookVector * previous.Size.z (traversing z-axis) 2. Find the coordinate of the top right corner of the previous rectangle 3. Rotate the new Part around this point by a given amount
I have been struggling to articulate my mathematics to find this coordinate. I have tried using the CFrame matrix and the lookVector properties but haven't done so successfully. How can I find the coordinate of a given corner of a rotated 3D rectangle?
TL;DR In an axis aligned, origin-centered rectangle the coordinate of the corner I want to reference is: (part.Position.x+0.5*part.Size.x, part.Position.y+0.5*part.Size.y, part.Position.z+0.5*part.Size.z)
...how can I refer to the new coordinate when the rectangle has been rotated?
Thank you very much for taking the time to help me with this!
|
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 19 Jun 2013 11:42 AM |
| Well. If you are using a CFrame, you could do a * CFrame.Angles() to fix it. Angles of the part. |
|
|
| Report Abuse |
|
|
duckwit
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 1310 |
|
|
| 19 Jun 2013 11:44 AM |
To find the coordinates of the corner I tried: defaultCorner * previous.CFrame:components() (Where default is the part-relative corner I mentioned above) ... but that doesn't give me the corner? |
|
|
| Report Abuse |
|
|
|
| 19 Jun 2013 11:53 AM |
local part =
local corner = Vectors.new(part.Size.X/2, part.Size.Y/2, part.Size.Z/2)
corner = part.CFrame:vectorToObjectSpace(corner)
corner = part.Position + corner |
|
|
| Report Abuse |
|
|
duckwit
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 1310 |
|
|
| 19 Jun 2013 12:13 PM |
Thanks @ArbiterOfDeath, that references the corner I was after. What I don't understand now though is that the look vector is pointing away from the positive z-axis even though it's rotation is (0,0,0)? |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 19 Jun 2013 12:21 PM |
local s = part.Size local c = part.CFrame corner = c*CFrame.new(s/2)
|
|
|
| Report Abuse |
|
|
duckwit
|
  |
| Joined: 08 Aug 2008 |
| Total Posts: 1310 |
|
|
| 19 Jun 2013 12:24 PM |
| @1waffle1 that returns a CFrame and not a Vector3 |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 19 Jun 2013 12:25 PM |
| corner = (part.CFrame*CFrame.new(part.Size/2)).p |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|