0

how can draw an arrow in all direction in sceneview using Two Points( Start point vector and end point vector) see attachment draw arrow like Up side , Downside , left side up and down, right side up and down enter image description here. i have tried to draw arrow using UIBezierPath but arrow shape not looks exactly same as arrow image also it doesn't work for all direction

check below code i have applied , any solution that how can i fix shape same as image or is there any solution that using two points how to draw directional Arrow in sceneview

    let path = UIBezierPath.arrow(from: CGPoint(x: arrowstartx, y: arrowstarty), to: CGPoint(x: arrowendx, y: arrowendy), tailWidth: 0.02, headWidth: 0.02, headLength: 0.02)
    path.close()
    let arrowShape = SCNShape(path: path, extrusionDepth: 0.001)
    let arrowNode = SCNNode(geometry: arrowShape)
    arrowNode.geometry?.firstMaterial?.diffuse.contents = UIColor(hexString: selectedItem ?? myMarkupDefaultColor)
 
    arrowNode.position = SCNVector3((vector1.x+vector3.x)/2.0, (vector1.y+vector3.y)/2.0, (vector1.z+vector3.z)/2.0)
    
    arrowNode.scale = SCNVector3(1.0,1.0, 1.0)

    
    self.sceneViewARMarkup.scene.rootNode.addChildNode(arrowNode)


class func arrow(from start: CGPoint, to end: CGPoint, tailWidth: CGFloat, headWidth: CGFloat, headLength: CGFloat) -> Self {
    let length = hypot(end.x - start.x, end.y - start.y)
    let tailLength = length - headLength
    
    func p(_ x: CGFloat, _ y: CGFloat) -> CGPoint { return CGPoint(x: x, y: y) }
    let points: [CGPoint] = [
        p(0, tailWidth / 2),
        p(tailLength, tailWidth / 2),
        p(tailLength, headWidth / 2),
        p(length, 0),
        p(tailLength, -headWidth / 2),
        p(tailLength, -tailWidth / 2),
        p(0, -tailWidth / 2)
    ]
    
    let cosine = (end.x - start.x) / length
    let sine = (end.y - start.y) / length
    let transform = CGAffineTransform(a: cosine, b: sine, c: -sine, d: cosine, tx: start.x, ty: start.y)
    
    let path = CGMutablePath()
    path.addLines(between: points, transform: transform )
    path.closeSubpath()
    return self.init(cgPath: path)
  • Hi, and welcome to SO. You could try to find answers here: https://stackoverflow.com/questions/55038312/curved-arrow-from-one-point-to-another and here: https://stackoverflow.com/questions/35002232/draw-scenekit-object-between-two-points – ZAY Apr 12 '23 at 16:42
  • i am able to draw stick of arrow start to end point using cylinder line but in case of arrow cap when i m adding cap its direction not setting towards to end position i have implemented path shape cap for straight top, right , left , down but for cross arrow i m not able to add it. – Vandana Modi Apr 12 '23 at 17:47

1 Answers1

0

One way you can do this is to create the arrow with Blender or find an an arrow model. Orient your model inside Blender like this: Stack O:[56183036], load it, and point it at the target.

func setTarget()
    {
        node.constraints = []
        let vConstraint = SCNLookAtConstraint(target: targetNode)
        vConstraint.isGimbalLockEnabled = true
        node.constraints = [vConstraint]
    }
Voltan
  • 1,170
  • 1
  • 7
  • 16