2

I want to draw line of walls in the room using available data from RoomPlan.

I am using RoomPlan sdk to get the 3d model of a room in ios 16. Each wall is returned as a Surface object in the api that looks something like this:

enter image description here

Now the two most crucial piece of information is dimensions and transform. The dimensions vector is [width, height, length]

In one of the forums I read the following:

"You can use transform and dimensions parameters to draw lines. The 4 corners can be inferred from those 2 parameters: the first column of the transform is the "right" vector, and second is the "up" vector. The fourth column is the position of the wall/door/opening/window/object Combining those unit vectors with the dimensions vector will give you the corners."

Also saw someone post this code on apple site to find a door's corner points:

The central point of a door can be defined as: Point(door.transform[3].x, door.transform[3].y, door.transform[3].z)

upperLeftPoint = Point(centerPoint) 
upperLeftPoint = upperLeftPoint.translate(rightV.negate(), doorWidth/2) 
upperLeftPoint = upperLeftPoint.translate(upV, doorHeight/2)

I am very new to Computer Graphics and need to understand at a theoretical level what's happening here. Can anyone guide me as to how one can draw the lines for a wall / door using the given values or more specifically find the corner points of walls/doors?

Qedrix
  • 453
  • 1
  • 8
  • 15

1 Answers1

3

The way I am currently doing this is hinted at with the last code snippet you posted. I added functionality to the CapturedRoom.Surface class and also created a RoomPoint struct to represent the corners with the following code

extension CapturedRoom.Surface {
    var center: RoomPoint {
        return RoomPoint(x: self.transform[3].x, y: self.transform[3].y, z: self.transform[3].z)
    }
    
    var bottomLeftPoint: RoomPoint {
        let center = self.center
        var x = dimensions.x/2
        var y = dimensions.y/2
        x.negate()
        y.negate()
        let leftBottom = center.translate(x: x, y: y, z: 0)
        return leftBottom
    }
}

struct RoomPoint {
    var x: Float
    var y: Float
    var z: Float
    
    func translate(x: Float, y: Float, z: Float) -> RoomPoint {
        return RoomPoint(x: self.x + x, y: self.y + y, z: self.z + z)
    }
}

The center of any CaptureRoom Surface seems to be given by the last vector in transform matrix. The surface dimensions vector holds the [width (x), height (y), length (z)]. The center point is in the center of our surface meaning there is half the width and height on either side. So if we take the center and remove half the width and height we should get the bottom left corner of that surface. The length (z) coordinate doesn't matter in this case because our surface is on a vertical plane and has no depth. I'm currently stuck trying to find the surface area of a room with many corners by creating a polygon out of these corner points. Not sure where I am wrong - hopefully not in this answer I gave haha.