# Drawing lines with 0,0 being in the left bottom corner

1. What do you want to achieve? Drawing a line from the bottom left corner being the origin.

2. What is the issue? The lines are rotated about 90 degrees.

3. What solutions have you tried so far? Ive tried adding 90 degrees, but it doesnt really work too well. It isn’t exact.

Here’s my code:

``````function drawLine(StartPoint, EndPoint, Color, Thickess, Parent)
local startX, startY = StartPoint.X, StartPoint.Y
local endX, endY = EndPoint.X, EndPoint.Y
local Line = Instance.new("Frame")
Line.AnchorPoint = Vector2.new(0.5, 0.5)
Line.BackgroundColor3 = Color
Line.BorderSizePixel = 0
Line.Size = UDim2.new(0, ((endX - startX) ^ 2 + (endY - startY) ^ 2) ^ 0.5, 0, Thickess)
Line.Position = UDim2.new(0, (startX + endX) / 2, 1, -(startY + endY) / 2)
Line.Rotation = math.atan2(endY - startY, endX - startX) * (180 / math.pi) -- This is where ive tried to add things.
Line.Parent = Parent
end
``````

2 Likes

Try changing the 180 to 90 or an other number in degrees.

Same problem

The issue comes from that you’re mixing your coordinate systems, convert everything at the start and be consistent with the calculations.

``````local function convertToLocal(point, parent)
return Vector2.new(point.X, (parent.AbsoluteSize.Y - point.Y))
end

function drawLine(StartPoint, EndPoint, Color, Thickess, Parent)

local p1 = convertToLocal(StartPoint, Parent)
local p2 = convertToLocal(EndPoint, Parent)
local center = p1:Lerp(p2, 0.5)
local diff = (p2 - p1)

local Line = Instance.new("Frame")
Line.AnchorPoint = Vector2.new(0.5, 0.5)
Line.BackgroundColor3 = Color
Line.BorderSizePixel = 0
Line.Size = UDim2.new(0, diff.Magnitude, 0, Thickess)
Line.Position = UDim2.new(0, center.X, 0, center.Y, 0)
Line.Rotation = math.deg(math.atan2(diff.Y, diff.X))
Line.Parent = Parent

end

drawLine(Vector2.new(0, 0), Vector2.new(100, 50), Color3.new(255, 0, 0), 2, script.Parent.Frame)
``````