I have reviewed and tried multiple different answers to similar questions but have not got the results expected. I have a layer with 4425 polyline features and want to make a perpendicular line feature for every existing line that is in a specific layer that will go from the centerpoint of the current line features and intersect through other line features. The black arrow is an example of the output, red is the layer I am getting the midpoint from, and blue is the layer I want the perpendicular lines to intersect. My current code is:
cursor = arcpy.SearchCursor("SpatialJoinLayer")
features = []
distance = 10
for row in cursor:
#Get midpoint of line feature
midpoint = row.shape.positionAlongLine(0.5, True).firstPoint
angle = row.Angle
startX = midpoint.X
startY = midpoint.Y
#Formula that I believe is wrong but cannot figure out where the problem is
endX = distance * math.cos(angle) + startX
endY = distance * math.sin(angle) + startY
arr = arcpy.Array([arcpy.Point(startX, startY), arcpy.Point(endX, endY)])
polyline = arcpy.Polyline(arr)
features.append(polyline)
#Add a feature class and add the newly created lines to it
arcpy.management.CreateFeatureclass(arcpy.env.workspace, "PerpLines")
arcpy.management.CopyFeatures(features, "PerpLines")
arcpy.Polyline
constructor without aspatial_reference
parameter is an anti-pattern that can corrupt your geometry coordinates.